Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !3375

[java rest-assured] prevent reqSpec reuse between requests

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/jmini/issue3370_rest-assured into master Jul 16, 2019
  • Overview 0
  • Commits 2
  • Pipelines 0
  • Changes 9

Created by: jmini

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
    Java: @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04)

Fixes #3370 (closed)

Description of the PR

Tested with this spec:

openapi: 3.0.1
info:
  title: ping test
  version: '1.0'
servers:
  - url: 'http://localhost:8080/'
paths:
  /ping:
    get:
      operationId: pingGet
      tags:
       - lorem
      parameters:
       - in: query
         name: q
         schema:
           type: string
       - in: query
         name: r
         schema:
           type: string
      responses:
        '201':
          description: Ok

With a this test using MockServer (more on this to come in #689):

public class LoremApiTest {

    private ClientAndServer mockServer;
    private LoremApi api;

    @Before
    public void createApi() {
        mockServer = ClientAndServer.startClientAndServer();
        String port =  "" + mockServer.getLocalPort();
        StringCounter counterA = new StringCounter("a_value_", 1);
        StringCounter counterB = new StringCounter("b_value_", 1);
        api = ApiClient.api(ApiClient.Config.apiConfig().reqSpecSupplier(
                () -> new RequestSpecBuilder()
                        .setConfig(config().objectMapperConfig(objectMapperConfig().defaultObjectMapper(gson())))
                        .addHeader("x-header-a",  counterA.nextValue())
                        .addFilter(new ErrorLoggingFilter())
                        .setBaseUri("http://localhost:" + port ))).lorem()
                .reqSpec(r -> r.addHeader("x-header-b", counterB.nextValue()));
    }
    
    @After
    public void stopMockServer() {
        mockServer.stop();
    }

    /**
     * Ok
     */
    @Test
    public void shouldSee201AfterPingGet() {
        StringCounter counterC = new StringCounter("c_value_", 1);

        mockServer
        .when(
                HttpRequest.request()
                        .withPath("/ping")
        )
        .respond(
                HttpResponse.response()
                        .withHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "application/json")
                        .withStatusCode(201)
                        .withBody("{ \"status\": \"ok\"}")
        );

        String q1 = "param1";
        api.pingGet()
            .reqSpec(r -> r.addHeader("x-header-c", counterC.nextValue()))
            .qQuery(q1).execute(r -> r.prettyPeek());
        
        String q2 = "param2";
        String r2 = "param2";
        api.pingGet()
            .reqSpec(r -> r.addHeader("x-header-c", counterC.nextValue()))
            .qQuery(q2).rQuery(r2).execute(r -> r.prettyPeek());
        
        HttpRequest[] recordedRequests = mockServer.retrieveRecordedRequests(
                HttpRequest.request()
                    .withPath("/ping")
        );
        Assert.assertEquals(2, recordedRequests.length);

        Assert.assertEquals(1, recordedRequests[0].getQueryStringParameterList().size());
        Assert.assertEquals("q", recordedRequests[0].getQueryStringParameterList().get(0).getName().getValue());
        Assert.assertEquals(1, recordedRequests[0].getQueryStringParameterList().get(0).getValues().size());
        Assert.assertEquals("param1", recordedRequests[0].getQueryStringParameterList().get(0).getValues().get(0).getValue());
        Assert.assertEquals("a_value_1", recordedRequests[0].getFirstHeader("x-header-a"));
        Assert.assertEquals("b_value_1", recordedRequests[0].getFirstHeader("x-header-b"));
        Assert.assertEquals("c_value_1", recordedRequests[0].getFirstHeader("x-header-c"));

        Assert.assertEquals(2, recordedRequests[1].getQueryStringParameterList().size());
        Assert.assertEquals("a_value_2", recordedRequests[1].getFirstHeader("x-header-a"));
        Assert.assertEquals("b_value_2", recordedRequests[1].getFirstHeader("x-header-b"));
        Assert.assertEquals("c_value_2", recordedRequests[1].getFirstHeader("x-header-c"));
        Assert.assertEquals("q", recordedRequests[1].getQueryStringParameterList().get(0).getName().getValue());
        Assert.assertEquals(1, recordedRequests[1].getQueryStringParameterList().get(0).getValues().size());
        Assert.assertEquals("param2", recordedRequests[1].getQueryStringParameterList().get(0).getValues().get(0).getValue());
    }
}

Was failing before and now it is no longer the case.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/jmini/issue3370_rest-assured