Compare commits
8 Commits
polishing
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
601f1c2fea | ||
|
|
e2b77ab1d0 | ||
|
|
967a349b4c | ||
|
|
42b08c8995 | ||
|
|
58a9a0f95b | ||
|
|
9b0c37ffd7 | ||
|
|
53939113f2 | ||
|
|
a9fd37ec5a |
49
pom.xml
49
pom.xml
@@ -72,7 +72,7 @@
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.12</version>
|
||||
<version>42.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
@@ -91,16 +91,28 @@
|
||||
<version>1.2.32</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>spock-core</artifactId>
|
||||
<version>1.3-groovy-2.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spockframework</groupId>
|
||||
<artifactId>spock-spring</artifactId>
|
||||
<version>1.3-groovy-2.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tngtech.archunit</groupId>
|
||||
@@ -108,10 +120,7 @@
|
||||
<version>0.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -144,8 +153,25 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<reportsDirectory>${surefire.and.failsafe.report.dir}</reportsDirectory>
|
||||
<includes>
|
||||
<include>**/*Spec.java</include>
|
||||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.10.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
@@ -263,6 +289,7 @@
|
||||
<sonar.sources>.</sonar.sources>
|
||||
<sonar.inclusions>src/main/java/**,src/main/resources/**</sonar.inclusions>
|
||||
<sonar.exclusions>${code.coverage.exclusions}</sonar.exclusions>
|
||||
<sonat.tests>src/test/groovy,src/test/java</sonat.tests>
|
||||
<sonar.projectKey>wkrzywiec_library-hexagonal</sonar.projectKey>
|
||||
<sonar.organization>wkrzywiec</sonar.organization>
|
||||
<sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
|
||||
|
||||
@@ -11,7 +11,7 @@ public class OverdueReservationScheduler {
|
||||
@Qualifier("CancelOverdueReservations")
|
||||
private final CancelOverdueReservations overdueReservations;
|
||||
|
||||
@Scheduled(fixedRate = 10 * 1000)
|
||||
@Scheduled(fixedRate = 60 * 1000)
|
||||
public void checkOverdueReservations(){
|
||||
overdueReservations.cancelOverdueReservations();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BookReservatio
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BookReservedEvent;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.BorrowedBook;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.DueDate;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.GiveBackBookCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.MakeBookAvailableCommand;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.OverdueReservation;
|
||||
@@ -24,8 +23,6 @@ import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.incoming.Reser
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.outgoing.BorrowingDatabase;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.outgoing.BorrowingEventPublisher;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
|
||||
public class BorrowingFacade implements MakeBookAvailable, ReserveBook, CancelOverdueReservations, BorrowBook, GiveBackBook {
|
||||
@@ -61,10 +58,9 @@ public class BorrowingFacade implements MakeBookAvailable, ReserveBook, CancelOv
|
||||
|
||||
@Override
|
||||
public void cancelOverdueReservations() {
|
||||
DueDate dueDate = new DueDate(Instant.now().plus(3L, ChronoUnit.DAYS));
|
||||
List<OverdueReservation> overdueReservationList = database.findReservationsAfter(dueDate);
|
||||
List<OverdueReservation> overdueReservationList = database.findReservationsForMoreThan(3L);
|
||||
overdueReservationList.forEach(
|
||||
overdue -> database.save(new AvailableBook(overdue.getBookIdentificationAsLong())));
|
||||
overdueBook -> database.save(new AvailableBook(overdueBook.getBookIdentificationAsLong())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface BorrowingDatabase {
|
||||
void save(BorrowedBook borrowedBook);
|
||||
Optional<AvailableBook> getAvailableBook(Long bookId);
|
||||
Optional<ActiveUser> getActiveUser(Long userId);
|
||||
List<OverdueReservation> findReservationsAfter(DueDate dueDate);
|
||||
List<OverdueReservation> findReservationsForMoreThan(Long days);
|
||||
Optional<ReservedBook> getReservedBook(Long bookId);
|
||||
Optional<BorrowedBook> getBorrowedBook(Long bookId);
|
||||
}
|
||||
|
||||
@@ -110,11 +110,11 @@ public class BorrowingDatabaseAdapter implements BorrowingDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OverdueReservation> findReservationsAfter(DueDate dueDate) {
|
||||
public List<OverdueReservation> findReservationsForMoreThan(Long days) {
|
||||
List<OverdueReservationEntity> entities = jdbcTemplate.query(
|
||||
"SELECT id AS reservationId, book_id AS bookIdentification FROM reserved WHERE reserved_date > ?",
|
||||
"SELECT id AS reservationId, book_id AS bookIdentification FROM reserved WHERE DATEADD(day, ?, reserved_date) > NOW()",
|
||||
new BeanPropertyRowMapper<OverdueReservationEntity>(OverdueReservationEntity.class),
|
||||
Timestamp.from(dueDate.asInstant()));
|
||||
days);
|
||||
return entities.stream()
|
||||
.map(entity -> new OverdueReservation(entity.getReservationId(), entity.getBookIdentification()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.wkrzywiec.hexagonal.library.domain.borrowing
|
||||
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.BorrowingFacade
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.AvailableBook
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.MakeBookAvailableCommand
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.outgoing.BorrowingEventPublisher
|
||||
import spock.lang.Specification
|
||||
|
||||
class BorrowingFacadeSpec extends Specification {
|
||||
|
||||
private BorrowingFacade facade;
|
||||
private InMemoryBorrowingDatabase database;
|
||||
private BorrowingEventPublisher eventPublisher;
|
||||
|
||||
def setup(){
|
||||
database = new InMemoryBorrowingDatabase();
|
||||
eventPublisher = new BorrowingEventPublisherFake();
|
||||
facade = new BorrowingFacade(database, eventPublisher);
|
||||
}
|
||||
|
||||
def "Make a book available"(){
|
||||
|
||||
given: "prepare a command"
|
||||
def command = new MakeBookAvailableCommand(100L)
|
||||
|
||||
when: "receive MakeBookAvailableCommand"
|
||||
facade.handle(command)
|
||||
|
||||
then: "check database to have this book as available"
|
||||
database.availableBooks[100L].idAsLong == new AvailableBook(100L).idAsLong
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class BorrowingFacadeTest {
|
||||
public void givenBookIsReserved_when3daysPass_thenBookIsAvailable(){
|
||||
//given
|
||||
ReservedBook reservedBook = ReservationTestData.anyReservedBook(100L, 100L);
|
||||
changeReservationTimeFor(reservedBook, 4L);
|
||||
changeReservationTimeFor(reservedBook, Instant.now().minus(4, ChronoUnit.DAYS));
|
||||
database.reservedBooks.put(100L, reservedBook);
|
||||
|
||||
//when
|
||||
@@ -158,7 +158,7 @@ public class BorrowingFacadeTest {
|
||||
public void givenBookIsReserved_when2daysPass_thenBookIsStillReserved(){
|
||||
//given
|
||||
ReservedBook reservedBook = ReservationTestData.anyReservedBook(100L, 100L);
|
||||
changeReservationTimeFor(reservedBook, 2L);
|
||||
changeReservationTimeFor(reservedBook, Instant.now().minus(2, ChronoUnit.DAYS));
|
||||
database.reservedBooks.put(100L, reservedBook);
|
||||
|
||||
//when
|
||||
@@ -168,14 +168,6 @@ public class BorrowingFacadeTest {
|
||||
assertEquals(1, database.reservedBooks.size());
|
||||
}
|
||||
|
||||
private void changeReservationTimeFor(ReservedBook reservedBook, Long daysFromNow) {
|
||||
try {
|
||||
FieldUtils.writeField(reservedBook, "reservedDate", Instant.now().plus(daysFromNow, ChronoUnit.DAYS), true);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Successfully borrow a book")
|
||||
public void givenReservedBookAndActiveUser_whenBorrowing_thenBookIsBorrowed(){
|
||||
@@ -213,4 +205,12 @@ public class BorrowingFacadeTest {
|
||||
assertEquals(1, database.availableBooks.size());
|
||||
assertEquals(0, database.activeUsers.get(activeUser.getIdAsLong()).getBorrowedBookList().size());
|
||||
}
|
||||
|
||||
private void changeReservationTimeFor(ReservedBook reservedBook, Instant reservationDate) {
|
||||
try {
|
||||
FieldUtils.writeField(reservedBook, "reservedDate", reservationDate, true);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.ReservationId;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.model.ReservedBook;
|
||||
import io.wkrzywiec.hexagonal.library.domain.borrowing.core.ports.outgoing.BorrowingDatabase;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
@@ -63,11 +65,11 @@ public class InMemoryBorrowingDatabase implements BorrowingDatabase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OverdueReservation> findReservationsAfter(DueDate dueDate) {
|
||||
public List<OverdueReservation> findReservationsForMoreThan(Long days) {
|
||||
return reservedBooks.values().stream()
|
||||
.filter(reservedBook ->
|
||||
reservedBook.getReservedDateAsInstant()
|
||||
.isAfter(dueDate.asInstant()))
|
||||
Instant.now().isAfter(
|
||||
reservedBook.getReservedDateAsInstant().plus(days, ChronoUnit.DAYS)))
|
||||
.map(reservedBook ->
|
||||
new OverdueReservation(
|
||||
1L,
|
||||
|
||||
@@ -147,7 +147,6 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
@Sql(scripts = "/clean-database.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public void shouldFindOverdueReservations(){
|
||||
//given
|
||||
DueDate thirdDayAfterReservation = new DueDate(Instant.now().plus(3, ChronoUnit.DAYS));
|
||||
Long overdueBookId = databaseHelper.getHomoDeusBookId();
|
||||
Long johnDoeUserId = databaseHelper.getJohnDoeUserId();
|
||||
jdbcTemplate.update(
|
||||
@@ -157,7 +156,7 @@ public class BorrowingDatabaseAdapterITCase {
|
||||
Instant.now().plus(4, ChronoUnit.DAYS));
|
||||
|
||||
//when
|
||||
OverdueReservation overdueReservation = database.findReservationsAfter(thirdDayAfterReservation).get(0);
|
||||
OverdueReservation overdueReservation = database.findReservationsForMoreThan(3L).get(0);
|
||||
|
||||
//then
|
||||
assertEquals(overdueBookId, overdueReservation.getBookIdentificationAsLong());
|
||||
|
||||
Reference in New Issue
Block a user