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.akaademiwolof.ConfigurationTests.java

@SuppressWarnings("static-access")
//@Test/*w w w  .  j a  v  a  2s .  co  m*/
public void shouldUpdateWordWhenSendingRequestToController() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    JSONObject requestJson = new JSONObject();
    requestJson.wrap(json);
    System.out.print(requestJson.toString());

    headers.setContentType(MediaType.APPLICATION_JSON);

    HttpEntity<String> entity = new HttpEntity<String>(json, headers);

    ResponseEntity<String> loginResponse = restTemplate.exchange(localhostUrl, HttpMethod.POST, entity,
            String.class);
    if (loginResponse.getStatusCode() == HttpStatus.OK) {
        JSONObject wordJson = new JSONObject(loginResponse.getBody());
        System.out.print(loginResponse.getStatusCode());
        assertThat(wordJson != null);

    } else if (loginResponse.getStatusCode() == HttpStatus.BAD_REQUEST) {
        System.out.print(loginResponse.getStatusCode());
    }

}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java

@Test
public void basicAuthenticationServiceTestInvalidCredentials() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.set("Authorization", "Basic " + new String(Base64.encode("user:badpassword".getBytes("UTF-8"))));
    HttpEntity<String> entity = new HttpEntity<String>("headers", headers);

    ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity,
            AuthorizationData.class);
    assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
}

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

@Test(expected = HttpClientErrorException.class)
public void notifyContextRequestWith404() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/notifyContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.notifyContext(baseUrl, null, createNotifyContextTempSensor(0)).get();
}

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

@Test
public void create() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/tables/user")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/crud_row_relationships")))
            .andRespond(withStatus(HttpStatus.CREATED).body(compactedJson("data/crud_create_response"))
                    .headers(responseHeaders));

    Row row = row();//from   ww w. j a v a 2 s. co  m

    Object id = crudOperations.create("user", row);
    Assert.assertEquals(8, id);

    mockServer.verify();
}

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

@Test(expected = HttpClientErrorException.class)
public void queryContextRequestWith404() throws Exception {

    mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature()).get();
}

From source file:com.pepaproch.gtswsdlclient.AuthTokenProviderImplTest.java

/**
 * Test of revoked method, of class AuthTokenProviderImpl.
 */// w w w .  j  av a 2s .c  om
@Test
public void testRevoked() {
    AuthTokenProvider instance = new AuthTokenProviderImpl(BASE_URL, "test", "test", restTemplate, 10);
    mockServer = MockRestServiceServer.createServer(restTemplate);
    this.mockServer.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST))
            .andRespond(withSuccess("{\"accessToken\" : \"testtoken\" }", MediaType.APPLICATION_JSON));
    this.mockServer.expect(requestTo(BASE_URL + AUTH_PATH)).andExpect(method(HttpMethod.POST)).andRespond(
            withSuccess("{\"accessToken\" : \"test token after revoke\" }", MediaType.APPLICATION_JSON));

    String authorisationToken = instance.getAuthorisationToken().getToken();

    this.revokedListener = (AuthTokenRevokedListener) instance;
    this.revokedListener.revoked(instance.getAuthorisationToken());

    String authorisationToken2 = instance.getAuthorisationToken().getToken();
    this.mockServer.verify();
    assertNotSame(authorisationToken, authorisationToken2);

}

From source file:com.ctrip.infosec.rule.rest.RuleEngineRESTfulControllerTest.java

@Test
@Ignore/*from   w w w  .  j  a v  a  2s .c  o m*/
public void testQuery() throws Exception {
    System.out.println("query");

    String response = Request.Post("http://10.2.10.77:8080/ruleenginews/rule/query")
            .body(new StringEntity(JSON.toJSONString(fact), "UTF-8")).connectTimeout(1000).socketTimeout(5000)
            .execute().returnContent().asString();
    System.out.println("response: " + response);

    ResponseEntity<String> responseEntity = rt.exchange("http://10.2.10.77:8080/ruleenginews/rule/query",
            HttpMethod.POST, new HttpEntity<String>(JSON.toJSONString(fact)), String.class);
    System.out.println("response: " + responseEntity.getBody());

}

From source file:com.expedia.seiso.SeisoWebSecurityConfig.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off
    http//from  w ww. ja v a 2  s .co  m
            // TODO Would prefer to do this without sessions if possible. But see
            // https://spring.io/guides/tutorials/spring-security-and-angular-js/
            // http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-sticky-sessions.html
            //         .sessionManagement()
            //            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            //            .and()
            .authorizeRequests().antMatchers(HttpMethod.GET, "/internal/**").permitAll()
            .antMatchers(HttpMethod.GET, "/api/**").permitAll().antMatchers(HttpMethod.POST, "/api/**")
            .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PUT, "/api/**")
            .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.DELETE, "/api/**")
            .hasAnyRole(Roles.USER, Roles.ADMIN).antMatchers(HttpMethod.PATCH, "/api/**")
            .hasAnyRole(Roles.USER, Roles.ADMIN)

            // Admin console
            .antMatchers(HttpMethod.GET, "/admin").hasRole(Roles.ADMIN).antMatchers(HttpMethod.GET, "/admin/**")
            .hasRole(Roles.ADMIN)

            // Blacklist
            .anyRequest().denyAll()
            //            .anyRequest().hasRole(Roles.USER)
            .and().httpBasic().authenticationEntryPoint(entryPoint()).and().exceptionHandling()
            .authenticationEntryPoint(entryPoint()).and()
            // FIXME Enable. See https://spring.io/guides/tutorials/spring-security-and-angular-js/
            .csrf().disable();
    // @formatter:on
}

From source file:org.openlmis.fulfillment.service.stockmanagement.StockEventStockManagementServiceTest.java

@Test(expected = ExternalApiException.class)
public void shouldThrowExceptionOnBadRequest() throws IOException {
    when(objectMapper.readValue(anyString(), eq(LocalizedMessageDto.class)))
            .thenReturn(new LocalizedMessageDto());
    when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), any(HttpEntity.class), eq(UUID.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST));

    service.submit(new StockEventDto());
}

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

@Test(expected = HttpClientErrorException.class)
public void subscribeContextRequestWith404() throws Exception {

    this.mockServer.expect(requestTo(baseUrl + "/ngsi10/subscribeContext")).andExpect(method(HttpMethod.POST))
            .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
}