Example usage for org.springframework.http HttpMethod DELETE

List of usage examples for org.springframework.http HttpMethod DELETE

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod DELETE.

Prototype

HttpMethod DELETE

To view the source code for org.springframework.http HttpMethod DELETE.

Click Source Link

Usage

From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImplTest.java

@Test
public void testUpdatePageWithPaginationModeIndividual() {
    final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig();
    swaggerConfluenceConfig.setPaginationMode(PaginationMode.INDIVIDUAL_PAGES);

    final String xhtml = IOUtils.readFull(
            AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream("/swagger-petstore-xhtml-example.html"));

    final ResponseEntity<String> postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK);

    final List<String> returnJson = new ArrayList<>();

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class), eq(String.class)))
            .thenReturn(responseEntity);

    for (int i = 0; i < 34; i++) {
        if (i > 0) {
            returnJson.add(GET_RESPONSE_FOUND);
        }/*from w  w  w. ja va 2  s . c o m*/

        if (CATEGORY_INDEXES.contains(i)) {
            returnJson.add(GET_CHILDREN);
        }
    }

    final String[] returnJsonArray = new String[returnJson.size()];
    returnJson.toArray(returnJsonArray);

    when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND, returnJsonArray);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.DELETE), any(RequestEntity.class),
            eq(String.class))).thenReturn(responseEntity);
    when(responseEntity.getStatusCode()).thenReturn(HttpStatus.NO_CONTENT);

    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), any(RequestEntity.class), eq(String.class)))
            .thenReturn(postResponseEntity);

    final ArgumentCaptor<HttpEntity> httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class);

    xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml);

    verify(restTemplate, times(38)).exchange(any(URI.class), eq(HttpMethod.GET), any(RequestEntity.class),
            eq(String.class));
    verify(restTemplate, times(34)).exchange(any(URI.class), eq(HttpMethod.PUT), httpEntityCaptor.capture(),
            eq(String.class));

    final HttpEntity<String> capturedHttpEntity = httpEntityCaptor.getAllValues().get(30);

    final String expectedPostBody = IOUtils.readFull(AsciiDocToXHtmlServiceImplTest.class
            .getResourceAsStream("/swagger-confluence-update-json-body-user-example.json"));

    assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity);
    // We'll do a full check on the last page versus a resource; not doing all of them as it
    // would be a pain to maintain, but this should give us a nod of confidence.
    assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody());
}

From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java

public void testResourceUpdateAttributes() {
    BaseResource resource1 = this.privilegeHelper.createResource("marissa");
    BaseResource resource2 = this.privilegeHelper.createResource("marissa");
    Set<Attribute> attributes = new HashSet<Attribute>();
    Attribute attribute = new Attribute();
    attribute.setName("site");
    attribute.setIssuer("http://attributes.net");
    attribute.setValue("sanfrancisco");
    attributes.add(attribute);/*  w w w  . j a va2s .  c o m*/
    resource2.setAttributes(attributes);

    this.acsAdminRestTemplate.put(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa",
            new HttpEntity<>(resource1, this.zone1Headers));
    this.acsAdminRestTemplate.put(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa",
            new HttpEntity<>(resource2, this.zone1Headers));
    ResponseEntity<BaseResource> response = acsAdminRestTemplate.exchange(
            this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa", HttpMethod.GET,
            new HttpEntity<>(this.zone1Headers), BaseResource.class);
    Assert.assertEquals(response.getBody(), resource2);
    this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa",
            HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class);
}

From source file:com.orange.ngsi.client.NgsiRestClientTest.java

@Test
public void testDeleteContextAttributeValue_JSON() throws Exception {
    String responseBody = json(jsonConverter, new StatusCode(CodeEnum.CODE_200));

    mockServer.expect(requestTo(baseUrl + "/ngsi10/contextEntities/123/attributes/temp/1"))
            .andExpect(method(HttpMethod.DELETE))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    StatusCode response = ngsiRestClient.deleteContextAttributeValue(baseUrl, null, "123", "temp", "1").get();

    this.mockServer.verify();

    assertEquals(CodeEnum.CODE_200.getLabel(), response.getCode());
}

From source file:org.cloudfoundry.identity.uaa.integration.ScimUserEndpointsIntegrationTests.java

@Test
public void deleteUserWithNoEtagSucceeds() throws Exception {
    ScimUser deleteMe = createUser(DELETE_ME, "Delete", "Me", "deleteme@blah.com").getBody();

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response = client.exchange(serverRunning.getUrl(userEndpoint + "/{id}"),
            HttpMethod.DELETE, new HttpEntity<Void>((Void) null), Map.class, deleteMe.getId());
    assertEquals(HttpStatus.OK, response.getStatusCode());
}

