List of usage examples for org.springframework.http ResponseEntity getStatusCode
public HttpStatus getStatusCode()
From source file:de.wirthedv.appname.SpringBootFacesApplicationTests.java
@Test public void testJsfWelcomePageAccessibleByAdmin() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add(WebSecurityConfiguration.PREAUTH_USER_HEADER, "admin"); 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:\n" + entity.getBody(), entity.getBody().contains("<h1>Home page</h1>")); }
From source file:io.jmnarloch.spring.boot.rxjava.async.ObservableSseEmitterTest.java
@Test public void shouldRetrieveJsonOverSseWithMultipleMessages() { // when//from ww w. j a v a 2 s .co m ResponseEntity<String> response = restTemplate.getForEntity(path("/events"), String.class); // then assertNotNull(response); assertEquals(HttpStatus.OK, response.getStatusCode()); }
From source file:net.eusashead.hateoas.response.impl.HeadResponseBuilderImplTest.java
@Test public void testEntityBuild() throws Exception { Entity entity = new Entity("foo"); ResponseEntity<Entity> response = builder.entity(entity).build(); Assert.assertNotNull(response);/*from w w w . j ava2 s. co m*/ Assert.assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); Assert.assertNull(response.getBody()); Assert.assertNull(response.getHeaders().getETag()); Assert.assertEquals(-1l, response.getHeaders().getLastModified()); Assert.assertNull(response.getHeaders().getCacheControl()); Assert.assertEquals(-1l, response.getHeaders().getExpires()); Assert.assertEquals(-1l, response.getHeaders().getDate()); }
From source file:org.moserp.environment.rest.UnitOfMeasurementRestIT.java
@Test public void testFindByCodeSpecialChars() { commonUtil.createAndSaveSpecialCharUnit(); ResponseEntity<UnitOfMeasurement> entity = restTemplate.getForEntity( testEnvironment.createRestUri("unitOfMeasurements/search/findByCode?code={unit.code}"), UnitOfMeasurement.class, "%"); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertNotNull(entity.getBody());/* w ww . ja va 2 s . c o m*/ }
From source file:org.zaizi.AuthServerApplicationTests.java
@Test public void homePageProtected() { ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + contextPath + "/", String.class); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String auth = response.getHeaders().getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + auth, auth.startsWith("Bearer realm=\"")); }
From source file:org.zaizi.AuthServerApplicationTests.java
@Test public void userEndpointProtected() { ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + contextPath + "/", String.class); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); String auth = response.getHeaders().getFirst("WWW-Authenticate"); assertTrue("Wrong header: " + auth, auth.startsWith("Bearer realm=\"")); }
From source file:io.kahu.hawaii.rest.DefaultResponseManagerTest.java
@Test public void testToResponseObjectList() throws Exception { List<JSONSerializable> objects = new ArrayList<JSONSerializable>(); objects.add(new ObjectExample("piet", "puk")); objects.add(new ObjectExample("jan", "klaassen")); ResponseEntity<?> response = responseManager.toResponse(objects); assertThat(response.getStatusCode(), is(equalTo(HttpStatus.OK))); JSONObject json = new JSONObject(response.getBody().toString()); JSONArray content = json.getJSONArray("data"); assertThat(content.length(), is(equalTo(2))); assertThat(content.getJSONObject(0).getString("firstname"), is(equalTo("piet"))); assertThat(content.getJSONObject(1).getString("firstname"), is(equalTo("jan"))); }
From source file:comsat.sample.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:io.jmnarloch.spring.boot.rxjava.async.ObservableSseEmitterTest.java
@Test public void shouldRetrieveSseWithMultipleMessages() { // when/*from w ww . j a v a2 s . com*/ ResponseEntity<String> response = restTemplate.getForEntity(path("/messages"), String.class); // then assertNotNull(response); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals("data:message 1\n\ndata:message 2\n\ndata:message 3\n\n", response.getBody()); }
From source file:org.hobsoft.contacts.server.controller.ContactsControllerTest.java
@Test public void createReturnsSeeOtherAndLocation() throws URISyntaxException { Contact contact = new Contact(); Resource<Contact> resource = new Resource<>(contact, new Link("x")); when(contactResourceAssembler.toResource(contact)).thenReturn(resource); ResponseEntity<Object> actual = controller.create(contact); assertEquals(HttpStatus.SEE_OTHER, actual.getStatusCode()); assertEquals(new URI("x"), actual.getHeaders().getLocation()); }