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.cisco.cta.taxii.adapter.AdapterTaskMultipartIT.java

@Before
public void setUp() throws Exception {
    initLogbackOutput();/*from w  w w. j a v  a 2s. c om*/
    MockitoAnnotations.initMocks(this);
    pollServiceUri = new URI("https://taxii.cloudsec.sco.cisco.com/skym-taxii-ws/PollService/");
    when(httpRequestFactory.createRequest(pollServiceUri, HttpMethod.POST)).thenReturn(httpReq, httpReq2);
    httpReqHeaders = new HttpHeaders();

    when(httpReq.getHeaders()).thenReturn(httpReqHeaders);
    httpReqBody = new ByteArrayOutputStream();
    when(httpReq.getBody()).thenReturn(httpReqBody);
    when(httpReq.execute()).thenReturn(httpResp);

    when(httpReq2.getHeaders()).thenReturn(httpReqHeaders);
    httpReq2Body = new ByteArrayOutputStream();
    when(httpReq2.getBody()).thenReturn(httpReq2Body);
    when(httpReq2.execute()).thenReturn(httpResp2);

    taxiiPollRespBodyInitial = AdapterTaskMultipartIT.class
            .getResourceAsStream("/taxii-poll-response-mp-body-initial.xml");
    taxiiPollRespBodyNext = AdapterTaskMultipartIT.class
            .getResourceAsStream("/taxii-poll-response-mp-body-next.xml");
}

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

@Test
public void createTeam() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/orgs/zalando-stups/teams"))
            .andExpect(method(HttpMethod.POST)).andExpect(content().contentType(MediaType.APPLICATION_JSON))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(/*from  w  w w. j  a v  a 2 s.  co m*/
                    withSuccess(new ClassPathResource("getTeam.json", getClass()), MediaType.APPLICATION_JSON));

    Team team = teamsTemplate.createTeam("zalando-stups", new TeamRequest("Justice League"));

    Assertions.assertThat(team).isNotNull();
    Assertions.assertThat(team.getId()).isEqualTo(1);
    Assertions.assertThat(team.getName()).isEqualTo("Justice League");
}

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

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

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

    ngsiClient.registerContext(baseUrl, null, createRegisterContextTemperature()).get();
}

From source file:fragment.web.TasksControllerTest.java

@Test
public void testRouting() throws Exception {
    logger.debug("Testing routing....");
    DispatcherTestServlet servlet = getServletInstance();
    @SuppressWarnings("unchecked")
    Class<TasksController> controllerClass = (Class<TasksController>) tasksController.getClass();
    Method expected = locateMethod(controllerClass, "getTasks", new Class[] { Tenant.class, String.class,
            String.class, Integer.class, ModelMap.class, HttpServletRequest.class });
    Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "getTask",
            new Class[] { String.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/1/"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "getApprovalTask",
            new Class[] { Locale.class, String.class, ModelMap.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/tasks/approval-task/1"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "actOnApprovalTask",
            new Class[] { String.class, String.class, String.class, HttpServletRequest.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/tasks/approval-task"));
    Assert.assertEquals(expected, handler);
}

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

@Test
public void testDefaultScopes() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "cf");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token");
    postBody.add("source", "credentials");
    postBody.add("username", testAccounts.getUserName());
    postBody.add("password", testAccounts.getPassword());

    ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST,
            new HttpEntity<>(postBody, headers), Void.class);

    Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode());

    UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation())
            .build();//ww w .  jav a2s  . co  m
    Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost());
    Assert.assertEquals("/redirect/cf", locationComponents.getPath());

    MultiValueMap<String, String> params = parseFragmentParams(locationComponents);

    Assert.assertThat(params.get("jti"), not(empty()));
    Assert.assertEquals("bearer", params.getFirst("token_type"));
    Assert.assertThat(Integer.parseInt(params.getFirst("expires_in")), Matchers.greaterThan(40000));

    String[] scopes = UriUtils.decode(params.getFirst("scope"), "UTF-8").split(" ");
    Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write",
            "cloud_controller.write", "openid", "cloud_controller.read"));

    Jwt access_token = JwtHelper.decode(params.getFirst("access_token"));

    Map<String, Object> claims = new ObjectMapper().readValue(access_token.getClaims(),
            new TypeReference<Map<String, Object>>() {
            });

    Assert.assertThat((String) claims.get("jti"), is(params.getFirst("jti")));
    Assert.assertThat((String) claims.get("client_id"), is("cf"));
    Assert.assertThat((String) claims.get("cid"), is("cf"));
    Assert.assertThat((String) claims.get("user_name"), is(testAccounts.getUserName()));

    Assert.assertThat(((List<String>) claims.get("scope")), containsInAnyOrder(scopes));

    Assert.assertThat(((List<String>) claims.get("aud")),
            containsInAnyOrder("cf", "scim", "openid", "cloud_controller", "password"));
}

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

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

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

    ngsiClient.unsubscribeContext(baseUrl, null, subscriptionID).get();
}

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

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

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

    ngsiClient.updateContextSubscription(baseUrl, null, createUpdateContextSubscriptionTemperature()).get();
}

From source file:com.cisco.cta.taxii.adapter.AdapterTaskIT.java

@Before
public void setUp() throws Exception {
    initLogbackOutput();//from  ww  w  .  j a va 2s. c om
    MockitoAnnotations.initMocks(this);
    pollServiceUri = new URI("https://taxii.cloudsec.sco.cisco.com/skym-taxii-ws/PollService/");
    when(httpRequestFactory.createRequest(pollServiceUri, HttpMethod.POST)).thenReturn(httpReq);
    httpReqHeaders = new HttpHeaders();
    when(httpReq.getHeaders()).thenReturn(httpReqHeaders);
    httpReqBody = new ByteArrayOutputStream();
    when(httpReq.getBody()).thenReturn(httpReqBody);
    when(httpReq.execute()).thenReturn(httpResp);
    taxiiPollRespBodyInitial = AdapterTaskIT.class.getResourceAsStream("/taxii-poll-response-body-initial.xml");
    taxiiPollRespBodyNext = AdapterTaskIT.class.getResourceAsStream("/taxii-poll-response-body-next.xml");
    taxiiStatusMsgBody = AdapterTaskIT.class.getResourceAsStream("/taxii-status-message-body.xml");
}

From source file:org.cloudfoundry.identity.uaa.login.integration.AutologinContollerIntegrationTests.java

@Test
public void testUnauthorizedWithoutPassword() {
    AutologinRequest request = new AutologinRequest();
    request.setUsername(testAccounts.getUserName());
    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> entity = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/autologin"),
            HttpMethod.POST, new HttpEntity<AutologinRequest>(request, headers), Map.class);
    assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
    @SuppressWarnings("unchecked")
    Map<String, Object> result = (Map<String, Object>) entity.getBody();
    assertNull(result.get("code"));
}

From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java

@Test
public void testDenied() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
    MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
    form.set("username", "user");
    form.set("password", "user");
    getCsrf(form, headers);/*from   w  w w  . ja v a 2 s  . co  m*/
    ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login",
            HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class);
    assertEquals(HttpStatus.FOUND, entity.getStatusCode());
    String cookie = entity.getHeaders().getFirst("Set-Cookie");
    headers.set("Cookie", cookie);
    ResponseEntity<String> page = new TestRestTemplate().exchange(entity.getHeaders().getLocation(),
            HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
    assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode());
    assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(),
            page.getBody().contains("Access denied"));
}