List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:com.create.controller.AuthenticationIT.java
@Test public void shouldReturnAnUserForAuthorizedGet() { final ResponseEntity<User> response = authenticatedUserTestRestTemplate.getForEntity(TEST_GET_PATH, User.class); assertThat(response.getStatusCode(), is(HttpStatus.OK)); assertThat(response.getBody().getUsername(), is(TICKET_SERVICE_USER)); }
From source file:comsat.sample.ui.SampleWebStaticApplicationTests.java
@Test public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/webjars/bootstrap/3.3.5/css/bootstrap.min.css", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), MediaType.valueOf("text/css;charset=UTF-8"), entity.getHeaders().getContentType()); }
From source file:de.codecentric.boot.admin.web.CorsFilterOnDifferentPortsTest.java
@Test public void testCORS_GET_application() { // DO NOT serve CORS-Headers on application-endpoints ResponseEntity<String> hello = new TestRestTemplate() .getForEntity("http://localhost:" + serverPort + "/hello", String.class); assertEquals(HttpStatus.OK, hello.getStatusCode()); assertEquals(null, hello.getHeaders().get("Access-Control-Allow-Origin")); assertEquals(null, hello.getHeaders().get("Access-Control-Allow-Headers")); }
From source file:fi.helsinki.opintoni.service.usefullink.UsefulLinkService.java
public SearchPageTitleDto searchPageTitle(SearchPageTitleDto searchPageTitleDto) throws NotFoundException { try {//from ww w . j ava2 s .c o m HttpHeaders headers = new HttpHeaders(); headers.setAccept(Lists.newArrayList(MediaType.TEXT_HTML)); headers.add("User-Agent", "Mozilla"); HttpEntity<String> entity = new HttpEntity<>("parameters", headers); ResponseEntity<String> responseEntity = linkUrlLoaderRestTemplate.exchange(searchPageTitleDto.searchUrl, HttpMethod.GET, entity, String.class); if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { Document document = Jsoup.parse(responseEntity.getBody()); searchPageTitleDto.searchResult = document.title(); } } catch (Exception e) { } return searchPageTitleDto; }
From source file:org.kuali.mobility.sakai.controllers.ForumsController.java
@RequestMapping(value = "/reply", method = RequestMethod.POST) public String reply(HttpServletRequest request, @PathVariable("siteId") String siteId, @ModelAttribute("message") Message message, BindingResult result, Model uiModel) { User user = (User) request.getSession().getAttribute(Constants.KME_USER_KEY); ResponseEntity<String> response = sakaiForumService.postMessage(message, user.getUserId()); if (response.getStatusCode().value() < 200 || response.getStatusCode().value() >= 300) { Errors errors = ((Errors) result); errors.rejectValue("body", "", "There was an error posting your reply. Please try again later."); uiModel.addAttribute("siteId", siteId); return "sakai/forums/forumsmessagereply"; }// w w w.ja v a2 s . c om return getForumTopicThread(request, siteId, message.getTopicId(), message.getTopicTitle(), message.getForumId(), message.getThreadId(), uiModel); }
From source file:org.trustedanalytics.servicebroker.h2oprovisioner.rest.api.H2oProvisionerRestClientTest.java
@Test public void createH2oInstance_restReturnedResponse_responsePassed() { // arrange/*from ww w . j a v a 2 s. c o m*/ when(restOperations.postForEntity(EFFECTIVE_URL_KRB_OFF, params, H2oCredentials.class)) .thenReturn(new ResponseEntity<>(H2O_CREDENTIALS, HttpStatus.OK)); // act ResponseEntity<H2oCredentials> h2oInstanceEntity = h2oRest.createH2oInstance("serviceInstanceId", "2", "512m", false, params); // assert assertThat(h2oInstanceEntity.getStatusCode(), equalTo(HttpStatus.OK)); assertThat(h2oInstanceEntity.getBody(), equalTo(H2O_CREDENTIALS)); verify(restOperations, times(1)).postForEntity(EFFECTIVE_URL_KRB_OFF, params, H2oCredentials.class); }
From source file:com.work.petclinic.SampleWebUiApplicationTests.java
@Test public void testHome() throws Exception { ResponseEntity<String> page = sendRequest("http://localhost:" + this.port, HttpMethod.GET); assertEquals(HttpStatus.OK, page.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + page.getBody(), page.getBody().contains(getMessageBundleText("app.title"))); assertTrue("Wrong body (did not find heading):\n" + page.getBody(), page.getBody().contains(getMessageBundleText("welcome"))); }
From source file:com.hpe.elderberry.Taxii10Template.java
private <T> T respond(ResponseEntity<T> response) { if (response.getStatusCode() == OK) { return response.getBody(); }/*from ww w.j a va 2 s . c om*/ log.error("error in TAXII request: " + response.getStatusCode()); return null; }
From source file:com.crazyacking.learn.spring.actuator.ManagementAddressActuatorApplicationTests.java
@Test public void testHealth() { ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getBody()).contains("\"status\":\"UP\""); }
From source file:com.ge.predix.acs.commons.web.ResponseEntityBuilderTest.java
@Test public void testUpdatedWithLocation() { ResponseEntity<Object> created = ResponseEntityBuilder.created("/report/1", Boolean.TRUE); Assert.assertNotNull(created);/*from www . j av a 2 s. co m*/ Assert.assertNull(created.getBody()); Assert.assertEquals(created.getStatusCode(), HttpStatus.NO_CONTENT); Assert.assertNotNull(created.getHeaders()); URI location = created.getHeaders().getLocation(); Assert.assertEquals(location.getPath(), "/report/1"); }