List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:de.codecentric.boot.admin.web.CorsFilterOnDifferentPortsTest.java
@Test public void testCORS_OPTIONS_jolokia_endpoint() { // DO serve CORS-Headers on management-endpoints ResponseEntity<Void> options = new TestRestTemplate().exchange( "http://localhost:" + managementPort + "/jolokia", HttpMethod.OPTIONS, HttpEntity.EMPTY, Void.class); assertEquals(HttpStatus.OK, options.getStatusCode()); assertEquals(Arrays.asList("*"), options.getHeaders().get("Access-Control-Allow-Origin")); assertEquals(Arrays.asList("Origin, X-Requested-With, Content-Type, Accept"), options.getHeaders().get("Access-Control-Allow-Headers")); }
From source file:org.cloudfoundry.identity.uaa.integration.TokenAdminEndpointsIntegrationTests.java
@Test @OAuth2ContextConfiguration(resource = TokenResourceOwnerPassword.class) public void testListTokensByUser() throws Exception { ResponseEntity<String> result = serverRunning .getForString("/oauth/users/" + testAccounts.getUserName() + "/tokens"); assertEquals(HttpStatus.OK, result.getStatusCode()); assertTrue(result.getBody().contains(context.getAccessToken().getValue())); }
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:it.tidalwave.northernwind.frontend.springmvc.SpringMvcResponseHolderTest.java
/******************************************************************************************************************* * * Note that here we are not testing the correctness of the actual output sent to the network: in fact, it's a * responsibility of Spring MVC. We are only testing the proper contents of ResponseEntity. * ******************************************************************************************************************/ @Override/*from ww w .ja v a2 s. c o m*/ protected void assertContents(final @Nonnull ResponseBuilder<?> builder, final String fileName) throws Exception { final TestHelper.TestResource tr = helper.testResourceFor(fileName); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ResponseEntity<byte[]> responseEntity = (ResponseEntity<byte[]>) builder.build(); final HttpHeaders headers = responseEntity.getHeaders(); final PrintWriter pw = new PrintWriter(baos); // FIXME: charset? pw.printf("HTTP/1.1 %d%n", responseEntity.getStatusCode().value()); headers.entrySet().stream().sorted(comparing(Entry::getKey)) .forEach(e -> pw.printf("%s: %s%n", e.getKey(), e.getValue().get(0))); pw.println(); pw.flush(); baos.write(responseEntity.getBody()); tr.writeToActualFile(baos.toByteArray()); tr.assertActualFileContentSameAsExpected(); }
From source file:net.eusashead.hateoas.response.impl.HeadResponseBuilderImplTest.java
@Test public void testAllHeaders() throws Exception { Entity entity = new Entity("foo"); Date now = new Date(1373571924000l); ResponseEntity<Entity> response = builder.entity(entity).etag().lastModified(now).expireIn(1000l).build(); Assert.assertNotNull(response);/*from w ww . j ava 2 s . c om*/ Assert.assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); Assert.assertNull(response.getBody()); Assert.assertNotNull(response.getHeaders().getETag()); Assert.assertEquals("W/\"b0c689597eb9dd62c0a1fb90a7c5c5a5\"", response.getHeaders().getETag()); Assert.assertEquals(now.getTime(), response.getHeaders().getLastModified()); Assert.assertNotNull(response.getHeaders().getCacheControl()); Assert.assertEquals("public, must-revalidate, proxy-revalidate, max-age=1", response.getHeaders().getCacheControl()); Assert.assertNotEquals(-1l, response.getHeaders().getDate()); Assert.assertEquals(response.getHeaders().getDate() + 1000l, response.getHeaders().getExpires()); }
From source file:org.obiba.mica.core.service.MailService.java
private synchronized void sendEmail(String subject, String text, String recipient) { try {//from ww w.ja va 2 s . c om RestTemplate template = newRestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(APPLICATION_AUTH_HEADER, getApplicationAuth()); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); String form = (Strings.isNullOrEmpty(recipient) ? "" : recipient + "&") + "subject=" + encode(subject, "UTF-8") + "&body=" + encode(text, "UTF-8"); HttpEntity<String> entity = new HttpEntity<>(form, headers); ResponseEntity<String> response = template.exchange(getNotificationsUrl(), HttpMethod.POST, entity, String.class); if (response.getStatusCode().is2xxSuccessful()) { log.info("Email sent via Agate"); } else { log.error("Sending email via Agate failed with status: {}", response.getStatusCode()); } } catch (Exception e) { log.error("Agate connection failure: {}", e.getMessage()); } }
From source file:com.create.controller.AuthenticationIT.java
@Test public void shouldReturnABadRequestForAuthorizedPostWithInvalidContent() { final ResponseEntity<User> response = authenticatedUserTestRestTemplate.postForEntity( localHostUriTemplateHandler.expand(TEST_POST_VALIDATOR_PATH), new User(), User.class); assertThat(response.getStatusCode(), is(HttpStatus.BAD_REQUEST)); }
From source file:com.ge.predix.test.utils.ZoneHelper.java
public Zone createTestZone(final RestTemplate restTemplate, final String zoneId, final boolean registerWithZac, final Map<String, Object> trustedIssuers) throws JsonParseException, JsonMappingException, IOException { Zone zone = new Zone(zoneId, zoneId, "Zone for integration testing."); if (registerWithZac) { ResponseEntity<String> response = registerServicetoZac(zoneId, trustedIssuers); if (!response.getStatusCode().is2xxSuccessful()) { throw new RuntimeException(String.format("Failed to register '%s' zone with ZAC.", zoneId)); }//from w w w .j ava 2 s.co m } restTemplate.put(this.acsBaseUrl + ACS_ZONE_API_PATH + zoneId, zone); return zone; }
From source file:io.syndesis.runtime.APITokenRule.java
@Override protected void after() { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.set("refresh_token", refreshToken); map.set("client_id", "admin-cli"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Bearer " + accessToken); ResponseEntity<JsonNode> json = restTemplate.postForEntity("http://localhost:" + keycloakPort + "/auth/realms/" + keycloakRealm + "/protocol/" + keycloakProtocol + "/logout", map, JsonNode.class); assertThat(json.getStatusCode()).as("logout status code").isEqualTo(HttpStatus.NO_CONTENT); }
From source file:org.cloudfoundry.identity.uaa.integration.TokenAdminEndpointsIntegrationTests.java
@Test @OAuth2ContextConfiguration(resource = TokenResourceOwnerPassword.class) public void testClientListsTokensByUser() throws Exception { ResponseEntity<String> result = serverRunning .getForString("/oauth/users/" + testAccounts.getUserName() + "/tokens"); assertEquals(HttpStatus.OK, result.getStatusCode()); assertTrue(result.getBody().startsWith("[")); assertTrue(result.getBody().endsWith("]")); assertTrue(result.getBody().length() > 0); }