This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed training module 02-testing
- Loading branch information
1 parent
b125cc2
commit d0af7d7
Showing
2 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/test/java/org/folio/sample/integration/api/books/GetLeapYearBookTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.folio.sample.integration.api.books; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import io.restassured.common.mapper.TypeRef; | ||
import io.restassured.response.Response; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import org.folio.sample.domain.dto.BookDTO; | ||
import org.folio.sample.domain.dto.BookForCreationDTO; | ||
import org.folio.sample.integration.AbstractBaseApiTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class GetLeapYearBookTest extends AbstractBaseApiTest { | ||
@Test | ||
void testEmptyGet(){ | ||
Response response = ra() | ||
.queryParam("onlyLeapYears", true) | ||
.get(getRequestUrl("books")); | ||
response.then().statusCode(is(HttpStatus.OK.value())); | ||
|
||
List<BookDTO> bookList = response | ||
.getBody() | ||
.as(new TypeRef<List<BookDTO>>() {}); | ||
assertThat(bookList, hasSize(0)); | ||
} | ||
|
||
@Test | ||
void testGetWithBook() { | ||
ra() | ||
.body( | ||
BookForCreationDTO | ||
.builder() | ||
.name("test book") | ||
.publishedDate(LocalDate.of(2020, 1, 1)) | ||
.build() | ||
) | ||
.post(getRequestUrl("books")) | ||
.then() | ||
.statusCode(is(HttpStatus.CREATED.value())); | ||
|
||
Response response = ra() | ||
.queryParam("onlyLeap", true) | ||
.get(getRequestUrl("books")); | ||
response.then().statusCode(is(HttpStatus.OK.value())); | ||
|
||
List<BookDTO> bookList = response | ||
.body() | ||
.as(new TypeRef<List<BookDTO>>() {}); | ||
|
||
assertThat(bookList, hasSize(1)); | ||
assertThat(bookList.get(0).getName(), is(equalTo("test book"))); | ||
assertThat(bookList.get(0).getPublishedDate(), is(equalTo(LocalDate.of(2020, 1, 1)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters