Compare commits
6 Commits
give-back-
...
polishing
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18d1038a18 | ||
|
|
f071d557ff | ||
|
|
b7db201e7b | ||
|
|
36316de3f7 | ||
|
|
428d281e38 | ||
|
|
62960ef444 |
@@ -8,4 +8,4 @@ RUN mvn -B -f pom.xml clean package -DskipTests
|
||||
FROM openjdk:11-jdk-slim
|
||||
COPY --from=build /workspace/target/*.jar app.jar
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["java","-jar","app.jar"]
|
||||
ENTRYPOINT ["java","-jar","app.jar", "--spring.profiles.active=prod"]
|
||||
17
README.md
17
README.md
@@ -19,14 +19,23 @@ In the terminal run the following command:
|
||||
$ docker-compose up
|
||||
```
|
||||
|
||||
#### Using Maven
|
||||
#### Using Maven (with H2 or local Postgres database)
|
||||
|
||||
First make sure that you adjust the configuration file - `src/main/resources/application.yml` with connection details to your database.
|
||||
First compile an application:
|
||||
|
||||
Then, in the terminal run the following command:
|
||||
```console
|
||||
$ mvn clean package
|
||||
$ mvn spring-boot:run
|
||||
```
|
||||
|
||||
Then, you have two options either run it with H2 database or with local Postgres database. For first approach just run:
|
||||
|
||||
```console
|
||||
$ mvn spring-boot:run
|
||||
```
|
||||
|
||||
For a second option, check in the configuration file - `src/main/resources/application.yml` for profile *local-postgres* if connection details are correct and if so, run the command:
|
||||
```console
|
||||
$ mvn spring-boot:run -P local-postgres
|
||||
```
|
||||
|
||||
#### Inside IntelliJ (with H2 or Postgres database)
|
||||
|
||||
31
pom.xml
31
pom.xml
@@ -33,6 +33,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -186,6 +190,33 @@
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>default</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<active-profiles>default</active-profiles>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>prod</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<active-profiles>prod</active-profiles>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>local-postgres</id>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<active-profiles>local-postgres</active-profiles>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>component-test</id>
|
||||
<build>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.wkrzywiec.hexagonal.library.DatabaseHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -12,15 +13,16 @@ public abstract class BaseComponentTest {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
protected String baseURL;
|
||||
|
||||
@Autowired
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
protected DatabaseHelper databaseHelper;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
this.baseURL = "http://localhost:" + port;
|
||||
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
|
||||
databaseHelper = new DatabaseHelper(jdbcTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.BookTestData;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import io.wkrzywiec.hexagonal.library.domain.BaseComponentTest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.BookStatus;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.ChangeBookStatusRequest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowBookCommand;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -16,45 +16,29 @@ public class BorrowBookComponentTest extends BaseComponentTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Borrow reserved book")
|
||||
@Sql({"/book-and-user.sql", "/available-book.sql"})
|
||||
@Sql({"/book-and-user.sql", "/reserved-book.sql"})
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenBookIsReserved_thenBorrowIt_thenBookIsBorrowed() {
|
||||
//given
|
||||
Long homoDeusBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
Long homoDeusBookId = databaseHelper.getHomoDeusBookId();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
Long activeUserId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO public.reserved (book_id, user_id) VALUES (?, ?)",
|
||||
homoDeusBookId,
|
||||
activeUserId);
|
||||
|
||||
BorrowBookCommand borrowBookCommand =
|
||||
BorrowBookCommand.builder()
|
||||
.bookId(homoDeusBookId )
|
||||
.userId(activeUserId)
|
||||
.build();
|
||||
ChangeBookStatusRequest borrowRequest =
|
||||
ChangeBookStatusRequest.builder()
|
||||
.userId(activeUserId)
|
||||
.status(BookStatus.BORROWED)
|
||||
.build();
|
||||
|
||||
//when
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(borrowBookCommand)
|
||||
.body(borrowRequest)
|
||||
.when()
|
||||
.post( baseURL + "/borrow")
|
||||
.patch( baseURL + "/books/" + homoDeusBookId + "/status")
|
||||
.prettyPeek()
|
||||
.then();
|
||||
|
||||
Long borrowId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM borrowed WHERE book_id = ?",
|
||||
Long.class,
|
||||
homoDeusBookId);
|
||||
|
||||
Long borrowId = databaseHelper.getPrimaryKeyOfBorrowedByBookId(homoDeusBookId);
|
||||
assertTrue(borrowId > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.BookTestData;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import io.wkrzywiec.hexagonal.library.domain.BaseComponentTest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.BookStatus;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.ChangeBookStatusRequest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.GiveBackBookCommand;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -16,44 +16,29 @@ public class GiveBackBookComponentTest extends BaseComponentTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Give back borrowed book")
|
||||
@Sql({"/book-and-user.sql", "/available-book.sql"})
|
||||
@Sql({"/book-and-user.sql", "/borrowed-book.sql"})
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenBookIsReserved_thenBorrowIt_thenBookIsBorrowed() {
|
||||
public void givenBookIsBorrowed_thenGiveBackIt_thenItIsAvailable() {
|
||||
//given
|
||||
Long homoDeusBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
Long homoDeusBookId = databaseHelper.getHomoDeusBookId();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
Long activeUserId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO public.borrowed (book_id, user_id) VALUES (?, ?)",
|
||||
homoDeusBookId,
|
||||
activeUserId);
|
||||
|
||||
GiveBackBookCommand giveBackBookCommand =
|
||||
GiveBackBookCommand.builder()
|
||||
.bookId(homoDeusBookId )
|
||||
ChangeBookStatusRequest giveBackRequest =
|
||||
ChangeBookStatusRequest.builder()
|
||||
.userId(activeUserId)
|
||||
.status(BookStatus.AVAILABLE)
|
||||
.build();
|
||||
|
||||
//when
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(giveBackBookCommand)
|
||||
.body(giveBackRequest)
|
||||
.when()
|
||||
.post( baseURL + "/giveBack")
|
||||
.patch( baseURL + "/books/" + homoDeusBookId + "/status")
|
||||
.prettyPeek()
|
||||
.then();
|
||||
|
||||
Long bookId = jdbcTemplate.queryForObject(
|
||||
"SELECT book_id FROM available WHERE book_id = ?",
|
||||
Long.class,
|
||||
homoDeusBookId);
|
||||
Long bookId = databaseHelper.getPrimaryKeyOfAvailableByBookBy(homoDeusBookId);
|
||||
|
||||
assertEquals(homoDeusBookId, bookId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.BookTestData;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import io.wkrzywiec.hexagonal.library.domain.BaseComponentTest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.BookStatus;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.ChangeBookStatusRequest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BookReservationCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.inventory.infrastructure.BookRepository;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -25,36 +25,25 @@ public class MakeReservationComponentTest extends BaseComponentTest {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenBookIsAvailable_thenMakeReservation_thenBookIsReserved() {
|
||||
//given
|
||||
Long homoDeusBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
Long homoDeusBookId = databaseHelper.getHomoDeusBookId();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
Long activeUserId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
|
||||
BookReservationCommand reservationCommand =
|
||||
BookReservationCommand.builder()
|
||||
.bookId(homoDeusBookId )
|
||||
.userId(activeUserId)
|
||||
.build();
|
||||
ChangeBookStatusRequest reservationRequest =
|
||||
ChangeBookStatusRequest.builder()
|
||||
.userId(activeUserId)
|
||||
.status(BookStatus.RESERVED)
|
||||
.build();
|
||||
|
||||
//when
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.body(reservationCommand)
|
||||
.body(reservationRequest)
|
||||
.when()
|
||||
.post( baseURL + "/reservations")
|
||||
.patch( baseURL + "/books/" + homoDeusBookId + "/status")
|
||||
.prettyPeek()
|
||||
.then();
|
||||
|
||||
Long reservationId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM reserved WHERE book_id = ?",
|
||||
Long.class,
|
||||
homoDeusBookId);
|
||||
|
||||
Long reservationId = databaseHelper.getPrimaryKeyOfReservationByBookId(homoDeusBookId);
|
||||
assertTrue(reservationId > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,17 +53,10 @@ public class AddNewBookComponentTest extends BaseComponentTest {
|
||||
.then();
|
||||
|
||||
//then
|
||||
Long savedBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE book_external_id = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookGoogleId());
|
||||
|
||||
Long savedBookId = databaseHelper.getHomoDeusBookId();
|
||||
assertTrue(savedBookId > 0);
|
||||
|
||||
Long availableBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM available WHERE book_id = ?",
|
||||
Long.class,
|
||||
savedBookId);
|
||||
Long availableBookId = databaseHelper.getPrimaryKeyOfAvailableByBookBy(savedBookId);
|
||||
|
||||
assertTrue(availableBookId > 0);
|
||||
}
|
||||
|
||||
@@ -33,11 +33,7 @@ public class AddNewUserComponentTest extends BaseComponentTest {
|
||||
.then();
|
||||
|
||||
//then
|
||||
Long savedUserId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
"john.doe@test.com");
|
||||
|
||||
Long savedUserId = databaseHelper.getJohnDoeUserId();
|
||||
assertTrue(savedUserId > 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.BorrowBook;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/borrow")
|
||||
@RequiredArgsConstructor
|
||||
public class BorrowBookController {
|
||||
|
||||
@Qualifier("BorrowBook")
|
||||
private final BorrowBook borrowBook;
|
||||
|
||||
@PostMapping("")
|
||||
public ResponseEntity<String> borrowBook(@RequestBody BorrowBookCommand borrowBookCommand){
|
||||
borrowBook.handle(borrowBookCommand);
|
||||
return new ResponseEntity<>("Book with an id " + borrowBookCommand.getBookId() + " was borrowed", HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.application.model.ChangeBookStatusRequest;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BookReservationCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.GiveBackBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.BorrowBook;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.GiveBackBook;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.ReserveBook;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PatchMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/books")
|
||||
@RequiredArgsConstructor
|
||||
public class BorrowingDomainController {
|
||||
|
||||
@Qualifier("GiveBackBook")
|
||||
private final GiveBackBook giveBackBook;
|
||||
|
||||
@Qualifier("ReserveBook")
|
||||
private final ReserveBook reserveBook;
|
||||
|
||||
@Qualifier("BorrowBook")
|
||||
private final BorrowBook borrowBook;
|
||||
|
||||
@PatchMapping("/{id}/status")
|
||||
public ResponseEntity<String> borrowBook(@PathVariable("id") Long bookId, @RequestBody ChangeBookStatusRequest request){
|
||||
switch (request.getStatus()){
|
||||
case AVAILABLE:
|
||||
giveBackBook.handle(new GiveBackBookCommand(bookId, request.getUserId()));
|
||||
return new ResponseEntity<>("Book with an id " + bookId + " was returned", HttpStatus.OK);
|
||||
case RESERVED:
|
||||
Long reservationId = reserveBook.handle(new BookReservationCommand(bookId, request.getUserId()));
|
||||
return new ResponseEntity<>("Reservation has been made with an id " + reservationId, HttpStatus.OK);
|
||||
case BORROWED:
|
||||
borrowBook.handle(new BorrowBookCommand(bookId, request.getUserId()));
|
||||
return new ResponseEntity<>("Book with an id " + bookId + " was borrowed", HttpStatus.OK);
|
||||
default:
|
||||
return new ResponseEntity<>("Book can't have status: " + request.getStatus(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.GiveBackBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.GiveBackBook;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/giveBack")
|
||||
@RequiredArgsConstructor
|
||||
public class GiveBackController {
|
||||
|
||||
@Qualifier("GiveBackBook")
|
||||
private final GiveBackBook giveBackBook;
|
||||
|
||||
@PostMapping("")
|
||||
public ResponseEntity<String> giveBack(@RequestBody GiveBackBookCommand giveBackBookCommand){
|
||||
giveBackBook.handle(giveBackBookCommand);
|
||||
return new ResponseEntity<>("Book with an id " + giveBackBookCommand.getBookId() + " was returned", HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BookReservationCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.ReserveBook;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/reservations")
|
||||
@RequiredArgsConstructor
|
||||
public class ReservationController {
|
||||
|
||||
@Qualifier("ReserveBook")
|
||||
private final ReserveBook reserveBook;
|
||||
|
||||
@PostMapping("")
|
||||
public ResponseEntity<String> makeReservation(@RequestBody BookReservationCommand reservationCommand){
|
||||
Long reservationId = reserveBook.handle(reservationCommand);
|
||||
return new ResponseEntity<>("Reservation has been made with an id " + reservationId, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application.model;
|
||||
|
||||
public enum BookStatus {
|
||||
AVAILABLE, RESERVED, BORROWED
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.application.model;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class ChangeBookStatusRequest {
|
||||
|
||||
private BookStatus status;
|
||||
private Long userId;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
public Optional<ActiveUser> getActiveUser(Long userId) {
|
||||
try {
|
||||
jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM public.user as u WHERE u.id = ?",
|
||||
"SELECT id FROM public.library_user as u WHERE u.id = ?",
|
||||
Long.class,
|
||||
userId);
|
||||
} catch (DataAccessException exception) {
|
||||
@@ -78,7 +78,7 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
"INSERT INTO reserved (book_id, user_id, reserved_date) VALUES (?, ?, ?)",
|
||||
reservedBook.getIdAsLong(),
|
||||
reservedBook.getAssignedUserIdAsLong(),
|
||||
reservedBook.getReservedDateAsInstant());
|
||||
Timestamp.from(reservedBook.getReservedDateAsInstant()));
|
||||
|
||||
jdbcTemplate.update(
|
||||
"DELETE FROM available WHERE book_id = ?",
|
||||
@@ -97,7 +97,7 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
"INSERT INTO borrowed (book_id, user_id, borrowed_date) VALUES (?, ?, ?)",
|
||||
borrowedBook.getIdAsLong(),
|
||||
borrowedBook.getAssignedUserIdAsLong(),
|
||||
borrowedBook.getBorrowedDateAsInstant());
|
||||
Timestamp.from(borrowedBook.getBorrowedDateAsInstant()));
|
||||
|
||||
jdbcTemplate.update(
|
||||
"DELETE FROM reserved WHERE book_id = ?",
|
||||
@@ -125,7 +125,7 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
try {
|
||||
return Optional.ofNullable(
|
||||
jdbcTemplate.queryForObject(
|
||||
"SELECT book_id AS bookId, user_id AS userId, reserved_date AS reservedDate FROM reserved WHERE reserved.book_id = ?",
|
||||
"SELECT book_id, user_id, reserved_date FROM reserved WHERE book_id = ?",
|
||||
new ReservedBookRowMapper(),
|
||||
bookId));
|
||||
} catch (DataAccessException exception) {
|
||||
@@ -148,9 +148,9 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
|
||||
private List<ReservedBook> getReservedBooksByUser(Long userId) {
|
||||
try {
|
||||
return jdbcTemplate.queryForList(
|
||||
"SELECT book_id FROM reserved WHERE reserved.user_id = ?",
|
||||
ReservedBook.class,
|
||||
return jdbcTemplate.query(
|
||||
"SELECT book_id, user_id, reserved_date FROM reserved WHERE user_id = ?",
|
||||
new ReservedBookRowMapper(),
|
||||
userId
|
||||
);
|
||||
} catch (DataAccessException exception){
|
||||
@@ -159,6 +159,14 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
}
|
||||
|
||||
private List<BorrowedBook> getBorrowedBooksByUser(Long userId) {
|
||||
return new ArrayList<>();
|
||||
try {
|
||||
return jdbcTemplate.query(
|
||||
"SELECT book_id, user_id, borrowed_date FROM borrowed WHERE user_id = ?",
|
||||
new BorrowedBookRowMapper(),
|
||||
userId
|
||||
);
|
||||
} catch (DataAccessException exception){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class EmailDatabaseAdapter implements EmailDatabase {
|
||||
public Optional<String> getUserEmailAddress(Long userId) {
|
||||
try {
|
||||
return Optional.ofNullable(jdbcTemplate.queryForObject(
|
||||
"SELECT email FROM user WHERE id = ?",
|
||||
"SELECT email FROM library_user WHERE id = ?",
|
||||
String.class,
|
||||
userId));
|
||||
} catch (DataAccessException ex){
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name="user")
|
||||
@Table(name="library_user")
|
||||
@EqualsAndHashCode
|
||||
public class User {
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
spring:
|
||||
application:
|
||||
name: library
|
||||
datasource:
|
||||
url: jdbc:h2:mem:testdb
|
||||
driverClassName: org.h2.Driver
|
||||
username: sa
|
||||
password: password
|
||||
jpa.database-platform: org.hibernate.dialect.H2Dialect
|
||||
@@ -1,9 +0,0 @@
|
||||
spring:
|
||||
application:
|
||||
name: library
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/library
|
||||
driverClassName: org.postgresql.Driver
|
||||
username: library
|
||||
password: library
|
||||
jpa.database-platform: org.hibernate.dialect.PostgreSQL9Dialect
|
||||
@@ -1,6 +1,39 @@
|
||||
spring:
|
||||
application:
|
||||
name: library
|
||||
profiles:
|
||||
active: @active-profiles@
|
||||
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: "*"
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: default
|
||||
datasource:
|
||||
url: jdbc:h2:mem:testdb
|
||||
driverClassName: org.h2.Driver
|
||||
username: sa
|
||||
password: password
|
||||
jpa.database-platform: org.hibernate.dialect.H2Dialect
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: local-postgres
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/library
|
||||
driverClassName: org.postgresql.Driver
|
||||
username: library
|
||||
password: library
|
||||
jpa.database-platform: org.hibernate.dialect.PostgreSQL9Dialect
|
||||
|
||||
---
|
||||
spring:
|
||||
profiles: prod
|
||||
datasource:
|
||||
url: jdbc:postgresql://${POSTGRES_SERVER}:5432/${POSTGRES_DB}
|
||||
driverClassName: org.postgresql.Driver
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CREATE TABLE IF NOT EXISTS public.user (
|
||||
CREATE TABLE IF NOT EXISTS library_user (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
first_name CHARACTER VARYING(255) NOT NULL,
|
||||
last_name CHARACTER VARYING(255) NOT NULL,
|
||||
|
||||
@@ -7,12 +7,12 @@ CREATE TABLE IF NOT EXISTS public.reserved (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
reserved_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
book_id BIGINT NOT NULL REFERENCES public.book,
|
||||
user_id BIGINT NOT NULL REFERENCES public.user
|
||||
user_id BIGINT NOT NULL REFERENCES public.library_user
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public.borrowed (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
borrowed_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
book_id BIGINT NOT NULL REFERENCES public.book,
|
||||
user_id BIGINT NOT NULL REFERENCES public.user
|
||||
user_id BIGINT NOT NULL REFERENCES public.library_user
|
||||
);
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.wkrzywiec.hexagonal.library;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class DatabaseHelper {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public Long getHomoDeusBookId(){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
}
|
||||
|
||||
public Long getJohnDoeUserId(){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM library_user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
}
|
||||
|
||||
public Long getPrimaryKeyOfAvailableByBookBy(Long bookId){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT book_id FROM available WHERE book_id = ?",
|
||||
Long.class,
|
||||
bookId);
|
||||
}
|
||||
|
||||
public Long getPrimaryKeyOfReservationByBookId(Long bookId){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM reserved WHERE book_id = ?",
|
||||
Long.class,
|
||||
bookId);
|
||||
}
|
||||
|
||||
public Long getPrimaryKeyOfBorrowedByBookId(Long bookId){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT book_id FROM borrowed WHERE book_id = ?",
|
||||
Long.class,
|
||||
bookId);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing.infrastructure;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.BookTestData;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import io.wkrzywiec.hexagonal.library.DatabaseHelper;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.ActiveUser;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.AvailableBook;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowedBook;
|
||||
@@ -10,7 +9,6 @@ import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.OverdueReserva
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.ReservationDetails;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.ReservedBook;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,12 +29,13 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private DatabaseHelper databaseHelper;
|
||||
private BorrowingDatabaseAdapter database;
|
||||
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
database = new BorrowingDatabaseAdapter(jdbcTemplate);
|
||||
databaseHelper = new DatabaseHelper(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,17 +44,14 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldSaveAvailableBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
database.save(new AvailableBook(bookId));
|
||||
|
||||
//then
|
||||
Long savedBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT book_id FROM available WHERE book_id = ?",
|
||||
Long.class,
|
||||
bookId);
|
||||
assertEquals(bookId, savedBookId);
|
||||
Long id = databaseHelper.getPrimaryKeyOfAvailableByBookBy(bookId);
|
||||
assertTrue(id > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +60,7 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldGetAvailableBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
Optional<AvailableBook> availableBookOptional = database.getAvailableBook(bookId);
|
||||
@@ -80,7 +76,7 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldGetActiveUser() {
|
||||
//given
|
||||
Long activeUserId = getJohnDoeUserIdFromDb();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
//when
|
||||
Optional<ActiveUser> activeUserOptional = database.getActiveUser(activeUserId);
|
||||
@@ -96,9 +92,8 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldSaveReservedBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
|
||||
Long activeUserId = getJohnDoeUserIdFromDb();
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
ReservedBook reservedBook = new ReservedBook(bookId, activeUserId);
|
||||
|
||||
@@ -113,16 +108,11 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
|
||||
@Test
|
||||
@DisplayName("Get reserved book by its id")
|
||||
@Sql({"/book-and-user.sql"})
|
||||
@Sql({"/book-and-user.sql", "/reserved-book.sql"})
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldFindReservedBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
Long johnDoeUserId = getJohnDoeUserIdFromDb();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO public.reserved (book_id, user_id) VALUES (?, ?)",
|
||||
bookId,
|
||||
johnDoeUserId);
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
Optional<ReservedBook> reservedBook = database.getReservedBook(bookId);
|
||||
@@ -138,8 +128,8 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldSaveBorrowedBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
Long activeUserId = getJohnDoeUserIdFromDb();
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
Long activeUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
BorrowedBook borrowedBook = new BorrowedBook(bookId, activeUserId);
|
||||
|
||||
@@ -147,10 +137,7 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
database.save(borrowedBook);
|
||||
|
||||
//then
|
||||
Long savedBookId = jdbcTemplate.queryForObject(
|
||||
"SELECT book_id FROM borrowed WHERE book_id = ?",
|
||||
Long.class,
|
||||
bookId);
|
||||
Long savedBookId = databaseHelper.getPrimaryKeyOfBorrowedByBookId(bookId);
|
||||
assertEquals(bookId, savedBookId);
|
||||
}
|
||||
|
||||
@@ -161,8 +148,8 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
public void shouldFindOverdueReservations(){
|
||||
//given
|
||||
DueDate thirdDayAfterReservation = new DueDate(Instant.now().plus(3, ChronoUnit.DAYS));
|
||||
Long overdueBookId = getHomoDeusBookIdFromDb();
|
||||
Long johnDoeUserId = getJohnDoeUserIdFromDb();
|
||||
Long overdueBookId = databaseHelper.getHomoDeusBookId();
|
||||
Long johnDoeUserId = databaseHelper.getJohnDoeUserId();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO public.reserved (book_id, user_id, reserved_date) VALUES (?, ?, ?)",
|
||||
overdueBookId,
|
||||
@@ -178,19 +165,11 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
|
||||
@Test
|
||||
@DisplayName("Find borrowed book by id")
|
||||
@Sql({"/book-and-user.sql"})
|
||||
@Sql({"/book-and-user.sql", "/borrowed-book.sql"})
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldFindBorrowedBook(){
|
||||
//given
|
||||
Long bookId = getHomoDeusBookIdFromDb();
|
||||
Long johnDoeUserId = getJohnDoeUserIdFromDb();
|
||||
jdbcTemplate.update(
|
||||
"INSERT INTO public.borrowed (book_id, user_id, borrowed_date) VALUES (?, ?, ?)",
|
||||
bookId,
|
||||
johnDoeUserId,
|
||||
Instant.now());
|
||||
|
||||
Long id = jdbcTemplate.queryForObject("SELECT book_id FROM borrowed WHERE book_id = ?", Long.class, bookId);
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
Optional<BorrowedBook> borrowedBook = database.getBorrowedBook(bookId);
|
||||
@@ -199,18 +178,4 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
assertTrue(borrowedBook.isPresent());
|
||||
assertEquals(bookId, borrowedBook.get().getIdAsLong());
|
||||
}
|
||||
|
||||
private Long getHomoDeusBookIdFromDb(){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
}
|
||||
|
||||
private Long getJohnDoeUserIdFromDb(){
|
||||
return jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.email.infrastructure;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.BookTestData;
|
||||
import io.wkrzywiec.hexagonal.library.DatabaseHelper;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -20,12 +21,13 @@ public class EmailDatabaseAdapterITCase {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private DatabaseHelper databaseHelper;
|
||||
private EmailDatabaseAdapter emailDatabase;
|
||||
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
emailDatabase = new EmailDatabaseAdapter(jdbcTemplate);
|
||||
databaseHelper = new DatabaseHelper(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,10 +36,7 @@ public class EmailDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenBookId_whenGetBookTitle_thenGetBookTitle() {
|
||||
//given
|
||||
Long bookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
Optional<String> bookTitle = emailDatabase.getTitleByBookId(bookId);
|
||||
@@ -52,10 +51,7 @@ public class EmailDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenWrongBookId_whenGetBookTitle_thenGetEmptyResult() {
|
||||
//given
|
||||
Long bookId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM book WHERE title = ?",
|
||||
Long.class,
|
||||
BookTestData.homoDeusBookTitle());
|
||||
Long bookId = databaseHelper.getHomoDeusBookId();
|
||||
|
||||
//when
|
||||
Optional<String> bookTitle = emailDatabase.getTitleByBookId(bookId + 1124);
|
||||
@@ -70,10 +66,7 @@ public class EmailDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenUserId_whenGetEmail_thenGetEmailAddress() {
|
||||
//given
|
||||
Long userId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
Long userId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
//when
|
||||
Optional<String> emailAddress = emailDatabase.getUserEmailAddress(userId);
|
||||
@@ -88,10 +81,7 @@ public class EmailDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void givenWrongUserId_whenGetEmail_thenGetEmptyResult() {
|
||||
//given
|
||||
Long userId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
Long userId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
//when
|
||||
Optional<String> emailAddress = emailDatabase.getUserEmailAddress(userId + 1124);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.user.infrastructure;
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.DatabaseHelper;
|
||||
import io.wkrzywiec.hexagonal.library.UserTestData;
|
||||
import io.wkrzywiec.hexagonal.library.domain.user.core.model.EmailAddress;
|
||||
import io.wkrzywiec.hexagonal.library.domain.user.core.model.User;
|
||||
@@ -20,6 +21,7 @@ public class UserDatabaseAdapterITCase {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private DatabaseHelper databaseHelper;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@@ -29,6 +31,7 @@ public class UserDatabaseAdapterITCase {
|
||||
@BeforeEach
|
||||
public void init(){
|
||||
userDatabase = new UserDatabaseAdapter(userRepository);
|
||||
databaseHelper = new DatabaseHelper(jdbcTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,10 +48,7 @@ public class UserDatabaseAdapterITCase {
|
||||
UserIdentifier userIdentifier = userDatabase.save(user);
|
||||
|
||||
//then
|
||||
Long savedUserId = jdbcTemplate.queryForObject(
|
||||
"SELECT id FROM user WHERE email = ?",
|
||||
Long.class,
|
||||
UserTestData.johnDoeEmail());
|
||||
Long savedUserId = databaseHelper.getJohnDoeUserId();
|
||||
|
||||
assertEquals(userIdentifier.getAsLong(), savedUserId);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
INSERT INTO public.author (name) VALUES
|
||||
INSERT INTO author (name) VALUES
|
||||
('Yuval Noah Harari')
|
||||
;
|
||||
|
||||
INSERT INTO public.book (book_external_id,isbn_10,isbn_13,title,publisher,published_date,description,page_count,image_link) VALUES
|
||||
INSERT INTO book (book_external_id,isbn_10,isbn_13,title,publisher,published_date,description,page_count,image_link) VALUES
|
||||
('dWYyCwAAQBAJ','1473545374','9781473545373','Homo Deus','Random House','2016-09-08','<p><b>**THE MILLION COPY BESTSELLER**</b><br> <b></b><br><b> <i>Sapiens </i>showed us where we came from. In uncertain times, <i>Homo Deus</i> shows us where we’re going.</b></p><p> Yuval Noah Harari envisions a near future in which we face a new set of challenges. <i>Homo Deus</i> explores the projects, dreams and nightmares that will shape the twenty-first century and beyond – from overcoming death to creating artificial life.</p><p> It asks the fundamental questions: how can we protect this fragile world from our own destructive power? And what does our future hold?<br> <b></b><br><b> ''<i>Homo Deus</i> will shock you. It will entertain you. It will make you think in ways you had not thought before’ Daniel Kahneman, bestselling author of <i>Thinking, Fast and Slow</i></b></p>',528,'http://books.google.com/books/content?id=dWYyCwAAQBAJ&printsec=frontcover&img=1&zoom=1&edge=curl&imgtk=AFLRE73PkLs4TNB-W2uhDvXJkIB4-9G9AJ_L1iYTYLEXa3zi2kahdsN9-_0tL7WRWgujNpjMA5ZuJO7_ykFUlCWAyLzcQVcGkqUS-NOkUkEcJ_ZRrgq48URpcfBrJWQCwSWtHo5pEGkp&source=gbs_api')
|
||||
;
|
||||
|
||||
INSERT INTO public.book_author (book_id, author_id)
|
||||
INSERT INTO book_author (book_id, author_id)
|
||||
SELECT b.id, a.id
|
||||
FROM public.book b, public.author a
|
||||
WHERE b.title = 'Homo deus' AND a.name = 'Yuval Noah Harari'
|
||||
;
|
||||
|
||||
INSERT INTO public.user (first_name, last_name, email) VALUES
|
||||
INSERT INTO library_user (first_name, last_name, email) VALUES
|
||||
('John','Doe','john.doe@test.com')
|
||||
;
|
||||
5
src/test/resources/borrowed-book.sql
Normal file
5
src/test/resources/borrowed-book.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
INSERT INTO public.borrowed (book_id, user_id)
|
||||
VALUES (
|
||||
(SELECT id FROM book WHERE title = 'Homo Deus'),
|
||||
(SELECT id FROM library_user WHERE email = 'john.doe@test.com')
|
||||
);
|
||||
@@ -2,6 +2,6 @@ DELETE FROM public.borrowed;
|
||||
DELETE FROM public.reserved;
|
||||
DELETE FROM public.available;
|
||||
DELETE FROM public.book_author;
|
||||
DELETE FROM public.user;
|
||||
DELETE FROM public.library_user;
|
||||
DELETE FROM public.book;
|
||||
DELETE FROM public.author;
|
||||
5
src/test/resources/reserved-book.sql
Normal file
5
src/test/resources/reserved-book.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
INSERT INTO public.reserved (book_id, user_id)
|
||||
VALUES (
|
||||
(SELECT id FROM book WHERE title = 'Homo Deus'),
|
||||
(SELECT id FROM library_user WHERE email = 'john.doe@test.com')
|
||||
);
|
||||
Reference in New Issue
Block a user