Code Monkey home page Code Monkey logo

garnishtest's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

garnishtest's Issues

support multiple HTTP clients

We should support multiple HTTP clients.
This will allow us to call multiple APIs in the tests, potentially each API having its own authentication scheme.

To integrate this seamlessly:

  • each HTTP client will be mapped by name
  • if there is only one, it will have the name defaultHttpClient
  • there will be two sets of steps
    • one that doesn't give a name for the HTTP client, and will use the HTTP client named defaultHttpClient, e.g. When I call GET on '/my/api'. These steps will make the tests more readable when you don't need multiple HTTP clients.
    • one that includes the name for the HTTP client, e.g. When I call GET on '/my/api' using 'myApiClient'

support multiple RDBMS client

Currently we only support one database client for the DB steps.

Sometimes we need to work with more that one DB at once. For example, it may be that calling a REST client will create entries in 2 DBs and we need to verify both.

To integrate this seamlessly:

  • each DB client will be mapped by name
  • if there is only one, it will have the name defaultRdbmsClient
  • there will be two sets of steps
    • one that doesn't give a name for the RDBMS client, and will use the RDBMS client named defaultRdbmsClient, e.g. Then the database state should be like in 'expected.db.xml'. These steps will make the tests more readable when you don't need multiple RDBMS clients
    • one that includes the name of the RDBMS client, e.g. Then the database state should be like in 'expected.db.xml', using 'myRdbmsClient'

add templates for data files

This will:

  • simplify creating new data files (only providing the dynamic values)
  • simplify migration when the data file format changes (most of the time only the template needs to be changed)

HTTP client steps: remove combinatorial complexity

There can be many combinations of headers, body, etc. when composing a request:

  • no headers, no body
  • no headers, with body inline (in the .feature file)
  • ho headers, with body from file
  • with headers, no body
  • with headers
  • with headers, with inline form parameters body (table in the .feature file)
  • with headers, multipart body
  • etc.

The current approach is to have a step for each combination. This leads to an explosion in the number of required steps.
Refactor to allow the request to be composed using multiple steps:

Given   the request headers
      | Content-Type | application/x-www-form-urlencoded |
And   the form body parameters
      | grant_type | password            |
      | client_id  | com.farbodsaraf     |
 When  I call 'POST' on '/authserver/oauth/token'

This way, you can compose whatever request is needed, and the code remains maintainable.

The intermediary information (headers, body, etc.) can be saved in story variables.
Important note: the steps that perform the actual request should clear all such story variables, so that another request in the same scenario will not be affected.

Need ability to set headers in a separate step

Something like this #1 :

@given("^the grppy request headers$")
public void the_request_headers(@nonnull final Map<String, String> requestHeaders) {
PREPARED_HEADERS.setValue(requestHeaders);
}

@When("^I call '(POST|PUT|PATCH)' on '(.+)' with JSON from '(.+)' and previously provided headers$")
public void callMethodOnUrlWithJsonBodyAndHeaders(
        @NonNull final HttpMethod method,
        @NonNull final String url,
        @NonNull final String jsonReqBodyFile
) {
    String jsonBody = ClasspathUtils.loadFromClasspath(ResourceFilesVariables.getResourceFilesPrefix() + jsonReqBodyFile);

    jsonBody = ScenarioUserVariables.resolveInText(jsonBody, ValueEscapers.json());
    jsonBody = JsonUtils.makeValidJson(jsonBody);


    HttpRequestBuilder requestBuilder = this.httpClient.request(method, url);

    final Map<String, String> requestHeaders = PREPARED_HEADERS.getValue();
    if (requestHeaders != null) {
        for (final Map.Entry<String, String> entry : requestHeaders.entrySet()) {
            requestBuilder = requestBuilder.addHeader(entry.getKey(), entry.getValue());
        }
    }
     requestBuilder = requestBuilder.body(jsonBody, ContentType.APPLICATION_JSON);
    HttpResponse response = requestBuilder.execute();

    this.responseManager.setResponse(response);
} 

remove destination directory before creating report

[ERROR] Failed to execute goal com.mobiquityinc.mobit:cucumber-reports-maven-plugin:0.16:generate-reports (generate-cucumber-reports) on project presentation-test: failed to create directory [/Users/alfred/work/BCC/Rabobank-Moonshot/presentation/presentation-test/target/cucumber/cucumber-html-report] or one of its parents -> [Help 1]

simplify the demos poms

The poms:

  • should not depend on a parent
  • should be simplified as much as possible
  • maybe we should add comments explaining the various pom parts

license: Apache 2.0

Make it obvious that the project is licensed under Apache 2.0:

  • in the Readme.md
  • in the root pom.xml
  • documentation
  • website

Header information in mock responses not being used

HttpMocksSteps.given_http_mocks_from_classpath_resource does not de-serialize header information for mock responses.

I got this to work using wiremock 2.5.0
and the following code (no prizes for elegance here):

@given("^http grppy mocks from '(.+)'$")
public void given_http_mocks_from_classpath_resource(@nonnull String httpMocksFile) throws JSONException {
if (httpMocksFile == null) {
throw new IllegalArgumentException("httpMocksFile is null");
} else {
String serializedMappings = ClasspathUtils.loadFromClasspath(ResourceFilesVariables.getResourceFilesPrefix() + httpMocksFile);
List mappings = new ArrayList<>();
JSONArray jsonArray = new JSONArray(serializedMappings);
for (int i = 0; i < jsonArray.length(); i++) {
mappings.add(StubMapping.buildFrom(jsonArray.getJSONObject(i).toString()));
}

        this.httpMockServerManager.reset();
        this.httpMockServerManager.register(mappings);
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.