Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix UT,pipeline,config
Browse files Browse the repository at this point in the history
c5ms committed Nov 22, 2024
1 parent 266cd6b commit 3082654
Showing 16 changed files with 87 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -145,6 +145,21 @@
<artifactId>lombok</artifactId>
</dependency>

<!-- log monitor trace -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>net.ttddyy.observation</groupId>
<artifactId>datasource-micrometer-spring-boot</artifactId>
<version>1.0.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@@ -197,10 +212,6 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- doc -->
<dependency>
<groupId>org.springdoc</groupId>
Original file line number Diff line number Diff line change
@@ -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,28 +28,34 @@


@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() {
return new CargoFactory(locationRepository, cargoRepository);
}

@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);
}

Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public List<HandlingEvent> distinctEventsByCompletionTime() {
final List<HandlingEvent> ordered = new ArrayList<>(
new HashSet<>(handlingEvents)
);
sort(ordered, BY_COMPLETION_TIME_COMPARATOR);
ordered.sort(BY_COMPLETION_TIME_COMPARATOR);
return Collections.unmodifiableList(ordered);
}

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<HandlingEvent> getHandlingHistoryOfCargo(String trackingId);

}
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 10 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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() {
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ void shouldReturn201ResponseWhenHandlingReportIsSubmitted() throws Exception {
.body(body);

ResponseEntity<String> response = restTemplate.exchange(request, String.class);
assertThat(response.getStatusCodeValue()).isEqualTo(201);
assertThat(response.getStatusCode().value()).isEqualTo(201);

Thread.sleep(1000); // TODO replace with Awaitility

Original file line number Diff line number Diff line change
@@ -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/");
Original file line number Diff line number Diff line change
@@ -46,9 +46,9 @@ void shouldReturn200ResponseAndJsonWhenRequestingCargoWithIdABC123() throws Exce

ResponseEntity<String> 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);
}

7 changes: 6 additions & 1 deletion src/test/resources/config/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
spring:
dataSource:
url: jdbc:hsqldb:mem:dddsample_test
url: jdbc:hsqldb:mem:dddsample_test
main:
allow-bean-definition-overriding: true
server:
error:
include-message: always
15 changes: 0 additions & 15 deletions src/test/resources/log4j.properties

This file was deleted.

0 comments on commit 3082654

Please sign in to comment.