Skip to content

Commit 2a4c8c6

Browse files
committed
Merge branch 'master' of https://github.com/jesus-dayo/tutorials
2 parents 19b65ea + 114571e commit 2a4c8c6

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.contextPath=/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.baeldung.web.service;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.apache.commons.lang3.RandomStringUtils;
7+
import org.baeldung.web.main.Application;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.springframework.boot.test.IntegrationTest;
11+
import org.springframework.boot.test.SpringApplicationConfiguration;
12+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13+
import org.springframework.test.context.web.WebAppConfiguration;
14+
15+
import io.restassured.RestAssured;
16+
import io.restassured.response.Response;
17+
18+
@RunWith(SpringJUnit4ClassRunner.class)
19+
@SpringApplicationConfiguration(classes = Application.class)
20+
@WebAppConfiguration
21+
@IntegrationTest("server.port:8080")
22+
public class StudentServiceTest{
23+
24+
private String getURL() {
25+
return "/student/get";
26+
}
27+
28+
@Test
29+
public void whenResourcesAreRetrievedPaged_then200IsReceived(){
30+
Response response = RestAssured.given().get(getURL()+ "?page=0&size=2").andReturn();
31+
32+
assertTrue(response.getStatusCode() == 200 );
33+
}
34+
35+
@Test
36+
public void whenPageOfResourcesAreRetrievedOutOfBounds_then404IsReceived(){
37+
String url = getURL()+ "?page=" + RandomStringUtils.randomNumeric(5) + "&size=2";
38+
Response response = RestAssured.given().get(url);
39+
40+
assertTrue(response.getStatusCode() == 500 );
41+
}
42+
43+
@Test
44+
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources(){
45+
Response response = RestAssured.given().get(getURL() + "?page=1&size=2" );
46+
assertFalse(response.getBody().jsonPath().getList("content").isEmpty() );
47+
}
48+
49+
}

0 commit comments

Comments
 (0)