minor cleanup
This commit is contained in:
parent
966e53a85b
commit
68281fa705
|
@ -104,13 +104,7 @@ public class Book {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append("Book [id=")
|
builder.append("Book [id=").append(id).append(", title=").append(title).append(", author=").append(author).append("]");
|
||||||
.append(id)
|
|
||||||
.append(", title=")
|
|
||||||
.append(title)
|
|
||||||
.append(", author=")
|
|
||||||
.append(author)
|
|
||||||
.append("]");
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,7 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
final Response response = RestAssured.get(location);
|
final Response response = RestAssured.get(location);
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertEquals(book.getTitle(), response.jsonPath()
|
assertEquals(book.getTitle(), response.jsonPath().get("title"));
|
||||||
.get("title"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,8 +54,7 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + book.getTitle());
|
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + book.getTitle());
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertTrue(response.jsonPath()
|
assertTrue(response.jsonPath().getLong("page.totalElements") > 0);
|
||||||
.getLong("page.totalElements") > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,8 +67,7 @@ public class RestApiLiveTest {
|
||||||
public void whenGetNotExistBookByName_thenNotFound() {
|
public void whenGetNotExistBookByName_thenNotFound() {
|
||||||
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + randomAlphabetic(20));
|
final Response response = RestAssured.get(API_URI + "/search/findByTitle?title=" + randomAlphabetic(20));
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertTrue(response.jsonPath()
|
assertTrue(response.jsonPath().getLong("page.totalElements") == 0);
|
||||||
.getLong("page.totalElements") == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
|
@ -78,10 +75,7 @@ public class RestApiLiveTest {
|
||||||
public void whenCreateNewBook_thenCreated() {
|
public void whenCreateNewBook_thenCreated() {
|
||||||
final Book book = createRandomBook();
|
final Book book = createRandomBook();
|
||||||
|
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(book)
|
|
||||||
.post(API_URI);
|
|
||||||
assertEquals(HttpStatus.CREATED.value(), response.getStatusCode());
|
assertEquals(HttpStatus.CREATED.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,10 +85,7 @@ public class RestApiLiveTest {
|
||||||
createBookAsUri(book);
|
createBookAsUri(book);
|
||||||
|
|
||||||
// duplicate
|
// duplicate
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(book)
|
|
||||||
.post(API_URI);
|
|
||||||
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +94,7 @@ public class RestApiLiveTest {
|
||||||
final Book book = createRandomBook();
|
final Book book = createRandomBook();
|
||||||
book.setAuthor(null);
|
book.setAuthor(null);
|
||||||
|
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(book)
|
|
||||||
.post(API_URI);
|
|
||||||
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,17 +106,13 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
// update
|
// update
|
||||||
book.setAuthor("newAuthor");
|
book.setAuthor("newAuthor");
|
||||||
Response response = RestAssured.given()
|
Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).put(location);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(book)
|
|
||||||
.put(location);
|
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
|
|
||||||
// check if changes saved
|
// check if changes saved
|
||||||
response = RestAssured.get(location);
|
response = RestAssured.get(location);
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertEquals("newAuthor", response.jsonPath()
|
assertEquals("newAuthor", response.jsonPath().get("author"));
|
||||||
.get("author"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +147,8 @@ public class RestApiLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createBookAsUri(Book book) {
|
private String createBookAsUri(Book book) {
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(book).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
return response.jsonPath().get("_links.self.href");
|
||||||
.body(book)
|
|
||||||
.post(API_URI);
|
|
||||||
return response.jsonPath()
|
|
||||||
.get("_links.self.href");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,11 +45,7 @@ public class SessionLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenAuthorizedUser_whenDeleteSession_thenUnauthorized() {
|
public void givenAuthorizedUser_whenDeleteSession_thenUnauthorized() {
|
||||||
// authorize User
|
// authorize User
|
||||||
Response response = RestAssured.given()
|
Response response = RestAssured.given().auth().preemptive().basic("user", "userPass").get(API_URI);
|
||||||
.auth()
|
|
||||||
.preemptive()
|
|
||||||
.basic("user", "userPass")
|
|
||||||
.get(API_URI);
|
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
final String sessionCookie = response.getCookie("SESSION");
|
final String sessionCookie = response.getCookie("SESSION");
|
||||||
|
|
||||||
|
@ -58,18 +54,14 @@ public class SessionLiveTest {
|
||||||
assertTrue(redisResult.size() > 0);
|
assertTrue(redisResult.size() > 0);
|
||||||
|
|
||||||
// login with cookie
|
// login with cookie
|
||||||
response = RestAssured.given()
|
response = RestAssured.given().cookie("SESSION", sessionCookie).get(API_URI);
|
||||||
.cookie("SESSION", sessionCookie)
|
|
||||||
.get(API_URI);
|
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
|
|
||||||
// empty redis
|
// empty redis
|
||||||
jedis.flushAll();
|
jedis.flushAll();
|
||||||
|
|
||||||
// login with cookie again
|
// login with cookie again
|
||||||
response = RestAssured.given()
|
response = RestAssured.given().cookie("SESSION", sessionCookie).get(API_URI);
|
||||||
.cookie("SESSION", sessionCookie)
|
|
||||||
.get(API_URI);
|
|
||||||
assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatusCode());
|
assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,15 +113,7 @@ public class BookReview {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append("BookReview [id=")
|
builder.append("BookReview [id=").append(id).append(", content=").append(content).append(", rating=").append(rating).append(", bookId=").append(bookId).append("]");
|
||||||
.append(id)
|
|
||||||
.append(", content=")
|
|
||||||
.append(content)
|
|
||||||
.append(", rating=")
|
|
||||||
.append(rating)
|
|
||||||
.append(", bookId=")
|
|
||||||
.append(bookId)
|
|
||||||
.append("]");
|
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,7 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
final Response response = RestAssured.get(location);
|
final Response response = RestAssured.get(location);
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertEquals(review.getContent(), response.jsonPath()
|
assertEquals(review.getContent(), response.jsonPath().get("content"));
|
||||||
.get("content"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,8 +54,7 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
final Response response = RestAssured.get(API_URI + "/search/findByBookId?bookId=" + review.getBookId());
|
final Response response = RestAssured.get(API_URI + "/search/findByBookId?bookId=" + review.getBookId());
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertTrue(response.jsonPath()
|
assertTrue(response.jsonPath().getLong("page.totalElements") > 0);
|
||||||
.getLong("page.totalElements") > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -69,8 +67,7 @@ public class RestApiLiveTest {
|
||||||
public void whenGetNotExistReviewByBookId_thenNotFound() {
|
public void whenGetNotExistReviewByBookId_thenNotFound() {
|
||||||
final Response response = RestAssured.get(API_URI + "/search/findByBookId?bookId=" + randomNumeric(4));
|
final Response response = RestAssured.get(API_URI + "/search/findByBookId?bookId=" + randomNumeric(4));
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertTrue(response.jsonPath()
|
assertTrue(response.jsonPath().getLong("page.totalElements") == 0);
|
||||||
.getLong("page.totalElements") == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
|
@ -78,10 +75,7 @@ public class RestApiLiveTest {
|
||||||
public void whenCreateNewReview_thenCreated() {
|
public void whenCreateNewReview_thenCreated() {
|
||||||
final BookReview review = createRandomReview();
|
final BookReview review = createRandomReview();
|
||||||
|
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(review).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(review)
|
|
||||||
.post(API_URI);
|
|
||||||
assertEquals(HttpStatus.CREATED.value(), response.getStatusCode());
|
assertEquals(HttpStatus.CREATED.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,10 +84,7 @@ public class RestApiLiveTest {
|
||||||
final BookReview review = createRandomReview();
|
final BookReview review = createRandomReview();
|
||||||
review.setBookId(null);
|
review.setBookId(null);
|
||||||
|
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(review).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(review)
|
|
||||||
.post(API_URI);
|
|
||||||
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
assertEquals(HttpStatus.CONFLICT.value(), response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,17 +96,13 @@ public class RestApiLiveTest {
|
||||||
|
|
||||||
// update
|
// update
|
||||||
review.setRating(4);
|
review.setRating(4);
|
||||||
Response response = RestAssured.given()
|
Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(review).put(location);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
.body(review)
|
|
||||||
.put(location);
|
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
|
|
||||||
// check if changes saved
|
// check if changes saved
|
||||||
response = RestAssured.get(location);
|
response = RestAssured.get(location);
|
||||||
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
assertEquals(HttpStatus.OK.value(), response.getStatusCode());
|
||||||
assertEquals(4, response.jsonPath()
|
assertEquals(4, response.jsonPath().getInt("rating"));
|
||||||
.getInt("rating"));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,12 +138,8 @@ public class RestApiLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createReviewAsUri(BookReview review) {
|
private String createReviewAsUri(BookReview review) {
|
||||||
final Response response = RestAssured.given()
|
final Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(review).post(API_URI);
|
||||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
return response.jsonPath().get("_links.self.href");
|
||||||
.body(review)
|
|
||||||
.post(API_URI);
|
|
||||||
return response.jsonPath()
|
|
||||||
.get("_links.self.href");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue