diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 87e80098..ce35b12b 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'temurin' cache: maven server-id: github # Value of the distributionManagement/repository/id field of the pom.xml diff --git a/pom.xml b/pom.xml index 3ae7c48c..6c618f41 100644 --- a/pom.xml +++ b/pom.xml @@ -145,6 +145,21 @@ lombok + + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-tracing-bridge-brave + + + net.ttddyy.observation + datasource-micrometer-spring-boot + 1.0.5 + + org.springframework.boot spring-boot-starter-test @@ -197,10 +212,6 @@ org.seleniumhq.selenium htmlunit-driver - - org.springframework.boot - spring-boot-starter-actuator - org.springdoc diff --git a/src/main/java/se/citerus/dddsample/config/DDDSampleApplicationContext.java b/src/main/java/se/citerus/dddsample/config/DDDSampleApplicationContext.java index 03a4dfcb..c676ea92 100644 --- a/src/main/java/se/citerus/dddsample/config/DDDSampleApplicationContext.java +++ b/src/main/java/se/citerus/dddsample/config/DDDSampleApplicationContext.java @@ -2,6 +2,7 @@ import com.pathfinder.api.GraphTraversalService; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -27,20 +28,26 @@ @Configuration -@RequiredArgsConstructor @Import({InterfacesApplicationContext.class, InfrastructureMessagingJmsConfig.class}) public class DDDSampleApplicationContext { + @Autowired private CargoRepository cargoRepository; + + @Autowired private VoyageRepository voyageRepository; + + @Autowired private LocationRepository locationRepository; + + @Autowired private HandlingEventRepository handlingEventRepository; - private RoutingService routingService; + @Autowired private GraphTraversalService graphTraversalService; + @Autowired private ApplicationEvents applicationEvents; - private HandlingEventFactory handlingEventFactory; @Bean public CargoFactory cargoFactory() { @@ -48,7 +55,7 @@ public CargoFactory cargoFactory() { } @Bean - public BookingService bookingService(CargoFactory cargoFactory) { + public BookingService bookingService(CargoFactory cargoFactory,RoutingService routingService) { return new BookingServiceImpl(cargoRepository, locationRepository, routingService, cargoFactory); } @@ -58,7 +65,7 @@ public CargoInspectionService cargoInspectionService() { } @Bean - public HandlingEventService handlingEventService() { + public HandlingEventService handlingEventService(HandlingEventFactory handlingEventFactory) { return new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory); } diff --git a/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java b/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java index 43c95d6d..8794c58b 100644 --- a/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java +++ b/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java @@ -31,7 +31,7 @@ public List distinctEventsByCompletionTime() { final List ordered = new ArrayList<>( new HashSet<>(handlingEvents) ); - sort(ordered, BY_COMPLETION_TIME_COMPARATOR); + ordered.sort(BY_COMPLETION_TIME_COMPARATOR); return Collections.unmodifiableList(ordered); } diff --git a/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/InfrastructureMessagingJmsConfig.java b/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/InfrastructureMessagingJmsConfig.java index d3ea2820..f9fcc6b6 100644 --- a/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/InfrastructureMessagingJmsConfig.java +++ b/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/InfrastructureMessagingJmsConfig.java @@ -114,7 +114,7 @@ public Connection connection(ConnectionFactory connectionFactory) throws JMSExce @Bean public Session session(Connection connection) throws JMSException { - return ((ActiveMQConnection) connection).createSession(false, Session.AUTO_ACKNOWLEDGE); + return connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } @Bean diff --git a/src/main/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryJPA.java b/src/main/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryJPA.java index 9d0b17f0..b4827ce6 100644 --- a/src/main/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryJPA.java +++ b/src/main/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryJPA.java @@ -23,7 +23,7 @@ default HandlingHistory lookupHandlingHistoryOfCargo(final TrackingId trackingId return new HandlingHistory(getHandlingHistoryOfCargo(trackingId.idString())); } - @Query("select he from HandlingEvent he where he.cargo.trackingId = :trackingId and he.location != NULL") + @Query("select he from HandlingEvent he where he.cargo.trackingId = :trackingId and he.location is not NULL") List getHandlingHistoryOfCargo(String trackingId); } diff --git a/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java b/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java index cd03acbf..c3387d46 100644 --- a/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java +++ b/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java @@ -2,6 +2,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.ServletRequestDataBinder; @@ -39,7 +40,8 @@ @RequestMapping("/admin") public final class CargoAdminController { - private final BookingServiceFacade bookingServiceFacade; + @Autowired + private BookingServiceFacade bookingServiceFacade; public CargoAdminController(BookingServiceFacade bookingServiceFacade) { this.bookingServiceFacade = bookingServiceFacade; diff --git a/src/main/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingController.java b/src/main/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingController.java index 7eb0c259..3879e911 100644 --- a/src/main/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingController.java +++ b/src/main/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingController.java @@ -2,6 +2,7 @@ import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; @@ -33,8 +34,8 @@ * @see se.citerus.dddsample.interfaces.booking.web.CargoAdminController */ @Controller -@RequiredArgsConstructor @RequestMapping("/track") +@RequiredArgsConstructor public final class CargoTrackingController { private final CargoRepository cargoRepository; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e7793ece..2b55daa0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,8 +4,7 @@ server: logging: level: - org.hibernate.SQL: info - net.sf.ehcache.config.ConfigurationFactory: error + jdbc: debug uploadDirectory: /tmp/upload parseFailureDirectory: /tmp/failed @@ -17,4 +16,12 @@ spring: url: jdbc:hsqldb:mem:dddsample username: sa password: "" - driver-class-name: org.hsqldb.jdbcDriver + +jdbc: + datasource-proxy: + enabled: true + query: + logger-name: jdbc + enable-logging: true + multiline: false + include-parameter-values: true diff --git a/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/CargoRepositoryTest.java b/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/CargoRepositoryTest.java index 650257e2..f01c3712 100644 --- a/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/CargoRepositoryTest.java +++ b/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/CargoRepositoryTest.java @@ -1,7 +1,6 @@ package se.citerus.dddsample.infrastructure.persistence.jpa; import jakarta.persistence.EntityManager; -import lombok.RequiredArgsConstructor; import org.assertj.core.groups.Tuple; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -21,7 +20,6 @@ import se.citerus.dddsample.domain.model.voyage.VoyageNumber; import se.citerus.dddsample.domain.model.voyage.VoyageRepository; -import java.math.BigInteger; import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; @@ -40,13 +38,21 @@ @ContextConfiguration(classes = TestRepositoryConfig.class) @Transactional @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -@RequiredArgsConstructor public class CargoRepositoryTest { - private final CargoRepository cargoRepository; - private final LocationRepository locationRepository; - private final VoyageRepository voyageRepository; - private final HandlingEventRepository handlingEventRepository; - private final EntityManager entityManager; + @Autowired + CargoRepository cargoRepository; + + @Autowired + LocationRepository locationRepository; + + @Autowired + VoyageRepository voyageRepository; + + @Autowired + HandlingEventRepository handlingEventRepository; + + @Autowired + EntityManager entityManager; @Test public void testFindByCargoId() { @@ -172,7 +178,7 @@ private void flush() { entityManager.flush(); } - private int countLegsForCargo(long cargoId) { - return ((BigInteger) entityManager.createNativeQuery(String.format("select count(*) from Leg l where l.cargo_id = %d", cargoId)).getSingleResult()).intValue(); + private long countLegsForCargo(long cargoId) { + return (long) entityManager.createNativeQuery(String.format("select count(*) from Leg l where l.cargo_id = %d", cargoId)).getSingleResult(); } } \ No newline at end of file diff --git a/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryTest.java b/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryTest.java index 73991f16..40782cb2 100644 --- a/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryTest.java +++ b/src/test/java/se/citerus/dddsample/infrastructure/persistence/jpa/HandlingEventRepositoryTest.java @@ -1,9 +1,9 @@ package se.citerus.dddsample.infrastructure.persistence.jpa; import jakarta.persistence.EntityManager; -import lombok.RequiredArgsConstructor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -28,13 +28,19 @@ @ContextConfiguration(classes = TestRepositoryConfig.class) @Transactional @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -@RequiredArgsConstructor public class HandlingEventRepositoryTest { - private final HandlingEventRepository handlingEventRepository; - private final CargoRepository cargoRepository; - private final LocationRepository locationRepository; - private final EntityManager entityManager; + @Autowired + HandlingEventRepository handlingEventRepository; + + @Autowired + CargoRepository cargoRepository; + + @Autowired + LocationRepository locationRepository; + + @Autowired + EntityManager entityManager; @Test public void testSave() { diff --git a/src/test/java/se/citerus/dddsample/interfaces/handling/HandlingReportIntegrationTest.java b/src/test/java/se/citerus/dddsample/interfaces/handling/HandlingReportIntegrationTest.java index a401501f..47174f76 100644 --- a/src/test/java/se/citerus/dddsample/interfaces/handling/HandlingReportIntegrationTest.java +++ b/src/test/java/se/citerus/dddsample/interfaces/handling/HandlingReportIntegrationTest.java @@ -62,7 +62,7 @@ void shouldReturn201ResponseWhenHandlingReportIsSubmitted() throws Exception { .body(body); ResponseEntity response = restTemplate.exchange(request, String.class); - assertThat(response.getStatusCodeValue()).isEqualTo(201); + assertThat(response.getStatusCode().value()).isEqualTo(201); Thread.sleep(1000); // TODO replace with Awaitility diff --git a/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java b/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java index db2a7054..7c3c7876 100644 --- a/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java +++ b/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java @@ -42,8 +42,9 @@ public void setup() throws Exception { cargoRepository.init(); CargoTrackingController controller = new CargoTrackingController(cargoRepository, - new HandlingEventRepositoryInMem(), - new FakeMessageSource()); + new HandlingEventRepositoryInMem(), + new FakeMessageSource(), + new TrackCommandValidator()); InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/jsp/"); diff --git a/src/test/java/se/citerus/dddsample/interfaces/tracking/ws/CargoTrackingRestServiceIntegrationTest.java b/src/test/java/se/citerus/dddsample/interfaces/tracking/ws/CargoTrackingRestServiceIntegrationTest.java index 772bedff..82e19d61 100644 --- a/src/test/java/se/citerus/dddsample/interfaces/tracking/ws/CargoTrackingRestServiceIntegrationTest.java +++ b/src/test/java/se/citerus/dddsample/interfaces/tracking/ws/CargoTrackingRestServiceIntegrationTest.java @@ -46,9 +46,9 @@ void shouldReturn200ResponseAndJsonWhenRequestingCargoWithIdABC123() throws Exce ResponseEntity response = restTemplate.exchange(request, String.class); - assertThat(response.getStatusCodeValue()).isEqualTo(200); + assertThat(response.getStatusCode().value()).isEqualTo(200); String expected = StreamUtils.copyToString(getClass().getResourceAsStream("/sampleCargoTrackingResponse.json"), StandardCharsets.UTF_8); - assertThat(response.getHeaders().get("Content-Type")).containsExactly("application/json;charset=UTF-8"); + assertThat(response.getHeaders().get("Content-Type")).containsExactly("application/json"); assertThat(response.getBody()).isEqualTo(expected); } diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml index a4e804ab..da897049 100644 --- a/src/test/resources/config/application.yml +++ b/src/test/resources/config/application.yml @@ -1,3 +1,8 @@ spring: dataSource: - url: jdbc:hsqldb:mem:dddsample_test \ No newline at end of file + url: jdbc:hsqldb:mem:dddsample_test + main: + allow-bean-definition-overriding: true +server: + error: + include-message: always \ No newline at end of file diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties deleted file mode 100644 index 9d89009b..00000000 --- a/src/test/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -log4j.rootLogger=info, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n - -log4j.logger.net.sf.ehcache.config.ConfigurationFactory=error - -log4j.logger.se.citerus.dddsample=debug -log4j.logger.org.hibernate.SQL=debug -#log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=debug - -#log4j.logger.org.springframework.orm=debug -#log4j.logger.org.springframework.transaction=debug -#TODO move this config to spring boot config