Example usage for org.springframework.http HttpMethod POST

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

Introduction

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

Prototype

HttpMethod POST

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

Click Source Link

Usage

From source file:org.echocat.marquardt.example.ServiceLoginIntegrationTest.java

private void whenAccessingUnprotectedResourceOnService() {
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.exchange(baseUriOfApp() + "/exampleservice/someUnprotectedResource", HttpMethod.POST, null,
            Void.class);
}

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

@Test
public void changesForTablesUsingCallback() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/sync/changes")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/sync_changes_for_tables_request")))
            .andRespond(withStatus(HttpStatus.OK).body(compactedJson("data/sync_changes_for_tables_response"))
                    .headers(responseHeaders));

    MemoryTableChangesCallback callback = new MemoryTableChangesCallback();

    TableVersion loggedTable = new TableVersion("logged_table");
    TableVersion otherTable = new TableVersion("other_table", 1);

    this.syncOperations.changesForTables(callback, loggedTable, otherTable);

    this.assertChanges(callback.getTableChanges());

    mockServer.verify();/*from w  w w.  j  a  v a  2s . com*/
}

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

@Test
public void queryContextRequestOK() throws Exception {

    ngsiClient.protocolRegistry.unregisterHost(baseUrl);

    String responseBody = json(jsonConverter, createQueryContextResponseTemperature());

    this.mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(header("Accept", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.entities[*]", hasSize(1)))
            .andExpect(jsonPath("$.entities[0].id").value("S*"))
            .andExpect(jsonPath("$.entities[0].type").value("TempSensor"))
            .andExpect(jsonPath("$.entities[0].isPattern").value("true"))
            .andExpect(jsonPath("$.attributes[*]", hasSize(1)))
            .andExpect(jsonPath("$.attributes[0]").value("temp"))
            .andExpect(jsonPath("*.restriction").doesNotExist())
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    QueryContextResponse response = ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature())
            .get();//from  www  .  j a  va2  s.  c  om
    this.mockServer.verify();

    Assert.assertEquals(1, response.getContextElementResponses().size());
    Assert.assertEquals(CodeEnum.CODE_200.getLabel(),
            response.getContextElementResponses().get(0).getStatusCode().getCode());
    Assert.assertEquals("S1",
            response.getContextElementResponses().get(0).getContextElement().getEntityId().getId());
    Assert.assertEquals("TempSensor",
            response.getContextElementResponses().get(0).getContextElement().getEntityId().getType());
    Assert.assertEquals(false,
            response.getContextElementResponses().get(0).getContextElement().getEntityId().getIsPattern());
    Assert.assertEquals(1,
            response.getContextElementResponses().get(0).getContextElement().getContextAttributeList().size());
    Assert.assertEquals("temp", response.getContextElementResponses().get(0).getContextElement()
            .getContextAttributeList().get(0).getName());
    Assert.assertEquals("float", response.getContextElementResponses().get(0).getContextElement()
            .getContextAttributeList().get(0).getType());
    Assert.assertEquals("15.5", response.getContextElementResponses().get(0).getContextElement()
            .getContextAttributeList().get(0).getValue());
}

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

/**
 * {@inheritDoc}//from   w  w w  .ja va  2s  . co m
 */
public boolean logout() throws AppGluRestClientException {
    try {
        this.restOperations.exchange(LOGOUT_URL, HttpMethod.POST, null, Void.class);
        this.userSessionPersistence.logout();
        return true;
    } catch (AppGluHttpUserUnauthorizedException e) {
        this.userSessionPersistence.logout();
        return false;
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.citrix.g2w.webdriver.dependencies.AccountServiceQAIImpl.java

/**
 * Method used to add user to an account.
 * /*from   ww  w  .  j a  v  a 2s . com*/
 * @param accountKey
 *            (user account key)
 * @param firstName
 *            (user first name)
 * @param lastName
 *            (user last name)
 * @param email
 *            (user email)
 * @param password
 *            (user password)
 * @param locale
 *            (user locale)
 * @param timezone
 *            (user timezone)
 * @return long
 */
private Long addUserToAccount(final Long accountKey, final String firstName, final String lastName,
        final String email, final String password, final String locale, final String timezone) {
    String userKey;
    try {
        JSONObject userJson = new JSONObject();
        userJson.put("email", email);
        userJson.put("firstName", firstName);
        userJson.put("lastName", lastName);
        userJson.put("password", password);
        userJson.put("locale", locale);
        userJson.put("timezone", timezone);

        HttpEntity httpEntity = new HttpEntity(userJson.toString(), this.accountSvcHeaders);
        userKey = this.restTemplate.exchange(this.accountSvcUrl + "/accounts/" + accountKey + "/users",
                HttpMethod.POST, httpEntity, String.class).getBody();
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }
    return Long.valueOf(userKey);
}

From source file:org.awesomeagile.integrations.hackpad.HackpadClientTest.java

@Test(expected = RuntimeException.class)
public void testUpdateHackpadFailure() {
    String newContent = "<html><body>This is a new content</body></html>";
    String padId = RandomStringUtils.randomAlphanumeric(16);
    mockServer.expect(requestTo("http://test/api/1.0/pad/" + padId + "/content"))
            .andExpect(method(HttpMethod.POST)).andExpect(header(HTTP.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE))
            .andExpect(content().string(newContent))
            .andRespond(withSuccess("{\"success\": false}", MediaType.APPLICATION_JSON));
    client.updateHackpad(new PadIdentity(padId), newContent);
}

From source file:org.cloudfoundry.identity.uaa.login.feature.LoginIT.java

@Test
public void testRedirectAfterFailedLogin() throws Exception {
    RestTemplate template = new RestTemplate();
    LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>();
    body.add("username", testAccounts.getUserName());
    body.add("password", "invalidpassword");
    ResponseEntity<Void> loginResponse = template.exchange(baseUrl + "/login.do", HttpMethod.POST,
            new HttpEntity<>(body, null), Void.class);
    assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode());
}

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

@Test
public void nonImplicitGrantClientWithoutSecretIsRejected() throws Exception {
    OAuth2AccessToken token = getClientCredentialsAccessToken("clients.read clients.write");
    HttpHeaders headers = getAuthenticatedHeaders(token);
    BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar",
            "client_credentials", "uaa.none");
    ResponseEntity<UaaException> result = serverRunning.getRestTemplate().exchange(
            serverRunning.getUrl("/oauth/clients"), HttpMethod.POST,
            new HttpEntity<BaseClientDetails>(client, headers), UaaException.class);
    assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    assertEquals("invalid_client", result.getBody().getErrorCode());
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restSchemaDoesNotExistsTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    headers.add("graphql-schema", "no-such-schema");

    GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}");

    HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers);
    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, httpEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertFalse(CollectionUtils.isEmpty(result.getErrors()));
    LOGGER.info(objectMapper.writeValueAsString(result));
}

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

