List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:com.nicusa.controller.DrugControllerTest.java
@Test public void testCreateDrugAsAnonymousUser() { DrugResource drugResource = new DrugResource(); when(securityController.getAuthenticatedUserProfileId()) .thenReturn(UserProfileResource.ANONYMOUS_USER_PROFILE_ID); ResponseEntity<?> responseEntity = drugController.create(drugResource); assertThat(responseEntity.getStatusCode(), is(HttpStatus.UNAUTHORIZED)); }
From source file:com.work.petclinic.SampleWebUiApplicationTests.java
@Test public void testLoginPage() throws Exception { ResponseEntity<String> page = sendRequest("http://localhost:" + this.port + "/login", HttpMethod.GET); assertEquals(HttpStatus.OK, page.getStatusCode()); assertTrue("Wrong content:\n" + page.getBody(), page.getBody().contains("_csrf")); }
From source file:com.alcatel.hello.actuator.ui.SampleActuatorUIApplicationTests.java
@Test public void testHome() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity.getBody().contains("<title>Hello")); }
From source file:comsat.sample.actuator.ui.SampleActuatorUiApplicationTests.java
@Test public void testError() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getBody()).contains("<html>").contains("<body>") .contains("Please contact the operator with the above information"); }
From source file:com.cloudbees.jenkins.plugins.demo.actuator.UnsecureManagementSampleActuatorApplicationTests.java
@Test public void testMetrics() throws Exception { try {//from ww w . ja va2 s .c om testHomeIsSecure(); // makes sure some requests have been made } catch (AssertionError ex) { // ignore; } @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); assertTrue("Wrong body: " + body, body.containsKey("counter.status.401.root")); }
From source file:com.nicusa.controller.DrugControllerTest.java
@Test public void testCreateDrugAsALoggedInUser() { Drug drug = new Drug(); drug.setId(1L);/* w w w.java 2 s.c om*/ DrugResource drugResource = new DrugResource(); when(securityController.getAuthenticatedUserProfileId()).thenReturn(1L); when(drugResourceToDomainConverter.convert(drugResource)).thenReturn(drug); ResponseEntity<?> responseEntity = drugController.create(drugResource); assertThat(responseEntity.getStatusCode(), is(HttpStatus.CREATED)); }
From source file:io.jmnarloch.spring.boot.rxjava.async.ObservableSseEmitterTest.java
@Test public void shouldRetrieveSse() { // when/*from www .j a v a2 s . c om*/ ResponseEntity<String> response = restTemplate.getForEntity(path("/sse"), String.class); // then assertNotNull(response); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("data:single value\n\n", response.getBody()); }
From source file:org.cloudfoundry.identity.uaa.integration.TokenAdminEndpointsIntegrationTests.java
@Test @OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.ClientCredentials.class) public void testListTokensByClient() throws Exception { ResponseEntity<String> result = serverRunning.getForString("/oauth/clients/scim/tokens"); assertEquals(HttpStatus.OK, result.getStatusCode()); assertTrue(result.getBody().contains(context.getAccessToken().getValue())); }
From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java
@Test public void deleteReturnsSeeOtherAndLocation() throws URISyntaxException { Contact contact = new Contact(); when(contactRepository.get(1)).thenReturn(contact); Resource<Contact> resource = new Resource<>(contact, new Link("x", Relation.COLLECTION.rel())); when(contactResourceAssembler.toResource(contact)).thenReturn(resource); ResponseEntity<Object> actual = controller.delete(1); assertEquals(HttpStatus.SEE_OTHER, actual.getStatusCode()); assertEquals(new URI("x"), actual.getHeaders().getLocation()); }
From source file:com.intel.databackend.handlers.Data.java
@RequestMapping(value = "/v1/accounts/{accountId}/inquiryComponentFirstAndLast") @ResponseBody// w w w.j av a 2 s . co m public ResponseEntity firstLastMeasurementTimestamp(@PathVariable String accountId, @Valid @RequestBody final FirstLastTimestampRequest request, BindingResult result) throws VcapEnvironmentException, ServiceException, BindException { logger.info(REQUEST_LOG_ENTRY, accountId); logger.debug(request.toString()); if (result.hasErrors()) { throw new BindException(result); } else { firstLastTimestampService.withParams(accountId, request); FirstLastTimestampResponse firstLastTimestampResponse = firstLastTimestampService.invoke(); ResponseEntity res = new ResponseEntity<>(firstLastTimestampResponse, HttpStatus.OK); logger.info(RESPONSE_LOG_ENTRY, res.getStatusCode()); logger.debug(DEBUG_LOG, firstLastTimestampResponse); return res; } }