com.github.tomakehurst.wiremock.client.WireMock Java Examples

The following examples show how to use com.github.tomakehurst.wiremock.client.WireMock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BitbucketWireMockBase.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Before
public void setup() throws Exception {
    super.setup();
    this.authenticatedUser = login();
    WireMockRule bitbucketApi = getWireMockRule();

    String files = wireMockFileSystemPath()+"__files";
    String mappings = wireMockFileSystemPath()+"mappings";
    String proxyUrl = wireMockProxyUrl();

    new File(mappings).mkdirs();
    new File(files).mkdirs();
    bitbucketApi.enableRecordMappings(new SingleRootFileSource(mappings),
            new SingleRootFileSource(files));

    if (useProxy) {
        bitbucketApi.stubFor(
            WireMock.get(urlMatching(".*")).atPriority(10).willReturn(aResponse()
                .proxiedFrom(proxyUrl)));
    }

    this.apiUrl = String.format("http://localhost:%s",bitbucketApi.port());
}
 
Example #2
Source File: BoxFileTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testCreateMetadataOnFileSucceeds() throws IOException {
    String result = "";
    final String metadataID = "12345";
    final String fileID = "12345";
    final String template = "properties";
    final String scope = "global";
    final String metadataURL = "/files/" + fileID + "/metadata/global/properties";
    JsonObject metadataObject = new JsonObject()
            .add("foo", "bar");

    result = TestConfig.getFixture("BoxFile/CreateMetadataOnFile201");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(metadataURL))
            .withRequestBody(WireMock.equalToJson(metadataObject.toString()))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxFile file = new BoxFile(this.api, fileID);
    Metadata info = file.createMetadata(new Metadata().add("/foo", "bar"));

    Assert.assertEquals(metadataID, info.getID());
    Assert.assertEquals(scope, info.getScope());
}
 
Example #3
Source File: BoxFileTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testUploadNewVersionReturnsCorrectInfo() throws IOException {

    String result = "";
    String fileID = "11111";
    String fileName = "test.txt";
    byte[] bytes = new byte[] {1, 2, 3};
    InputStream fileContents = new ByteArrayInputStream(bytes);

    result = TestConfig.getFixture("BoxFile/UploadNewVersion201");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo("/files/" + fileID + "/content"))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxFile file = new BoxFile(this.api, fileID);

    BoxFile.Info info = file.uploadNewVersion(fileContents);

    Assert.assertEquals(fileID, info.getID());
    Assert.assertEquals(fileName, info.getName());
}
 
Example #4
Source File: BoxTermsOfServiceTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetATermsOfServiceInfoSucceeds() throws IOException {
    String result = "";
    final String tosID = "12345";
    final String tosURL = "/terms_of_services/" + tosID;
    final String enterpriseID = "1111";
    final String tosType = "managed";

    result = TestConfig.getFixture("BoxTermsOfService/GetATermsOfServiceInfo200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(tosURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxTermsOfService termsOfService = new BoxTermsOfService(this.api, tosID);
    BoxTermsOfService.Info tosInfo = termsOfService.getInfo();

    Assert.assertEquals(tosID, tosInfo.getID());
    Assert.assertEquals(enterpriseID, tosInfo.getEnterprise().getID());
    Assert.assertEquals(BoxTermsOfService.TermsOfServiceType.MANAGED, tosInfo.getTosType());
}
 
Example #5
Source File: BoxUserTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testCreateEmailAliasSucceeds() throws IOException {
    String result = "";
    final String userID = "12345";
    final String emailAliasURL = "/users/" + userID + "/email_aliases";
    final String emailAlias = "[email protected]";
    JsonObject emailAliasObject = new JsonObject()
            .add("email", emailAlias);

    result = TestConfig.getFixture("BoxUser/CreateEmailAlias201");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(emailAliasURL))
            .withRequestBody(WireMock.equalToJson(emailAliasObject.toString()))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxUser user = new BoxUser(this.api, userID);
    EmailAlias alias = user.addEmailAlias(emailAlias);

    Assert.assertEquals(userID, alias.getID());
    Assert.assertTrue(alias.getIsConfirmed());
    Assert.assertEquals(emailAlias, alias.getEmail());
}
 