@Test
public void registerContextRequestOK() throws Exception {

    ngsiClient.protocolRegistry.unregisterHost(baseUrl);
    String responseBody = json(jsonConverter, createRegisterContextResponseTemperature());

    this.mockServer.expect(requestTo(baseUrl + "/ngsi9/registerContext")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(header("Accept", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.contextRegistrations[*]", hasSize(1)))
            .andExpect(jsonPath("$.contextRegistrations[0].providingApplication")
                    .value("http://localhost:1028/accumulate"))
            .andExpect(jsonPath("$.contextRegistrations[0].entities[*]", hasSize(1)))
            .andExpect(jsonPath("$.contextRegistrations[0].entities[0].id").value("Room*"))
            .andExpect(jsonPath("$.contextRegistrations[0].entities[0].type").value("Room"))
            .andExpect(jsonPath("$.contextRegistrations[0].entities[0].isPattern").value("true"))
            .andExpect(jsonPath("$.contextRegistrations[0].attributes[*]", hasSize(1)))
            .andExpect(jsonPath("$.contextRegistrations[0].attributes[0].name").value("temperature"))
            .andExpect(jsonPath("$.contextRegistrations[0].attributes[0].type").value("float"))
            .andExpect(jsonPath("$.contextRegistrations[0].attributes[0].isDomain").value("false"))
            .andExpect(jsonPath("$.duration").value("PT10S"))
            .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    RegisterContextResponse response = ngsiClient
            .registerContext(baseUrl, null, createRegisterContextTemperature()).get();
    this.mockServer.verify();

    Assert.assertNull(response.getErrorCode());
    Assert.assertEquals("123456789", response.getRegistrationId());
    Assert.assertEquals("PT10S", response.getDuration());
}