diff --git a/src/main/java/rocks/bastion/Bastion.java b/src/main/java/rocks/bastion/Bastion.java index 31d06ad..ed16650 100644 --- a/src/main/java/rocks/bastion/Bastion.java +++ b/src/main/java/rocks/bastion/Bastion.java @@ -2,15 +2,12 @@ import rocks.bastion.core.Assertions; import rocks.bastion.core.BastionFactory; -import rocks.bastion.core.Callback; import rocks.bastion.core.HttpRequest; import rocks.bastion.core.builder.BastionBuilder; import rocks.bastion.core.builder.ExecuteRequestBuilder; import rocks.bastion.core.builder.PostExecutionBuilder; -import rocks.bastion.core.configuration.BastionConfigurationLoader; import rocks.bastion.core.configuration.Configuration; import rocks.bastion.core.configuration.GlobalRequestAttributes; -import rocks.bastion.core.json.JsonRequest; import rocks.bastion.core.resource.ResourceLoader; import static java.util.Objects.requireNonNull; @@ -38,7 +35,7 @@ *

* Inside your test method or test case, make a call to the {@link Bastion#request(String, HttpRequest)} method. This will * return a fluent-builder style interface that will allow you - * to further specify the response model, assertions and callbacks on your test. + * to further specify the response model and assertions on your test. *

*

* The returned builder will allow you call any of the following methods: @@ -48,14 +45,12 @@ * interpret and decode the received response object into an instance of whatever type is supplied to this method. *

  • {@link rocks.bastion.core.builder.AssertionsBuilder#withAssertions(Assertions)}: Specify what test assertions to apply to the response. We recommend supplying the * assertions as a lambda or using one of the available subclass implementations of {@link Assertions}.
  • - *
  • {@link rocks.bastion.core.builder.CallbackBuilder#thenDo(Callback)}: Specify a callback function to execute when the response is received and it passes its assertions. We - * recommend supplying the {@link Callback} as a lambda function.
  • *
  • {@link ExecuteRequestBuilder#call()}: Starts the Bastion test by executing the HTTP request.
  • * *

    * You cannot call any of the methods above before any of the methods listed before it. Therefore, in your test, you should call * the methods above one after each other as listed above: you can skip any of the methods and Bastion will assign defaults. - * For example, if you want to make an HTTP request, apply some assertions without binding a model or using a callback, you would + * For example, if you want to make an HTTP request and apply some assertions without binding a model, you would * call the {@link #request(String, HttpRequest)} method first, followed by the {@link rocks.bastion.core.builder.AssertionsBuilder#withAssertions(Assertions)} * method to configure your assertions, followed by the {@link ExecuteRequestBuilder#call()} method to send the request * and start the test. @@ -125,21 +120,6 @@ * {@link rocks.bastion.core.builder.AssertionsBuilder#withAssertions(Assertions)} method of the Bastion test builder as * a Java 8 lambda. *

    - *

    Callbacks

    - *

    - * {@link Callback Callback objects} can be provided for a Bastion test using the {@link rocks.bastion.core.builder.CallbackBuilder#thenDo(Callback)} - * method. Callbacks are executed right after the test passes its assertions. Using a callback you may perform additional - * post processing to the response object which is not necessarily related to test assertions. This can include logging, - * setting variables for use further in your test and so on. - *

    - *

    You are encouraged to define your own {@link Callback callback} implementations. Just like requests and assertions, - * this promotes code reuse and maintainability especially if you are performing an action multiple times across your - * Bastion tests.

    - *

    - * If you do not want to implement your own callback classes though you can supply a callback object directly into the - * {@link rocks.bastion.core.builder.CallbackBuilder#thenDo(Callback)} method of the Bastion test builder as a Java 8 - * lambda. - *

    *

    Groovy Tests

    *

    * Certain features of Bastion such as the {@link rocks.bastion.core.json.JsonRequest} and the {@link rocks.bastion.core.json.JsonResponseAssertions} @@ -170,7 +150,7 @@ public final class Bastion { * * @param message A descriptive message for this Bastion test. * @param request The HTTP request that Bastion will execute for this test. - * @return A fluent-builder object which will let you bind a model type, add assertions, add callbacks and execute the test. + * @return A fluent-builder object which will let you bind a model type, add assertions and execute the test. */ public static BastionBuilder request(String message, HttpRequest request) { return BastionFactory.getDefaultBastionFactory().getBastion(message, request); @@ -187,7 +167,7 @@ public static BastionBuilder request(String message, HttpRequest request *

    * * @param request The HTTP request that Bastion will execute for this test. - * @return A fluent-builder object which will let you bind a model type, add assertions, add callbacks and execute the test. + * @return A fluent-builder object which will let you bind a model type, add assertions and execute the test. */ public static BastionBuilder request(HttpRequest request) { return BastionFactory.getDefaultBastionFactory().getBastion("", request); diff --git a/src/main/java/rocks/bastion/core/Assertions.java b/src/main/java/rocks/bastion/core/Assertions.java index 03ba705..32a42fc 100644 --- a/src/main/java/rocks/bastion/core/Assertions.java +++ b/src/main/java/rocks/bastion/core/Assertions.java @@ -8,8 +8,8 @@ *

    * Technically, the assertions can be any executable code but it is strongly recommended that a user only performs * stateless checks on the provided model and response. If you would like to change the state of the current test - * you can use the {@link BastionBuilderImpl#thenDo(Callback)} method using a {@link Callback}. You can also retrieve the returned - * object using the {@link BastionBuilderImpl#getModel()} and {@link BastionBuilderImpl#getResponse()} methods. + * you can retrieve the returned object using the {@link BastionBuilderImpl#getModel()} and {@link BastionBuilderImpl#getResponse()} + * methods for use later on. * * @param The type of response model the assertions will apply for. */ diff --git a/src/main/java/rocks/bastion/core/BastionBuilderImpl.java b/src/main/java/rocks/bastion/core/BastionBuilderImpl.java index c887a51..5407c5a 100644 --- a/src/main/java/rocks/bastion/core/BastionBuilderImpl.java +++ b/src/main/java/rocks/bastion/core/BastionBuilderImpl.java @@ -30,7 +30,6 @@ public class BastionBuilderImpl implements BastionBuilder, Respons private Class modelType; private boolean suppressAssertions; private Assertions assertions; - private Callback callback; private MODEL model; private ModelResponse modelResponse; private Configuration configuration; @@ -45,7 +44,6 @@ public class BastionBuilderImpl implements BastionBuilder, Respons modelType = null; suppressAssertions = false; assertions = Assertions.noAssertions(); - callback = Callback.noCallback(); } public void addBastionListener(BastionListener newListener) { @@ -102,7 +100,6 @@ public PostExecutionBuilder call() { model = decodeModel(response); modelResponse = new ModelResponse<>(response, model); executeAssertions(modelResponse); - executeCallback(modelResponse); return this; } catch (AssertionError error) { notifyListenersCallFailed(new BastionFailureEvent(request, response, error)); @@ -125,19 +122,12 @@ public AssertionsBuilder bind(Class modelType) { } @Override - public CallbackBuilder withAssertions(Assertions assertions) { + public ExecuteRequestBuilder withAssertions(Assertions assertions) { Objects.requireNonNull(assertions); this.assertions = assertions; return this; } - @Override - public ExecuteRequestBuilder thenDo(Callback callback) { - Objects.requireNonNull(callback); - this.callback = callback; - return this; - } - @Override public MODEL getModel() { return model; @@ -162,10 +152,6 @@ private String getDescriptiveText() { } } - private void executeCallback(ModelResponse modelResponse) { - callback.execute(modelResponse.getStatusCode(), modelResponse, modelResponse.getModel()); - } - private void executeAssertions(ModelResponse modelResponse) { if (!suppressAssertions) { assertions.execute(modelResponse.getStatusCode(), modelResponse, modelResponse.getModel()); diff --git a/src/main/java/rocks/bastion/core/BastionFactory.java b/src/main/java/rocks/bastion/core/BastionFactory.java index b3c477f..80c79f2 100644 --- a/src/main/java/rocks/bastion/core/BastionFactory.java +++ b/src/main/java/rocks/bastion/core/BastionFactory.java @@ -5,9 +5,7 @@ import rocks.bastion.core.configuration.BastionConfigurationLoader; import rocks.bastion.core.configuration.Configuration; -import java.util.Objects; - -import static java.util.Objects.*; +import static java.util.Objects.requireNonNull; /** * Creates and configures an instance of the {@link BastionBuilderImpl} fluent builder. A single factory can be designated as the @@ -86,8 +84,8 @@ public BastionBuilder getBastion(String message, HttpRequest request) { /** * Configures whether {@link BastionBuilderImpl} objects returned by this factory should be configured to suppress assertions or - * not. When set to suppress assertions, Bastion will execute the HTTP request as normal as well as any callbacks provided - * but will skip executing any assertions provided to the {@link BastionBuilderImpl#withAssertions(Assertions)} method. + * not. When set to suppress assertions, Bastion will execute the HTTP request as normal but will skip executing any assertions + * provided to the {@link BastionBuilderImpl#withAssertions(Assertions)} method. * * @param suppressAssertions {@literal true} to suppress assertions; {@literal false}, otherwise. */ diff --git a/src/main/java/rocks/bastion/core/Callback.java b/src/main/java/rocks/bastion/core/Callback.java deleted file mode 100644 index c076e39..0000000 --- a/src/main/java/rocks/bastion/core/Callback.java +++ /dev/null @@ -1,38 +0,0 @@ -package rocks.bastion.core; - -/** - * Performs an action after an API request has occurred and passed its assertions. Users can use {@code Callback}s - * to extract information from response recieved by an API. This information can be used for later Bastion requests. - *

    - * By default, a {@link BastionBuilderImpl} builders start with the {@link Callback#noCallback() empty callback}. - */ -@FunctionalInterface -public interface Callback { - - /** - * The empty callback which does nothing. - */ - Callback NO_OPERATION_CALLBACK = (statusCode, response, context) -> { - }; - - /** - * Returns the empty callback which does nothing. - * - * @param The type of model which Bastion will bind the received response to - * @return The empty callback - */ - @SuppressWarnings("unchecked") - static Callback noCallback() { - return (Callback) NO_OPERATION_CALLBACK; - } - - /** - * The actual Callback action to perform after a Bastion Request completes and it passes its assertions. - * - * @param statusCode The HTTP status code received - * by the API endpoint. - * @param response The HTTP response information received from the API (including HTTP headers, etc.) - * @param model The bound model which was extracted from the received HTTP response - */ - void execute(int statusCode, ModelResponse response, M model); -} diff --git a/src/main/java/rocks/bastion/core/builder/AssertionsBuilder.java b/src/main/java/rocks/bastion/core/builder/AssertionsBuilder.java index e3ccd1f..1c5d5c1 100644 --- a/src/main/java/rocks/bastion/core/builder/AssertionsBuilder.java +++ b/src/main/java/rocks/bastion/core/builder/AssertionsBuilder.java @@ -1,7 +1,6 @@ package rocks.bastion.core.builder; import rocks.bastion.core.Assertions; -import rocks.bastion.core.Callback; /** * Defines the operations which a user can perform on a Bastion builder before any {@link Assertions assertions} object is added to the test. @@ -9,15 +8,13 @@ *

      *
    • {@link #withAssertions(Assertions)}: Specify what test assertions to apply to the response. We recommend supplying the * assertions as a lambda or using one of the available subclass implementations of {@link Assertions}.
    • - *
    • {@link #thenDo(Callback)}: Specify a callback function to execute when the response is received and it passes its assertions. We - * recommend supplying the {@link Callback} as a lambda function.
    • *
    • {@link #call()}: Starts the Bastion test by executing the HTTP request.
    • *
    *

    * After using the {@linkplain #call()} method, the user may obtain the response, for further use in the ongoing test, using * methods defined in the {@link PostExecutionBuilder} interface. */ -public interface AssertionsBuilder extends CallbackBuilder { +public interface AssertionsBuilder extends ExecuteRequestBuilder { /** * Add an assertions object which determines whether the received response is as expected. We recommend @@ -29,8 +26,8 @@ public interface AssertionsBuilder extends CallbackBuilder { * always pass are set by default. * * @param assertions A non-{@literal null} {@linkplain Assertions} object - * @return A fluent-builder which will allow you to add callbacks, execute the HTTP request and retrieve the response information + * @return A fluent-builder which will allow you to execute the HTTP request and retrieve the response information */ - CallbackBuilder withAssertions(Assertions assertions); + ExecuteRequestBuilder withAssertions(Assertions assertions); } diff --git a/src/main/java/rocks/bastion/core/builder/BastionBuilder.java b/src/main/java/rocks/bastion/core/builder/BastionBuilder.java index 6979389..bb0cf4f 100644 --- a/src/main/java/rocks/bastion/core/builder/BastionBuilder.java +++ b/src/main/java/rocks/bastion/core/builder/BastionBuilder.java @@ -2,20 +2,17 @@ import rocks.bastion.Bastion; import rocks.bastion.core.Assertions; -import rocks.bastion.core.Callback; import rocks.bastion.core.HttpRequest; /** - * The first interface for the Bastion fluent-builder allowing the user to {@link #bind(Class) bind} a model type, apply {@link #withAssertions(Assertions) assertions}, - * apply a {@link #thenDo(Callback) callback} function and {@link #call() initiate} the test. This interface serves to group together all the options for Bastion users + * The first interface for the Bastion fluent-builder allowing the user to {@link #bind(Class) bind} a model type, apply {@link #withAssertions(Assertions) assertions} + * and {@link #call() initiate} the test. This interface serves to group together all the options for Bastion users * immediately after invoking the Bastion builder using {@link Bastion#request(String, HttpRequest)}. Using this builder, a user can: *

      *
    • {@link #bind(Class)}: Specify which class type to use when constructing a model of the received response. Bastion will * interpret and decode the received response object into an instance of whatever type is supplied to this method.
    • *
    • {@link #withAssertions(Assertions)}: Specify what test assertions to apply to the response. We recommend supplying the * assertions as a lambda or using one of the available subclass implementations of {@link Assertions}.
    • - *
    • {@link #thenDo(Callback)}: Specify a callback function to execute when the response is received and it passes its assertions. We - * recommend supplying the {@link Callback} as a lambda function.
    • *
    • {@link #call()}: Starts the Bastion test by executing the HTTP request.
    • *
    * After using the {@linkplain #call()} method, the user may obtain the response, for further use in the ongoing test, using @@ -23,7 +20,7 @@ *
    * Note that the user must perform the steps detailed above, in * the order they are listed: the user may skip any of the steps but they cannot perform steps out of order (for example, if you - * supply a callback function using {@linkplain #thenDo(Callback)} then you cannot use the {@linkplain #bind(Class)} method afterwards. + * supply an assertion lambda using {@linkplain #withAssertions(Assertions)} then you cannot use the {@linkplain #bind(Class)} method afterwards. * * @param The model type which was bound with the {@link #bind(Class)} method. */ diff --git a/src/main/java/rocks/bastion/core/builder/BindBuilder.java b/src/main/java/rocks/bastion/core/builder/BindBuilder.java index a775106..d438d47 100644 --- a/src/main/java/rocks/bastion/core/builder/BindBuilder.java +++ b/src/main/java/rocks/bastion/core/builder/BindBuilder.java @@ -1,7 +1,6 @@ package rocks.bastion.core.builder; import rocks.bastion.core.Assertions; -import rocks.bastion.core.Callback; /** * Defines the operations that can be performed on a Bastion builder before it has been bound to a model type. Binding the @@ -26,8 +25,8 @@ public interface BindBuilder { * pass in a constructable type (a non-abstract class which can be instantiated) because the various decoders used by * Bastion, such as the Jackson JSON parser, only work if it can construct an instance of the model. *

    - * The bound type will be used further on when the user specifies {@link AssertionsBuilder#withAssertions(Assertions) assertions}, - * {@link CallbackBuilder#thenDo(Callback) callbacks} or outright retrieves the {@link PostExecutionBuilder#getModel() decoded response model} + * The bound type will be used further on when the user specifies {@link AssertionsBuilder#withAssertions(Assertions) + * assertions} or outright retrieves the {@link PostExecutionBuilder#getModel() decoded response model} * as the bound model (of the correct type) will be provided by Bastion. * * @param modelType A non-{@literal null} class type which will be used when constructing the response model diff --git a/src/main/java/rocks/bastion/core/builder/CallbackBuilder.java b/src/main/java/rocks/bastion/core/builder/CallbackBuilder.java deleted file mode 100644 index 1bd06e9..0000000 --- a/src/main/java/rocks/bastion/core/builder/CallbackBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -package rocks.bastion.core.builder; - -import rocks.bastion.core.Callback; - -/** - * Defines the operations which a user can perform on a Bastion builder before any {@link Callback callbacks} have been added to the test. - * At this point, a user may perform one of the following: - *
      - *
    • {@link #thenDo(Callback)}: Specify a callback function to execute when the response is received and it passes its assertions. We - * recommend supplying the {@link Callback} as a lambda function.
    • - *
    • {@link #call()}: Starts the Bastion test by executing the HTTP request.
    • - *
    - *
    - * After using the {@linkplain #call()} method, the user may obtain the response, for further use in the ongoing test, using - * methods defined in the {@link PostExecutionBuilder} interface. - * - * @param The model type currently bound to this Bastion builder - */ -public interface CallbackBuilder extends ExecuteRequestBuilder { - - /** - * Attach a callback function to this Bastion test. The callback function will be executed after a response has been - * received, it has been decoded into a model object and any assertions have passed. - *

    - * If this method is not called on the current Bastion builder, then a {@link Callback#noCallback() no-operations callback - * function} which does nothing will be set by default. - * - * @param callback A callback function to execute after this Bastion test's assertions have passed - * @return A fluent-builder which will allow you to execute the request and then retrieve the response - */ - ExecuteRequestBuilder thenDo(Callback callback); - -} diff --git a/src/main/java/rocks/bastion/core/builder/ExecuteRequestBuilder.java b/src/main/java/rocks/bastion/core/builder/ExecuteRequestBuilder.java index 27dacfa..0d45be9 100644 --- a/src/main/java/rocks/bastion/core/builder/ExecuteRequestBuilder.java +++ b/src/main/java/rocks/bastion/core/builder/ExecuteRequestBuilder.java @@ -14,14 +14,14 @@ public interface ExecuteRequestBuilder { /** - * Instructs Bastion to perform the HTTP request, decode the response into a model, perform any assertions and execute - * the registered callback. If you are using the {@link BastionRunner}, the actual call will appear - * as a test in any test harness GUI you are using. This is true, even if the test fails in which case the singular - * Bastion request which failed will appear in the GUI. + * Instructs Bastion to perform the HTTP request, decode the response into a model and perform any assertions. If you are using the + * {@link BastionRunner}, the actual call will appear as a test in any test harness GUI you are using. This is true, even if the test + * fails in which case the singular Bastion request which failed will appear in the GUI. *

    * If the call was successful, you can obtain the response received by Bastion by chaining further methods to this - * method. Notably, the {@link PostExecutionBuilder#getModel()} will return the decoded model and {@link PostExecutionBuilder#getResponse()} - * will return the complete response object (including the model) which represents the HTTP information. + * method. Notably, the {@link PostExecutionBuilder#getModel()} method will return the decoded model and + * {@link PostExecutionBuilder#getResponse()} will return the complete response object (including the model) which represents the + * HTTP information. * * @return A Bastion fluent-builder which allows you to retrieve the HTTP response and the decoded model */ diff --git a/src/test/java/rocks/bastion/support/CreateSushiTest.java b/src/test/java/rocks/bastion/support/CreateSushiTest.java index 2d69b9d..c6161cd 100644 --- a/src/test/java/rocks/bastion/support/CreateSushiTest.java +++ b/src/test/java/rocks/bastion/support/CreateSushiTest.java @@ -24,9 +24,6 @@ public void testCreateSushi_Success() { assertThat(statusCode).isEqualTo(201); assertThat(model.getName()).isEqualTo("happiness"); }) - .thenDo((statusCode, response, model) -> { - // do stuff - }) .call(); Bastion.request("SUCCESS (Again)", new CreateSushiRequest()) @@ -37,9 +34,6 @@ public void testCreateSushi_Success() { assertThat(statusCode).isEqualTo(201); assertThat(model.getName()).isEqualTo("happiness"); }) - .thenDo((statusCode, response, model) -> { - // do stuff - }) .call(); }