Example #6
Source File: BoxFolderTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test(expected = BoxDeserializationException.class)
public void testDeserializationException() throws IOException {
    String result = "";
    final String folderID = "12345";
    final String foldersURL = "/folders/" + folderID;

    result = TestConfig.getFixture("BoxFolder/GetFolderInfoCausesDeserializationException");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(foldersURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxFolder.Info folderInfo = new BoxFolder(this.api, folderID).getInfo();
    Assert.assertEquals("12345", folderInfo.getID());
}
 
Example #7
Source File: BoxFolderTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetAllFolderItemsSucceeds() throws IOException {
    String result = "";
    final String folderID = "12345";
    final String folderURL = "/folders/" + folderID + "/items/";
    final String firstFolderName = "Example.pdf";

    result = TestConfig.getFixture("BoxFolder/GetAllFolderItems200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(folderURL))
            .withQueryParam("limit", WireMock.containing("1000"))
            .withQueryParam("offset", WireMock.containing("0"))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxFolder folder = new BoxFolder(this.api, folderID);
    BoxItem.Info firstFolderInfo = folder.iterator().next();

    Assert.assertEquals(folderID, firstFolderInfo.getID());
    Assert.assertEquals(firstFolderName, firstFolderInfo.getName());
}
 
Example #8
Source File: AllureRestAssuredTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
protected final AllureResults execute() {
    RestAssured.replaceFiltersWith(new AllureRestAssured());
    final WireMockServer server = new WireMockServer(WireMockConfiguration.options().dynamicPort());

    return runWithinTestContext(() -> {
        server.start();
        WireMock.configureFor(server.port());

        WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/hello")).willReturn(WireMock.aResponse().withBody("some body")));
        try {
            RestAssured.when().get(server.url("/hello")).then().statusCode(200);
        } finally {
            server.stop();
            RestAssured.replaceFiltersWith(ImmutableList.of());
        }
    });
}
 
Example #9
Source File: RequestResponeLoggingFilterTest.java    From parsec-libraries with Apache License 2.0 6 votes vote down vote up
@Test
public void getRequestShouldNotBeLogged() throws ExecutionException, InterruptedException {

    String url = "/getWithFilter200?param1=value1";
    WireMock.stubFor(get(urlEqualTo(url))
            .willReturn(okJson(stubRespBodyJson)));

    String requestMethod = HttpMethod.GET;

    Map<String, Collection<String>> headers = stubHeaders;

    ParsecAsyncHttpRequest request =
            new ParsecAsyncHttpRequest.Builder()
                    .setUrl(wireMockBaseUrl+url)
                    .setHeaders(headers)
                    .setRequestTimeout(30)
                    .setMethod(requestMethod)
                    .setBody("").setBodyEncoding("UTF-8").build();

    Response response = parsecHttpClient.criticalExecute(request).get();
    assertThat(response.getStatus(), equalTo(200));

    then(mockAppender).should(never()).doAppend(any());

}
 
Example #10
Source File: BoxDevicePinTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetDevicePinInfoSucceeds() throws IOException {
    String result = "";
    final String devicePinID = "12345";
    final String devicePinURL = "/device_pinners/" + devicePinID;
    final String ownedByUserName = "Test User";
    final String ownedByUserLogin = "[email protected]";
    final String productName = "iPhone";

    result = TestConfig.getFixture("BoxDevicePin/GetDevicePinInfo200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(devicePinURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxDevicePin devicePin = new BoxDevicePin(this.api, devicePinID);
    BoxDevicePin.Info devicePinInfo = devicePin.getInfo();

    Assert.assertEquals(devicePinID, devicePinInfo.getID());
    Assert.assertEquals(ownedByUserName, devicePinInfo.getOwnedBy().getName());
    Assert.assertEquals(ownedByUserLogin, devicePinInfo.getOwnedBy().getLogin());
    Assert.assertEquals(productName, devicePinInfo.getProductName());
}
 
Example #11
Source File: BoxAPIResponseExceptionTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetResponseHeadersWithNoRequestID() throws IOException {
    String result = "";
    final String userURL = "/users/12345";

    result = TestConfig.getFixture("BoxException/BoxResponseException403");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(userURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("BOX-REQUEST-ID", "11111")
                    .withStatus(403)
                    .withBody(result)));

    try {
        BoxUser user = new BoxUser(this.api, "12345");
        BoxUser.Info userInfo = user.getInfo();
    } catch (Exception e) {
        Assert.assertEquals("The API returned an error code [403 | .11111] Forbidden", e.getMessage());
    }
}
 
Example #12
Source File: ApacheWireTest.java    From verano-http with MIT License 6 votes vote down vote up
@Test
public void sendsPutRequestWithHeaders() throws Exception {
    this.mock.stubFor(WireMock.post(WireMock.urlMatching("/.*"))
        .willReturn(WireMock.aResponse().withStatus(204))
    );
    new ApacheWire(
        String.format("http://localhost:%d", this.mock.port()),
        new ContentType("application/json")
    ).send(new Post("/items"));
    WireMock.verify(
        WireMock.postRequestedFor(WireMock.urlMatching("/items"))
            .withHeader(
                "Content-Type", WireMock.containing("application/json")
            )
    );
}
 
Example #13
Source File: BoxTrashTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testRestoreFolderFromTrashSucceeds() throws IOException {
    String result = "";
    final String folderID = "12345";
    final String restoreFolderURL = "/folders/" + folderID;
    final String folderName = "Test Folder";
    final String createdByName = "Test User";
    final String parentFolderName = "All Files";

    result = TestConfig.getFixture("BoxTrash/RestoreFolderItemFromTrash201");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.post(WireMock.urlPathEqualTo(restoreFolderURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxTrash trash = new BoxTrash(this.api);
    BoxFolder.Info restoredFolder = trash.restoreFolder(folderID);

    Assert.assertEquals(folderID, restoredFolder.getID());
    Assert.assertEquals(folderName, restoredFolder.getName());
    Assert.assertEquals(createdByName, restoredFolder.getCreatedBy().getName());
    Assert.assertEquals(parentFolderName, restoredFolder.getParent().getName());
}
 
Example #14
Source File: CustomerClientWiremockTest.java    From bootiful-testing-online-training with Apache License 2.0 6 votes vote down vote up
@Test
public void customerByIdShouldReturnACustomer() {

	WireMock.stubFor(WireMock.get(WireMock.urlMatching("/customers/1"))
		.willReturn(
			WireMock.aResponse()
				.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
				.withStatus(HttpStatus.OK.value())
				.withBody(asJson(customerById))
		));

	Customer customer = client.getCustomerById(1L);
	BDDAssertions.then(customer.getFirstName()).isEqualToIgnoringCase("first");
	BDDAssertions.then(customer.getLastName()).isEqualToIgnoringCase("last");
	BDDAssertions.then(customer.getEmail()).isEqualToIgnoringCase("email");
	BDDAssertions.then(customer.getId()).isEqualTo(1L);
}
 
Example #15
Source File: BoxLegalHoldPolicyTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testUpdateLegalHoldPolicySucceedsAndSendsCorrectJson() throws IOException {
    String result = "";
    final String legalHoldsID = "11111";
    final String legalHoldsURL = "/legal_hold_policies/" + legalHoldsID;
    final String legalHoldsDescription = "Documents related to our ongoing litigation";

    JsonObject updateObject = new JsonObject()
            .add("description", legalHoldsDescription);

    result = TestConfig.getFixture("BoxLegalHold/PutLegalHoldPoliciesID200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo(legalHoldsURL))
            .withRequestBody(WireMock.equalToJson(updateObject.toString()))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxLegalHoldPolicy policy = new BoxLegalHoldPolicy(this.api, legalHoldsID);
    BoxLegalHoldPolicy.Info policyInfo = policy.new Info();
    policyInfo.addPendingChange("description", legalHoldsDescription);
    policy.updateInfo(policyInfo);

    Assert.assertEquals(legalHoldsDescription, policyInfo.getDescription());
}
 
Example #16
Source File: AllureRestTemplateTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
protected final AllureResults execute() {
    final RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
    restTemplate.setInterceptors(Collections.singletonList(new AllureRestTemplate()));

    final WireMockServer server = new WireMockServer(WireMockConfiguration.options().dynamicPort());

    return runWithinTestContext(() -> {
        server.start();
        WireMock.configureFor(server.port());
        WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/hello")).willReturn(WireMock.aResponse().withBody("some body")));
        try {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            HttpEntity<JsonNode> entity = new HttpEntity<>(headers);
            ResponseEntity<String> result = restTemplate.exchange(server.url("/hello"), HttpMethod.GET, entity, String.class);
            Assertions.assertEquals(result.getStatusCode(), HttpStatus.OK);
        } finally {
            server.stop();
        }
    });
}
 
Example #17
Source File: StyxServerTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@Test
public void canConfigureWithStyxOrigins() {
    styxServer = new StyxServer.Builder()
            .addRoute("/", origin(originServer1.port()))
            .addRoute("/o2/", origin(originServer2.port()))
            .start();

    HttpResponse response1 = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
    assertThat(response1.status(), is(OK));
    assertThat(response1.header("origin"), isValue("first"));

    HttpResponse response2 = await(client.sendRequest(get(format("http://localhost:%d/o2/foo", styxServer.proxyHttpPort())).build()));
    assertThat(response2.status(), is(OK));
    assertThat(response2.header("origin"), isValue("second"));

    configureFor(originServer1.port());
    WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
    configureFor(originServer2.port());
    WireMock.verify(getRequestedFor(urlPathEqualTo("/o2/foo")));
}
 
Example #18
Source File: BoxFileTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetClassification() throws IOException {
    String getResult = "";
    final String fileID = "12345";
    final String metadataURL = "/files/" + fileID + "/metadata/enterprise/securityClassification-6VMVochwUWo";

    getResult = TestConfig.getFixture("BoxFile/CreateClassificationOnFile201");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(metadataURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(getResult)));

    BoxFile file = new BoxFile(this.api, fileID);
    String classification = file.getClassification();

    Assert.assertEquals("Public", classification);
}
 
Example #19
Source File: GithubMockBase.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public void setup() throws Exception {
    super.setup();
    //setup github api mock with WireMock
    new File("src/test/resources/api/mappings").mkdirs();
    new File("src/test/resources/api/__files").mkdirs();
    githubApi.enableRecordMappings(new SingleRootFileSource("src/test/resources/api/mappings"),
            new SingleRootFileSource("src/test/resources/api/__files"));

    if (useProxy) {
        githubApi.stubFor(
            WireMock.get(urlMatching(".*"))
                .atPriority(10)
                .willReturn(aResponse().proxiedFrom("https://api.github.com/")));
    }
    
    this.user = login("vivek", "Vivek Pandey", "[email protected]");
    this.githubApiUrl = String.format("http://localhost:%s",githubApi.port());
    this.crumb = getCrumb( j.jenkins );
}
 
Example #20
Source File: GithubEnterpriseApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void fetchExistingCredentialTokenInvalid() throws UnirestException {
    createGithubEnterpriseCredential();

    addPerTestStub(
        WireMock.get(urlEqualTo("/user"))
            .willReturn(aResponse().withStatus(401))
    );

    Map r = new RequestBuilder(baseUrl)
        .status(428)
        .jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId()))
        .get("/organizations/jenkins/scm/github-enterprise/?apiUrl="+githubApiUrl)
        .build(Map.class);

    assertTrue(r.get("message").toString().equals("Invalid accessToken"));
}
 
Example #21
Source File: LobbyWatcherClientTest.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
@Test
void updateGame(@WiremockResolver.Wiremock final WireMockServer server) {
  server.stubFor(
      post(LobbyWatcherClient.UPDATE_GAME_PATH)
          .withHeader(AuthenticationHeaders.API_KEY_HEADER, equalTo(EXPECTED_API_KEY))
          .withRequestBody(
              equalToJson(
                  toJson(
                      UpdateGameRequest.builder()
                          .gameId(GAME_ID)
                          .gameData(TestData.LOBBY_GAME)
                          .build())))
          .willReturn(WireMock.aResponse().withStatus(200)));

  newClient(server).updateGame(GAME_ID, TestData.LOBBY_GAME);
}
 
Example #22
Source File: AuthenticatedRestTemplateTest.java    From mojito with Apache License 2.0 6 votes vote down vote up
protected void initialAuthenticationMock() {
    String expectedResponse = "expected content";

    WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/" + formLoginConfig.getLoginFormPath()))
            .willReturn(WireMock.aResponse()
                    .withStatus(HttpStatus.OK.value())
                    .withHeader("Content-Type", "text/html")
                    .withBody(LOGIN_PAGE_HTML)));

    WireMock.stubFor(WireMock.post(WireMock.urlEqualTo("/" + formLoginConfig.getLoginPostPath()))
            .willReturn(WireMock.aResponse()
                    .withStatus(HttpStatus.FOUND.value())
                    .withHeader("Content-Type", "text/html")
                    .withHeader("Location", authenticatedRestTemplate.getURIForResource(formLoginConfig.getLoginRedirectPath()))
                    .withBody(expectedResponse)));
}
 
Example #23
Source File: WebhooksAcceptanceTest.java    From wiremock-webhooks-extension with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    targetServer.addMockServiceRequestListener(new RequestListener() {
        @Override
        public void requestReceived(Request request, Response response) {
            if (request.getUrl().startsWith("/callback")) {
                latch.countDown();
            }
        }
    });
    reset();
    notifier.reset();
    targetServer.stubFor(any(anyUrl())
        .willReturn(aResponse().withStatus(200)));
    latch = new CountDownLatch(1);
    client = new WireMockTestClient(rule.port());
    WireMock.configureFor(targetServer.port());

    System.out.println("Target server port: " + targetServer.port());
    System.out.println("Under test server port: " + rule.port());
}
 
Example #24
Source File: BoxWatermarkTest.java    From box-java-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetWatermarkOnFileSucceeds() throws IOException {
    String result = "";
    final String fileID = "12345";
    final String watermarkURL = "/files/" + fileID + "/watermark";

    result = TestConfig.getFixture("BoxWatermark/CreateWatermarkOnFile200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(watermarkURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxFile file = new BoxFile(this.api, fileID);
    BoxWatermark watermark = file.getWatermark();

    Assert.assertNotNull(watermark);
    Assert.assertNotNull(watermark.getCreatedAt());
    Assert.assertNotNull(watermark.getModifiedAt());
}
 
Example #25
Source File: RestSwaggerConnectorIntegrationTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotPassHeadersAlreadyPresentOnExchange() throws Exception {
    wiremock.givenThat(get("/v2/pet/123")
        .willReturn(ok(DOGGIE)
            .withHeader("Content-Type", "application/json")));

    final Map<String, Object> headers = new HashMap<>();
    headers.put("Host", "outside");
    headers.put("Accept", "application/xml");
    headers.put("Forwarded", "for=1.2.3.4;proto=http;by=4.3.2.1");
    headers.put("Cookie", "cupcake=chocolate");
    headers.put("Authorization", "Bearer supersecret");

    assertThat(context.createProducerTemplate().requestBodyAndHeaders("direct:getPetById",
        "{\"parameters\":{\"petId\":\"123\"}}", headers, String.class))
            .isEqualTo(DOGGIE);

    wiremock.verify(getRequestedFor(urlEqualTo("/v2/pet/123"))
        .withHeader("Host", equalTo("localhost:" + wiremock.port()))
        .withHeader("Accept", equalTo("application/json"))
        .withoutHeader("Forwarded")
        .withoutHeader("Cookie")
        .withoutHeader("Authorization")
        .withRequestBody(WireMock.equalTo("")));
}
 
Example #26
Source File: InstanceProfileCredentialsProviderTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveCredentials_requestsIncludeUserAgent() {
    String stubToken = "some-token";
    stubFor(put(urlPathEqualTo(TOKEN_RESOURCE_PATH)).willReturn(aResponse().withBody(stubToken)));
    stubFor(get(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH)).willReturn(aResponse().withBody("some-profile")));
    stubFor(get(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH + "some-profile")).willReturn(aResponse().withBody(STUB_CREDENTIALS)));

    InstanceProfileCredentialsProvider provider = InstanceProfileCredentialsProvider.builder().build();

    provider.resolveCredentials();

    String userAgentHeader = "User-Agent";
    String userAgent = UserAgentUtils.getUserAgent();
    WireMock.verify(putRequestedFor(urlPathEqualTo(TOKEN_RESOURCE_PATH)).withHeader(userAgentHeader, equalTo(userAgent)));
    WireMock.verify(getRequestedFor(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH)).withHeader(userAgentHeader, equalTo(userAgent)));
    WireMock.verify(getRequestedFor(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH + "some-profile")).withHeader(userAgentHeader, equalTo(userAgent)));
}
 
Example #27
Source File: LobbyWatcherClientTest.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Test
void sendKeepAlive(@WiremockResolver.Wiremock final WireMockServer server) {
  server.stubFor(
      post(LobbyWatcherClient.KEEP_ALIVE_PATH)
          .withHeader(AuthenticationHeaders.API_KEY_HEADER, equalTo(EXPECTED_API_KEY))
          .withRequestBody(equalTo(GAME_ID))
          .willReturn(WireMock.aResponse().withStatus(200).withBody("true")));

  final boolean result = newClient(server).sendKeepAlive(GAME_ID);

  assertThat(result, is(true));
}
 
Example #28
Source File: BoxFolderTest.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testDeleteClassification() throws IOException {
    final String folderID = "12345";
    final String metadataURL = "/folders/" + folderID
            + "/metadata/enterprise/securityClassification-6VMVochwUWo";

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.delete(WireMock.urlPathEqualTo(metadataURL))
           .willReturn(WireMock.aResponse()
                   .withHeader("Content-Type", "application/json-patch+json")
                   .withStatus(204)));

    BoxFolder folder = new BoxFolder(this.api, folderID);
    folder.deleteClassification();
}
 
Example #29
Source File: BoxWebLinkTest.java    From box-java-sdk with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetWebLinkSucceeds() throws IOException {
    String result = "";
    final String webLinkID = "12345";
    final String linkURL = "https://example.com";
    final String createdByName = "Test User";
    final String parentName = "Example Folder";
    final String modifiedByName = "Test User";
    final String ownedByLogin = "[email protected]";
    final String webLinkURL = "/web_links/" + webLinkID;

    result = TestConfig.getFixture("BoxWebLink/GetWebLinkOnFolder200");

    WIRE_MOCK_CLASS_RULE.stubFor(WireMock.get(WireMock.urlPathEqualTo(webLinkURL))
            .willReturn(WireMock.aResponse()
                    .withHeader("Content-Type", "application/json")
                    .withBody(result)));

    BoxWebLink webLink = new BoxWebLink(this.api, webLinkID);
    BoxWebLink.Info webLinkInfo = webLink.getInfo();

    Assert.assertEquals(webLinkID, webLinkInfo.getID());
    Assert.assertEquals(new URL(linkURL), webLinkInfo.getLinkURL());
    Assert.assertEquals(createdByName, webLinkInfo.getCreatedBy().getName());
    Assert.assertEquals(parentName, webLinkInfo.getParent().getName());
    Assert.assertEquals(modifiedByName, webLinkInfo.getModifiedBy().getName());
    Assert.assertEquals(ownedByLogin, webLinkInfo.getOwnedBy().getLogin());
}
 
Example #30
Source File: InstanceProfileCredentialsProviderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveCredentials_queriesTokenResource_405Error_fallbackToInsecure() {
    stubFor(put(urlPathEqualTo(TOKEN_RESOURCE_PATH)).willReturn(aResponse().withStatus(405).withBody("oops")));
    stubFor(get(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH)).willReturn(aResponse().withBody("some-profile")));
    stubFor(get(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH + "some-profile")).willReturn(aResponse().withBody(STUB_CREDENTIALS)));

    InstanceProfileCredentialsProvider provider = InstanceProfileCredentialsProvider.builder().build();

    provider.resolveCredentials();

    WireMock.verify(getRequestedFor(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH)));
    WireMock.verify(getRequestedFor(urlPathEqualTo(CREDENTIALS_RESOURCE_PATH + "some-profile")));
}