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.
Merge pull request #7 from ualibweb/chris-hellen-03-databases
Completed training module 03-databases
- Loading branch information
Showing
10 changed files
with
150 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package org.folio.sample.repository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import org.folio.sample.domain.entity.Book; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* A {@link org.springframework.data.jpa.repository.JpaRepository} of {@link org.folio.sample.domain.entity.Book} objects | ||
*/ | ||
@Repository | ||
public interface BookRepository extends JpaRepository<Book, UUID> {} | ||
public interface BookRepository extends JpaRepository<Book, UUID> { | ||
@Query("SELECT b FROM Book b WHERE b.available = true") | ||
List<Book> findAllAvailable(); | ||
} |
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
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
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
15 changes: 15 additions & 0 deletions
15
src/main/resources/db/changes/0010-add-available-column.yaml
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,15 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: 0010-add-available-column | ||
author: chellen | ||
comment: add available column to books table | ||
changes: | ||
- addColumn: | ||
tableName: books | ||
columns: | ||
- column: | ||
name: available | ||
type: boolean | ||
constraints: | ||
nullable: true | ||
defaultValueBoolean: true |
71 changes: 71 additions & 0 deletions
71
src/test/java/org/folio/sample/integration/api/books/GetAllAvailableTest.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,71 @@ | ||
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; | ||
|
||
class GetAllAvailableTest extends AbstractBaseApiTest { | ||
|
||
@Test | ||
void testEmptyGet(){ | ||
|
||
Response response = ra() | ||
.get(getRequestUrl("books/available")); | ||
response.then().statusCode(is(HttpStatus.OK.value())); | ||
|
||
List<BookDTO> collection = response | ||
.body() | ||
.as(new TypeRef<List<BookDTO>>() {}); | ||
assertThat(collection, hasSize(0)); | ||
} | ||
|
||
@Test | ||
void testGetWithBooks(){ | ||
ra() | ||
.body( | ||
BookForCreationDTO | ||
.builder() | ||
.name("book 1") | ||
.publishedDate(LocalDate.of(2020, 1, 1)) | ||
.isAvailable(true) | ||
.build() | ||
) | ||
.post(getRequestUrl("books")) | ||
.then() | ||
.statusCode(is(HttpStatus.CREATED.value())); | ||
|
||
ra() | ||
.body( | ||
BookForCreationDTO | ||
.builder() | ||
.name("book 2") | ||
.publishedDate(LocalDate.of(2020, 1, 1)) | ||
.isAvailable(false) | ||
.build() | ||
) | ||
.post(getRequestUrl("books")) | ||
.then() | ||
.statusCode(is(HttpStatus.CREATED.value())); | ||
|
||
Response response = ra() | ||
.get(getRequestUrl("books/available")); | ||
response.then().statusCode(is(HttpStatus.OK.value())); | ||
|
||
List<BookDTO> collection = response | ||
.body() | ||
.as(new TypeRef<List<BookDTO>>() {}); | ||
assertThat(collection, hasSize(1)); | ||
assertThat(collection.get(0).getName(), is(equalTo("book 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