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:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateRemoteTokenServicesUnitTests.java

/**
 * Make sure invalid response from server causes authentication to fail.
 *///from  w w w .j  a  v  a  2 s.c  o m
@Test(expected = InvalidTokenException.class)
public void cantLoadAuthenticationOnError() {
    final AccessTokenConverter converter = Mockito.mock(AccessTokenConverter.class);
    final RestTemplate restTemplate = Mockito.mock(RestTemplate.class);
    final PingFederateRemoteTokenServices services = new PingFederateRemoteTokenServices(
            this.resourceServerProperties, converter, this.registry);
    services.setRestTemplate(restTemplate);
    final String accessToken = UUID.randomUUID().toString();

    final Map<String, Object> map = Maps.newHashMap();
    map.put(PingFederateRemoteTokenServices.ERROR_KEY, UUID.randomUUID().toString());

    @SuppressWarnings("unchecked")
    final ResponseEntity<Map> response = Mockito.mock(ResponseEntity.class);

    Mockito.when(restTemplate.exchange(Mockito.eq(CHECK_TOKEN_ENDPOINT_URL), Mockito.eq(HttpMethod.POST),
            Mockito.any(HttpEntity.class), Mockito.eq(Map.class))).thenReturn(response);

    Mockito.when(response.getBody()).thenReturn(map);

    // Should throw exception based on error key being present
    services.loadAuthentication(accessToken);
}

From source file:fragment.web.SupportControllerTest.java

@Test
public void testSupportRouting() throws Exception {
    logger.debug("Testing routing....Started");
    DispatcherTestServlet servlet = this.getServletInstance();
    Method expected = locateMethod(controller.getClass(), "listTickets",
            new Class[] { Tenant.class, String.class, String.class, Boolean.TYPE, String.class, String.class,
                    String.class, int.class, String.class, ModelMap.class });
    Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/support/tickets"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "createTicket",
            new Class[] { String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/support/tickets/create"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "createTicket",
            new Class[] { String.class, HttpServletRequest.class, TicketForm.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/support/tickets/create"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "viewTicket",
            new Class[] { Tenant.class, String.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/support/tickets/view"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "createNewComment",
            new Class[] { Tenant.class, TicketCommentForm.class, String.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/support/tickets/{ticketId}/comment"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "editTicket",
            new Class[] { Tenant.class, String.class, String.class, String.class, String.class, String.class,
                    HttpServletRequest.class, TicketForm.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/support/tickets/edit"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controller.getClass(), "closeTicket", new Class[] { Tenant.class, String.class,
            HttpServletRequest.class, TicketForm.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/support/tickets/close"));
    Assert.assertEquals(expected, handler);

    logger.debug("Testing routing.... Done");
}

From source file:com.teradata.benchto.driver.DriverAppIntegrationTest.java

private void verifySerialExecutionFinished(String uniqueBenchmarkName, String queryName, int executionNumber,
        List<String> measurementNames) {
    verifyExecutionFinished(uniqueBenchmarkName, executionNumber, measurementNames);

    restServiceServer.expect(matchAll(requestTo("http://graphite:18088/events/"), method(HttpMethod.POST),
            jsonPath("$.what",
                    is("Benchmark " + uniqueBenchmarkName + ", query " + queryName + " (" + executionNumber
                            + ") ended")),
            jsonPath("$.tags", is("execution ended TEST_ENV")), jsonPath("$.data", startsWith("duration: "))))
            .andRespond(withSuccess());/*from w  w w.j a va 2  s  . c  om*/
}

From source file:ru.anr.base.facade.web.api.RestClient.java

/**
 * POST for a form//from ww w . jav  a2 s  . co  m
 * 
 * @param path
 *            Path to resource
 * @param formData
 *            Form params
 * @return Http status for response
 */
public ResponseEntity<Void> post(String path, MultiValueMap<String, String> formData) {

    setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    return exchange(getUri(path), HttpMethod.POST, formData, (Class<Void>) null);
}

From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java

@Override
public Boolean reSendMobilePin(CustomerIdTypeMobileTypeDTO customerDTO) {

    HttpEntity<CustomerIdTypeMobileTypeDTO> entity = new HttpEntity<CustomerIdTypeMobileTypeDTO>(customerDTO);

    ResponseEntity<Boolean> detailsSentStatus = restTemplate.exchange(
            env.getProperty("rest.host") + "/customer/quickregister/resendMobilePin", HttpMethod.POST, entity,
            Boolean.class);

    if (detailsSentStatus.getStatusCode() == HttpStatus.OK)
        return detailsSentStatus.getBody();
    else//from w w w. j a va2  s  . c o m
        throw new ResourceNotFoundException();
}

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

@Test
public void downloadChanges() {
    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(DOWNLOAD_CHANGES_CONTENT).headers(responseHeaders));

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

    InputStreamCallback inputStream = new InputStreamCallback() {

        public void doWithInputStream(InputStream inputStream) throws IOException {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            IOUtils.copy(inputStream, outputStream);

            Assert.assertEquals(new String(DOWNLOAD_CHANGES_CONTENT), new String(outputStream.toByteArray()));
        }/*from   ww w .  j  a va2s. co  m*/

    };

    this.syncOperations.downloadChangesForTables(inputStream, loggedTable, otherTable);

    mockServer.verify();
}

From source file:de.hska.ld.core.AbstractIntegrationTest.java

protected HttpRequestWrapper post() {
    return new HttpRequestWrapper(HttpMethod.POST);
}

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

@Test
public void logout() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/users/logout")).andExpect(method(HttpMethod.POST))
            .andExpect(header(UserSessionPersistence.X_APPGLU_SESSION_HEADER, "sessionId"))
            .andRespond(withStatus(HttpStatus.OK).headers(responseHeaders));

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    appGluTemplate.setUserSessionPersistence(new LoggedInUserSessionPersistence("sessionId", new User("test")));

    Assert.assertTrue(appGluTemplate.isUserAuthenticated());
    Assert.assertNotNull(appGluTemplate.getAuthenticatedUser());

    Assert.assertEquals("test", appGluTemplate.getAuthenticatedUser().getUsername());

    boolean succeed = userOperations.logout();
    Assert.assertTrue(succeed);/* w w w  . ja  va  2  s  .com*/

    Assert.assertFalse(appGluTemplate.isUserAuthenticated());
    Assert.assertNull(appGluTemplate.getAuthenticatedUser());

    mockServer.verify();
}

From source file:org.cloudfoundry.identity.batch.integration.ServerRunning.java

public ResponseEntity<Void> postForResponse(String path, HttpHeaders headers,
        MultiValueMap<String, String> params) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);/* w ww. j a va2s  .  c o  m*/
    actualHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    return client.exchange(getUrl(path), HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(params, actualHeaders), null);
}

From source file:com.orange.ngsi2.client.Ngsi2ClientTest.java

@Test
public void testUpdateEntity_Append() throws Exception {

    mockServer.expect(requestTo(baseURL + "/v2/entities/room1?type=Room&options=append"))
            .andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.temperature.value").value(35.6)).andRespond(withNoContent());

    ngsiClient.updateEntity("room1", "Room", Collections.singletonMap("temperature", new Attribute(35.6)), true)
            .get();// w ww  .  j  a va2s. c o  m
}