List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:com.crazyacking.learn.spring.actuator.EndpointsPropertiesSampleActuatorApplicationTests.java
@Test public void testCustomErrorPath() { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", Map.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); assertThat(body.get("error")).isEqualTo("None"); assertThat(body.get("status")).isEqualTo(999); }
From source file:de.zib.gndms.gndmc.gorfx.Test.GORFXClientTest.java
@Test(groups = { "GORFXServiceTest" }) public void listTaskFlows() { ResponseEntity<List<String>> responseEntity = gorfxClient.listTaskFlows(admindn); Assert.assertNotNull(responseEntity); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); }
From source file:sample.resteasy.SampleResteasyApplicationTests.java
@Test public void asynchronousRequest() { TestRestTemplate rest = new TestRestTemplate(); ResponseEntity<String> response = rest.getForEntity("http://localhost:" + port + "/hello?asynch=true", String.class); assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); URI jobLocation = response.getHeaders().getLocation(); HttpStatus jobStatus = HttpStatus.ACCEPTED; ResponseEntity<String> jobResponse = null; while (jobStatus == HttpStatus.ACCEPTED) { jobResponse = rest.getForEntity(jobLocation, String.class); jobStatus = jobResponse.getStatusCode(); }//from w w w .j av a 2 s .co m assertEquals(HttpStatus.OK, jobResponse.getStatusCode()); assertEquals("Hello World", jobResponse.getBody()); rest.delete(jobLocation); }
From source file:sample.undertow.SampleUndertowApplicationTests.java
@Test public void testCompression() throws Exception { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Accept-Encoding", "gzip"); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); RestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<byte[]> entity = restTemplate.exchange("http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(entity.getBody())); try {/*from www . j a v a 2 s .c om*/ assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))).isEqualTo("Hello World"); } finally { inflater.close(); } }
From source file:com.opensearchserver.hadse.index.IndexTest.java
@Test public void t03_exists() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); RestTemplate template = new RestTemplate(); ResponseEntity<String> entity = template.exchange("http://localhost:8080/my_index", HttpMethod.GET, null, String.class); assertEquals(HttpStatus.FOUND, entity.getStatusCode()); }
From source file:comsat.sample.ui.SampleGroovyTemplateApplicationTests.java
@Test public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity.getBody().contains("<title>Messages")); assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(), entity.getBody().contains("layout:fragment")); }
From source file:de.codecentric.boot.admin.controller.RegistryControllerTest.java
@Test public void register_sameUrl() { controller.register(new Application("http://localhost", "FOO")); ResponseEntity<?> response = controller.register(new Application("http://localhost", "BAR")); assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java
/** * tests a happy-day flow of the Resource Owner Password Credentials grant type. (formerly native application * profile).// w w w.ja v a 2s.c om */ @Test public void testHappyDay() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("grant_type", "password"); formData.add("username", resource.getUsername()); formData.add("password", resource.getPassword()); formData.add("scope", "cloud_controller.read"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", testAccounts.getAuthorizationHeader(resource.getClientId(), resource.getClientSecret())); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); ResponseEntity<String> response = serverRunning.postForString("/oauth/token", formData, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("no-store", response.getHeaders().getFirst("Cache-Control")); }
From source file:org.cloudfoundry.identity.uaa.login.integration.VmcAuthenticationTests.java
@Test public void testInvalidScopes() { params.set("source", "credentials"); params.set("username", testAccounts.getUserName()); params.set("password", testAccounts.getPassword()); params.set("scope", "read"); ResponseEntity<Void> response = serverRunning.postForResponse(serverRunning.getAuthorizationUri(), headers, params);/*from www . jav a 2 s . c om*/ assertEquals(HttpStatus.FOUND, response.getStatusCode()); String location = response.getHeaders().getLocation().toString(); // System.err.println(location); assertTrue(location.startsWith(params.getFirst("redirect_uri"))); assertTrue(location.contains("error=invalid_scope")); assertFalse(location.contains("credentials=")); }
From source file:be.boyenvaesen.Humidity.HumidityControllerTest.java
@Test public void testList() { ResponseEntity<Humidity[]> responseEntity = restTemplate.getForEntity("/humidity", Humidity[].class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); Humidity[] humidities = responseEntity.getBody(); assertEquals("first percentage : ", 75.1f, humidities[0].getPercentage(), MAX_ASSERT_FLOAT_OFFSET); assertEquals("second percentage : ", 80f, humidities[1].getPercentage(), MAX_ASSERT_FLOAT_OFFSET); assertEquals(2, humidities.length);// w w w .ja va 2 s.com }