Package com.github.tomakehurst.wiremock.testsupport

Examples of com.github.tomakehurst.wiremock.testsupport.WireMockResponse


    @Test
    public void stubbingPatch() {
        stubFor(patch(urlEqualTo("/a/registered/resource")).withRequestBody(equalTo("some body"))
                .willReturn(aResponse().withStatus(204)));

        WireMockResponse response = testClient.patchWithBody("/a/registered/resource", "some body", "text/plain");

        assertThat(response.statusCode(), is(204));
    }
View Full Code Here


    }

  private void getAndAssertUnderlyingExceptionInstanceClass(String url, Class<?> expectedClass) {
    boolean thrown = false;
    try {
      WireMockResponse response = testClient.get(url);
      response.content();
    } catch (Exception e) {
      assertThat(e.getCause(), instanceOf(expectedClass));
      thrown = true;
    }
   
View Full Code Here

    @Test
  public void mappingsLoadedFromJsonFiles() {
        buildWireMock(wireMockConfig());
        wireMockServer.loadMappingsUsing(new JsonFileMappingsLoader(new SingleRootFileSource("src/test/resources/test-requests")));

    WireMockResponse response = testClient.get("/canned/resource/1");
    assertThat(response.statusCode(), is(200));

    response = testClient.get("/canned/resource/2");
    assertThat(response.statusCode(), is(401));
  }
View Full Code Here

    WireMock.configure();
  }
 
  @Test
  public void servesBakedInStubResponse() {
    WireMockResponse response = testClient.get("/wiremock/api/mytest");
    assertThat(response.content(), containsString("YES"));
  }
View Full Code Here

                        .withBody("<items>" +
                                "   <item>Buy milk</item>" +
                                "   <item>Cancel newspaper subscription</item>" +
                                "</items>")));

        WireMockResponse response = testClient.get("/todo/items");
        assertThat(response.content(), containsString("Buy milk"));
        assertThat(response.content(), not(containsString("Cancel newspaper subscription")));

        response = testClient.postWithBody("/todo/items", "Cancel newspaper subscription", "text/plain", "UTF-8");
        assertThat(response.statusCode(), is(201));

        response = testClient.get("/todo/items");
        assertThat(response.content(), containsString("Buy milk"));
        assertThat(response.content(), containsString("Cancel newspaper subscription"));
    }
View Full Code Here

    givenThat(put(urlEqualTo("/state/modifying/resource"))
        .willReturn(aResponse().withStatus(HTTP_OK))
        .inScenario("StateIndependent")
        .willSetStateTo("BodyModified"));
   
    WireMockResponse response = testClient.get("/state/independent/resource");
    assertThat(response.statusCode(), is(HTTP_OK));
    assertThat(response.content(), is("Some content"));
   
    testClient.put("/state/modifying/resource");
   
    response = testClient.get("/state/independent/resource");
    assertThat(response.statusCode(), is(HTTP_OK));
    assertThat(response.content(), is("Some content"));
  }
View Full Code Here

    }

    private void executeGetIn(String address) {
        WireMockTestClient wireMockClient = new WireMockTestClient(port, address);
        wireMockClient.addResponse(MappingJsonSamples.BASIC_MAPPING_REQUEST_WITH_RESPONSE_HEADER);
        WireMockResponse response = wireMockClient.get("/a/registered/resource");
        assertThat(response.statusCode(), is(401));
    }
View Full Code Here

      "    \"body\": \"Matched!\"            \n" +
      "  }                        \n" +
      "}                            ";
   
    testClient.addResponse(REGEX_URL_MAPPING_REQUEST);
    WireMockResponse response = testClient.get("/one/two/three");
   
    assertThat(response.statusCode(), is(200));
    assertThat(response.content(), is("Matched!"));
  }
View Full Code Here

 
  @Test
  public void basicMappingWithExactUrlAndMethodMatchIsCreatedAndReturned() {
    testClient.addResponse(MappingJsonSamples.BASIC_MAPPING_REQUEST_WITH_RESPONSE_HEADER);
   
    WireMockResponse response = testClient.get("/a/registered/resource");
   
    assertThat(response.statusCode(), is(401));
    assertThat(response.content(), is("Not allowed!"));
    assertThat(response.firstHeader("Content-Type"), is("text/plain"));
  }
View Full Code Here

 
  @Test
  public void mappingWithStatusOnlyResponseIsCreatedAndReturned() {
    testClient.addResponse(MappingJsonSamples.STATUS_ONLY_MAPPING_REQUEST);
   
    WireMockResponse response = testClient.put("/status/only");
   
    assertThat(response.statusCode(), is(204));
    assertNull(response.content());
  }
View Full Code Here

TOP

Related Classes of com.github.tomakehurst.wiremock.testsupport.WireMockResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.