浏览代码

BaseCertificate Bootstrap

Andrew Grant 6 月之前
父节点
当前提交
c62d0a7a01

+ 19 - 6
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java

@@ -9,11 +9,17 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.springframework.context.annotation.Profile;
 import org.springframework.stereotype.Component;
-import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
 import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
+import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
+
+import java.sql.Date;
+import java.time.LocalDate;
 
 @Component
 @Profile("dev")
@@ -24,13 +30,15 @@ public class DataLoadCertificates {
     private final BirthCertificateService birthCertificateService;
     private final DeathCertificateService deathCertificateService;
     private final PersonService personService;
+    private final PlaceService placeService;
 
     public DataLoadCertificates(BirthCertificateService birthCertificateService,
                                 DeathCertificateService deathCertificateService,
-                                PersonService personService) {
+                                PersonService personService, PlaceService placeService) {
         this.birthCertificateService = birthCertificateService;
         this.deathCertificateService = deathCertificateService;
         this.personService = personService;
+        this.placeService = placeService;
     }
 
 
@@ -40,11 +48,16 @@ public class DataLoadCertificates {
         loadDeathCertificates();
     }
 
-
     private void loadBirthCertificates() {
-        BirthCertificate birthCertificate = new BirthCertificate();
-        birthCertificate.setNewBorn(personService.findById(1L));
-        birthCertificateService.save(birthCertificate);
+        BirthCertificateCommand birthCertificateCommand = new BirthCertificateCommandImpl();
+        birthCertificateCommand.setNewBorn(personService.findById(1L));
+        birthCertificateCommand.setCertificateDate(Date.valueOf(LocalDate.now()));
+        birthCertificateCommand.setCertificateNumber("999");
+        Place place = placeService.findById(1L);
+
+        birthCertificateCommand.setCertificateIssuedAt(place);
+
+        birthCertificateService.saveBirthCertificateCommand(birthCertificateCommand);
 
     }
 

+ 1 - 1
src/main/java/scot/carricksoftware/grants/domains/certificates/BaseCertificate.java

@@ -29,7 +29,7 @@ public class BaseCertificate extends BaseEntity {
     private Place certificateIssuedAt;
 
     @Column(name= "`certificate_date`")
-    @Temporal(TemporalType.TIMESTAMP)
+    @Temporal(TemporalType.DATE)
     private Date certificateDate;
 
     @SuppressWarnings("unused")

+ 20 - 4
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesTest.java

@@ -6,17 +6,23 @@ import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
-import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommand;
 import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
 import scot.carricksoftware.grants.domains.people.Person;
+import scot.carricksoftware.grants.domains.places.Place;
 import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
 import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
 import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
+
+import java.sql.Date;
+import java.time.LocalDate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static scot.carricksoftware.grants.GenerateRandomPeopleValues.GetRandomPerson;
+import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomPlace;
 
 @ExtendWith(MockitoExtension.class)
 public class DataLoadCertificatesTest {
@@ -32,24 +38,34 @@ public class DataLoadCertificatesTest {
     @Mock
     private PersonService personServiceMock;
 
+    @Mock
+    private PlaceService placeServiceMock;
+
 
     @BeforeEach
     public void setUp() {
         dataLoadCertificates = new DataLoadCertificates(birthCertificateServiceMock,
                 deathCertificateServiceMock,
-                personServiceMock);
+                personServiceMock,
+                placeServiceMock);
     }
 
     @Test
     public void birthCertificatesAreLoadedTest() {
         Person person = GetRandomPerson();
         when(personServiceMock.findById(1L)).thenReturn(person);
-        ArgumentCaptor<BirthCertificate> captor = ArgumentCaptor.forClass(BirthCertificate.class);
+        Place place = GetRandomPlace();
+        when(placeServiceMock.findById(1L)).thenReturn(place);
+
+        ArgumentCaptor<BirthCertificateCommand> captor = ArgumentCaptor.forClass(BirthCertificateCommand.class);
 
         dataLoadCertificates.load();
 
-        verify(birthCertificateServiceMock).save(captor.capture());
+        verify(birthCertificateServiceMock).saveBirthCertificateCommand(captor.capture());
         assertEquals(person, captor.getValue().getNewBorn());
+        assertEquals(place, captor.getValue().getCertificateIssuedAt());
+        assertEquals("999", captor.getValue().getCertificateNumber());
+        assertEquals(Date.valueOf(LocalDate.now()), captor.getValue().getCertificateDate());
     }
 
     @Test