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:org.cloudfoundry.identity.uaa.scim.RemoteScimUserProvisioningTests.java

@Test
public void testRemoveUser() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", "123456789");
    Mockito.when(restTemplate.exchange(Mockito.eq("http://base/User/{id}"), Mockito.eq(HttpMethod.DELETE),
            Mockito.argThat(new HttpHeadersMatcher()), Mockito.eq(ScimUser.class), Mockito.eq("1234")))
            .thenReturn(new ResponseEntity<ScimUser>(user, HttpStatus.OK));
    service.removeUser("1234", 123456789);
}

From source file:com.walmart.gatling.AbstractRestIntTest.java

protected HttpStatus delete(String url) {
    ResponseEntity<Void> response = template.exchange(url, HttpMethod.DELETE, null, Void.class);
    HttpStatus code = response.getStatusCode();
    if (code == HttpStatus.OK || code == HttpStatus.NO_CONTENT || code == HttpStatus.NOT_FOUND)
        return response.getStatusCode();
    else {/*ww w.  j av a  2 s . c  om*/
        fail("Expected the delete response to be 200 or 404, but was " + code.value() + "("
                + code.getReasonPhrase() + ").");
        return null; //for compiler
    }
}

From source file:org.zalando.github.spring.UsersTemplatePublicKeyTest.java

@Test
public void deletePublicKey() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/user/keys/1")).andExpect(method(HttpMethod.DELETE))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(MockRestResponseCreators.withNoContent());

    usersTemplate.deletePublicKey(1);//ww w  . j a  v  a 2  s .c  om
}

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

@Test
@OAuth2ContextConfiguration(resource = TokenResourceOwnerPassword.class)
public void testRevokeTokenByUser() throws Exception {

    OAuth2AccessToken token = context.getAccessToken();
    String hash = new StandardPasswordEncoder().encode(token.getValue());

    HttpEntity<?> request = new HttpEntity<String>(token.getValue());
    assertEquals(HttpStatus.OK,//w  ww .  java  2  s .co  m
            serverRunning
                    .getRestTemplate().exchange(serverRunning.getUrl("/oauth/users/{user}/tokens/{token}"),
                            HttpMethod.DELETE, request, Void.class, testAccounts.getUserName(), hash)
                    .getStatusCode());

    // The token was revoked so if we trya nd use it again it should come back unauthorized
    ResponseEntity<String> result = serverRunning
            .getForString("/oauth/users/" + testAccounts.getUserName() + "/tokens");
    assertEquals(HttpStatus.UNAUTHORIZED, result.getStatusCode());
    String body = result.getBody();
    assertTrue("Wrong body: " + body, body.contains("invalid_token"));

}

From source file:org.cloudfoundry.identity.uaa.scim.remote.RemoteScimUserProvisioningTests.java

@Test
public void testRemoveUser() {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", "123456789");
    Mockito.when(restTemplate.exchange(Mockito.eq("http://base/User/{id}"), Mockito.eq(HttpMethod.DELETE),
            Mockito.argThat(new HttpHeadersMatcher()), Mockito.eq(ScimUser.class), Mockito.eq("1234")))
            .thenReturn(new ResponseEntity<ScimUser>(user, HttpStatus.OK));
    service.delete("1234", 123456789);
}

From source file:com.logaritex.hadoop.configuration.manager.http.AndroidHttpService.java

public <R> R delete(String url, Object request, Class<R> responseType, Object... uriVariables) {
    R response = restTemplate.exchange(baseUrl + url, HttpMethod.DELETE,
            new HttpEntity<Object>(request, httpHeaders), responseType, uriVariables).getBody();

    return response;
}

From source file:org.springbyexample.contact.web.client.AbstractPersistenceClient.java

public R delete(Integer id) {
    R response = null;/*from w w w. ja v  a 2s. c om*/

    String url = client.createUrl(deletePkRequest);

    logger.debug("REST client delete.  id={}  url='{}'", id, url);

    Map<String, Long> vars = createPkVars(id);

    response = client.getRestTemplate().exchange(url, HttpMethod.DELETE, null, responseClazz, vars).getBody();

    return response;
}

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

@SuppressWarnings("rawtypes")
private ResponseEntity<Map> deleteUser(String id, int version) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + version + "\"");
    return client.exchange(serverRunning.getUrl(userEndpoint + "/{id}"), HttpMethod.DELETE,
            new HttpEntity<Void>(headers), Map.class, id);
}

From source file:org.cloudfoundry.identity.uaa.scim.RemoteScimUserProvisioning.java

@Override
public ScimUser removeUser(String id, int version) throws ScimResourceNotFoundException {
    HttpHeaders headers = new HttpHeaders();
    headers.set("If-Match", String.format("%d", version));
    return restTemplate.exchange(baseUrl + "/User/{id}", HttpMethod.DELETE, new HttpEntity<Void>(headers),
            ScimUser.class, id).getBody();
}

From source file:com.appglu.impl.ApiExceptionsTest.java

@Test
public void serverError() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/tables/user/2"))
            .andExpect(method(HttpMethod.DELETE)).andRespond(
                    withServerError().body(compactedJson("data/error_server_error")).headers(responseHeaders));

    try {/*  ww  w. j a  v  a2  s .c o m*/
        crudOperations.delete("user", 2);
        Assert.fail("Should had caused a exception");
    } catch (AppGluHttpServerException e) {
        Error error = e.getError();

        Assert.assertEquals(ErrorCode.GENERIC_SERVER_ERROR, error.getCode());
        Assert.assertEquals(
                "An unexpected error occurred while processing your request. Please try again later.",
                error.getMessage());
        Assert.assertNull(error.getDetail());
    }

    mockServer.verify();
}