From source file:com.ge.predix.acceptance.test.zone.admin.ZoneEnforcementStepsDefinitions.java

@When("^client_two does a DELETE on (.*?) with (.*?) in zone (.*?)$")
public void client_two_does_a_DELETE_on_api_with_identifier_in_test_zone_dev(final String api,
        final String identifier, final String zone) throws Throwable {

    OAuth2RestTemplate acsTemplate = this.acsZone2Template;
    String zoneName = getZoneName(zone);

    HttpHeaders zoneHeaders = new HttpHeaders();
    zoneHeaders.set(PolicyHelper.PREDIX_ZONE_ID, zoneName);

    String encodedIdentifier = URLEncoder.encode(identifier, "UTF-8");
    URI uri = URI.create(this.acsUrl + ACS_VERSION + "/" + api + "/" + encodedIdentifier);
    try {//from   www .j a v a2s.c o m
        this.status = acsTemplate
                .exchange(uri, HttpMethod.DELETE, new HttpEntity<>(zoneHeaders), ResponseEntity.class)
                .getStatusCode().value();
    } catch (HttpClientErrorException e) {
        Assert.fail("Unable to DELETE identifier: " + identifier + " for api: " + api);
    }
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void compareAndDeleteWithPrevIndex() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevIndex=3"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.compareAndDelete("sample", 3);
    Assert.assertNotNull("response", response);

    server.verify();// w  w  w . jav  a 2 s .  c om
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java

private String getUIAppUrl(String uiServiceInstanceGuid) throws IOException {
    LOGGER.info("Getting UI App URL using create service key function");
    String body = String.format(CREATE_SERVICE_KEY_BODY_TEMPLATE, uiServiceInstanceGuid);
    ResponseEntity<String> response = execute(POST_CREATE_SERVICE_KEY_URL, HttpMethod.POST, body,
            cfApiEndpoint);//from   w ww.  j  a v a 2s  .c om
    String uiAppUrl = cfCaller.getValueFromJson(response.getBody(), APP_URL);
    String serviceKeyGuid = cfCaller.getValueFromJson(response.getBody(), METADATA_GUID);
    LOGGER.info("Deleting service key");
    execute(DELETE_SERVICE_KEY_URL, HttpMethod.DELETE, "", cfApiEndpoint, serviceKeyGuid);
    LOGGER.debug("UI App url '{}'", uiAppUrl);
    return uiAppUrl;
}

From source file:com.ge.predix.integration.test.PrivilegeManagementAccessControlServiceIT.java

@Test
public void testBatchResourcesDataConstraintViolationResourceIdentifier() {
    List<BaseResource> resources = new ArrayList<BaseResource>();
    resources.add(this.privilegeHelper.createResource("dupResourceIdentifier"));
    resources.add(this.privilegeHelper.createResource("dupResourceIdentifier"));

    try {// ww w .j  a  v  a 2 s  .  co  m
        // This POST causes a data constraint violation on the service bcos
        // of duplicate
        // resource_identifiers which returns a HTTP 422 error.
        this.acsAdminRestTemplate.postForEntity(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH,
                new HttpEntity<>(resources, this.zone1Headers), ResponseEntity.class);
    } catch (HttpClientErrorException e) {
        Assert.assertEquals(e.getStatusCode(), HttpStatus.UNPROCESSABLE_ENTITY);
        return;
    }
    this.acsAdminRestTemplate.exchange(this.acsUrl + PrivilegeHelper.ACS_RESOURCE_API_PATH + "/marissa",
            HttpMethod.DELETE, new HttpEntity<>(this.zone1Headers), ResponseEntity.class);
    Assert.fail(
            "Expected unprocessable entity http client error on post for 2 resources with duplicate resource"
                    + "identifiers.");
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.CloudFoundryService.java

public void deleteUIServiceInstance(String uiServiceGuid) {
    try {/*www .ja  va 2s  . c  o m*/
        execute(DELETE_SERVICE_URL, HttpMethod.DELETE, "", cfApiEndpoint, uiServiceGuid);
    } catch (HttpClientErrorException e) {
        if (e.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            LOGGER.warn("GearPump UI instance with GUID {} doesn't exist. Skipping.", uiServiceGuid);
        } else {
            LOGGER.debug("Cannot delete GearPump UI instance with GUID {} - rethrowing excepiton.",
                    uiServiceGuid);
            throw e;
        }
    }
}