浏览代码

Bootstrap certificates restructured

Andrew Grant 4 月之前
父节点
当前提交
b49625e64e

+ 84 - 0
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadBirthCertificates.java

@@ -0,0 +1,84 @@
+/*
+ * Copyright (c)  18 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.bootstrap;
+
+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.commands.certificates.birthcertificates.BirthCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
+import scot.carricksoftware.grants.enums.certificates.CertificateType;
+import scot.carricksoftware.grants.enums.general.Sex;
+import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
+import scot.carricksoftware.grants.services.people.PersonService;
+import scot.carricksoftware.grants.services.places.organisations.OrganisationService;
+import scot.carricksoftware.grants.services.places.places.PlaceService;
+
+
+@Component
+@Profile("dev")
+public class DataLoadBirthCertificates {
+
+    private static final Logger logger = LogManager.getLogger(DataLoadBirthCertificates.class);
+    private final OrganisationService organisationService;
+    private final BirthCertificateService birthCertificateService;
+    private final PersonService personService;
+    private final PlaceService placeService;
+
+    public DataLoadBirthCertificates(OrganisationService organisationService,
+                                     BirthCertificateService birthCertificateService,
+                                     PersonService personService, PlaceService placeService) {
+        this.organisationService = organisationService;
+        this.birthCertificateService = birthCertificateService;
+        this.personService = personService;
+        this.placeService = placeService;
+    }
+
+    public void load() {
+        logger.debug("DataLoadBirthCertificates::load");
+        loadBirthCertificates();
+    }
+
+    private void loadBirthCertificates() {
+        logger.debug("DataLoadBirthCertificates::LoadBirthCertificates");
+        BirthCertificateCommand birthCertificateCommand = new BirthCertificateCommandImpl();
+
+        birthCertificateCommand.setCertificateNumber("999");
+        birthCertificateCommand.setCertificateDate("25/01/1953");
+        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
+
+        birthCertificateCommand.setRegistrationAuthority(organisationService.findById(2L));
+        birthCertificateCommand.setVolume("01");
+        birthCertificateCommand.setNumber("02");
+        birthCertificateCommand.setCertificateSource(organisationService.findById(1L));
+
+        birthCertificateCommand.setNewBorn(personService.findById(3L));
+        birthCertificateCommand.setSex(Sex.MALE);
+        birthCertificateCommand.setWhenBorn("25/01/1953 01:01");
+        birthCertificateCommand.setUntrackedWhereBorn("Edinburgh");
+        birthCertificateCommand.setFather(personService.findById(1L));
+        birthCertificateCommand.setUntrackedFather("Untracked Father");
+
+        birthCertificateCommand.setMother(personService.findById(2L));
+        birthCertificateCommand.setWhereBorn(placeService.findById(1L));
+        birthCertificateCommand.setInformant(personService.findById(1L));
+        birthCertificateCommand.setUntrackedInformant("Untracked Informant");
+        birthCertificateCommand.setInformantQualification("Qualification");
+        birthCertificateCommand.setWhenRegistered("22/01/1978");
+        birthCertificateCommand.setWhereRegistered("Where Registered");
+        birthCertificateCommand.setFatherUsualResidence(placeService.findById(1L));
+        birthCertificateCommand.setUntrackedFatherUsualResidence("57 Back Street, Edinburgh");
+        birthCertificateCommand.setInformantResidence("2 Wilson Avenue, Edinburgh");
+        birthCertificateCommand.setMotherUsualResidence(placeService.findById(1L));
+        birthCertificateCommand.setUntrackedMotherUsualResidence("92 Broughton Road, Edinburgh");
+        birthCertificateCommand.setMotherPlaceOfBirth("Drop");
+        birthCertificateCommand.setFatherPlaceOfBirth("Drip");
+        birthCertificateService.saveBirthCertificateCommand(birthCertificateCommand);
+    }
+
+
+}

+ 10 - 71
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificates.java

@@ -9,92 +9,31 @@ 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.commands.certificates.birthcertificates.BirthCertificateCommand;
-import scot.carricksoftware.grants.commands.certificates.birthcertificates.BirthCertificateCommandImpl;
-import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommand;
-import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommandImpl;
-import scot.carricksoftware.grants.enums.certificates.CertificateType;
-import scot.carricksoftware.grants.enums.general.Sex;
-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.organisations.OrganisationService;
-import scot.carricksoftware.grants.services.places.places.PlaceService;
-
 
 @Component
 @Profile("dev")
 public class DataLoadCertificates {
 
     private static final Logger logger = LogManager.getLogger(DataLoadCertificates.class);
-    private final OrganisationService organisationService;
-    private final BirthCertificateService birthCertificateService;
-    private final PersonService personService;
-    private final PlaceService placeService;
-    private final DeathCertificateService deathCertificateService;
 
-    public DataLoadCertificates(OrganisationService organisationService,
-                                BirthCertificateService birthCertificateService,
-                                PersonService personService, PlaceService placeService,
-                                DeathCertificateService deathCertificateService) {
-        this.organisationService = organisationService;
-        this.birthCertificateService = birthCertificateService;
-        this.personService = personService;
-        this.placeService = placeService;
-        this.deathCertificateService = deathCertificateService;
+    private final DataLoadBirthCertificates dataLoadBirthCertificates;
+    private final DataLoadDeathCertificates dataLoadDeathertificates;
+
+    public DataLoadCertificates(DataLoadBirthCertificates dataLoadBirthCertificates,
+                                DataLoadDeathCertificates dataLoadDeathertificates) {
+        this.dataLoadBirthCertificates = dataLoadBirthCertificates;
+        this.dataLoadDeathertificates = dataLoadDeathertificates;
     }
 
+
     public void load() {
         logger.debug("DataLoadCertificates::load");
-        loadBirthCertificates();
-        loadDeathCertificates();
+        dataLoadBirthCertificates.load();
+        dataLoadDeathertificates.load();
     }
 
-    private void loadBirthCertificates() {
-        logger.debug("DataLoadCertificates::LoadBirthCertificates");
-        BirthCertificateCommand birthCertificateCommand = new BirthCertificateCommandImpl();
-
-        birthCertificateCommand.setCertificateNumber("999");
-        birthCertificateCommand.setCertificateDate("25/01/1953");
-        birthCertificateCommand.setCertificateType(CertificateType.EXTRACT);
-
-        birthCertificateCommand.setRegistrationAuthority(organisationService.findById(2L));
-        birthCertificateCommand.setVolume("01");
-        birthCertificateCommand.setNumber("02");
-        birthCertificateCommand.setCertificateSource(organisationService.findById(1L));
 
-        birthCertificateCommand.setNewBorn(personService.findById(3L));
-        birthCertificateCommand.setSex(Sex.MALE);
-        birthCertificateCommand.setWhenBorn("25/01/1953 01:01");
-        birthCertificateCommand.setUntrackedWhereBorn("Edinburgh");
-        birthCertificateCommand.setFather(personService.findById(1L));
-        birthCertificateCommand.setUntrackedFather("Untracked Father");
 
-        birthCertificateCommand.setMother(personService.findById(2L));
-        birthCertificateCommand.setWhereBorn(placeService.findById(1L));
-        birthCertificateCommand.setInformant(personService.findById(1L));
-        birthCertificateCommand.setUntrackedInformant("Untracked Informant");
-        birthCertificateCommand.setInformantQualification("Qualification");
-        birthCertificateCommand.setWhenRegistered("22/01/1978");
-        birthCertificateCommand.setWhereRegistered("Where Registered");
-        birthCertificateCommand.setFatherUsualResidence(placeService.findById(1L));
-        birthCertificateCommand.setUntrackedFatherUsualResidence("57 Back Street, Edinburgh");
-        birthCertificateCommand.setInformantResidence("2 Wilson Avenue, Edinburgh");
-        birthCertificateCommand.setMotherUsualResidence(placeService.findById(1L));
-        birthCertificateCommand.setUntrackedMotherUsualResidence("92 Broughton Road, Edinburgh");
-        birthCertificateCommand.setMotherPlaceOfBirth("Drop");
-        birthCertificateCommand.setFatherPlaceOfBirth("Drip");
-        birthCertificateService.saveBirthCertificateCommand(birthCertificateCommand);
-    }
-
-    private void loadDeathCertificates() {
-        logger.debug("DataLoadCertificates::LoadDeathCertificates");
-        DeathCertificateCommand deathCertificateCommand = new DeathCertificateCommandImpl();
-        deathCertificateCommand.setDeceased(personService.findById(1L));
-        deathCertificateCommand.setFather(personService.findById(2L));
-
-        deathCertificateService.saveDeathCertificateCommand(deathCertificateCommand);
-    }
 
 
 }

+ 48 - 0
src/main/java/scot/carricksoftware/grants/bootstrap/DataLoadDeathCertificates.java

@@ -0,0 +1,48 @@
+/*
+ * Copyright (c)  18 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.bootstrap;
+
+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.commands.certificates.deathcertificates.DeathCertificateCommand;
+import scot.carricksoftware.grants.commands.certificates.deathcertificates.DeathCertificateCommandImpl;
+import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
+import scot.carricksoftware.grants.services.people.PersonService;
+
+
+@Component
+@Profile("dev")
+public class DataLoadDeathCertificates {
+
+    private static final Logger logger = LogManager.getLogger(DataLoadDeathCertificates.class);
+    private final PersonService personService;
+    private final DeathCertificateService deathCertificateService;
+
+    public DataLoadDeathCertificates(PersonService personService,
+                                     DeathCertificateService deathCertificateService) {
+        this.personService = personService;
+        this.deathCertificateService = deathCertificateService;
+    }
+
+    public void load() {
+        logger.debug("DataLoadDeathCertificates::load");
+        loadDeathCertificates();
+    }
+
+
+    private void loadDeathCertificates() {
+        logger.debug("DataLoadCertificates::LoadDeathCertificates");
+        DeathCertificateCommand deathCertificateCommand = new DeathCertificateCommandImpl();
+        deathCertificateCommand.setDeceased(personService.findById(1L));
+        deathCertificateCommand.setFather(personService.findById(2L));
+
+        deathCertificateService.saveDeathCertificateCommand(deathCertificateCommand);
+    }
+
+
+}

+ 0 - 121
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesBirthCertificatesTest.java

@@ -1,121 +0,0 @@
-package scot.carricksoftware.grants.bootstrap;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-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.commands.certificates.birthcertificates.BirthCertificateCommand;
-import scot.carricksoftware.grants.domains.people.Person;
-import scot.carricksoftware.grants.domains.places.Organisation;
-import scot.carricksoftware.grants.domains.places.Place;
-import scot.carricksoftware.grants.enums.certificates.CertificateType;
-import scot.carricksoftware.grants.enums.general.Sex;
-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.organisations.OrganisationService;
-import scot.carricksoftware.grants.services.places.places.PlaceService;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-
-@ExtendWith(MockitoExtension.class)
-public class DataLoadCertificatesBirthCertificatesTest {
-
-    private DataLoadCertificates dataLoadCertificates;
-
-    @Mock
-    private BirthCertificateService birthCertificateServiceMock;
-
-    @Mock
-    private DeathCertificateService deathCertificateServiceMock;
-
-    @Mock
-    private OrganisationService organisationServiceMock;
-
-    @Mock
-    private PersonService personServiceMock;
-
-    @Mock
-    private PlaceService placeServiceMock;
-
-    @Mock
-    private Person fatherMock;
-
-    @Mock
-    private Person motherMock;
-
-    @Mock
-    private Person newBornMock;
-
-    @Mock
-    private Place placeMock;
-
-    @Mock
-    private Organisation certificateSourceMock;
-
-    @Mock
-    private Organisation registrationAuthorityMock;
-
-
-    @BeforeEach
-    public void setup() {
-        dataLoadCertificates = new DataLoadCertificates(
-                organisationServiceMock,
-                birthCertificateServiceMock,
-                personServiceMock,
-                placeServiceMock,
-                deathCertificateServiceMock);
-    }
-
-    @Test
-    void birthCertificateIsCreatedTest() {
-        ArgumentCaptor<BirthCertificateCommand> captor = ArgumentCaptor.forClass(BirthCertificateCommand.class);
-        when(personServiceMock.findById(1L)).thenReturn(fatherMock);
-        when(personServiceMock.findById(2L)).thenReturn(motherMock);
-        when(personServiceMock.findById(3L)).thenReturn(newBornMock);
-        when(placeServiceMock.findById(1L)).thenReturn(placeMock);
-        when(certificateSourceMock.getName()).thenReturn("Source");
-        when(registrationAuthorityMock.getName()).thenReturn("Authority");
-        when(organisationServiceMock.findById(1L)).thenReturn(certificateSourceMock);
-        when(organisationServiceMock.findById(2L)).thenReturn(registrationAuthorityMock);
-
-
-        dataLoadCertificates.load();
-
-        verify(birthCertificateServiceMock).saveBirthCertificateCommand(captor.capture());
-        assertEquals("999", captor.getValue().getCertificateNumber());
-        assertEquals("25/01/1953", captor.getValue().getCertificateDate());
-        assertEquals(CertificateType.EXTRACT, captor.getValue().getCertificateType());
-        assertEquals("Authority", captor.getValue().getRegistrationAuthority().getName());
-        assertEquals("01", captor.getValue().getVolume());
-        assertEquals("02", captor.getValue().getNumber());
-        assertEquals("Source", captor.getValue().getCertificateSource().getName());
-        assertEquals(newBornMock, captor.getValue().getNewBorn());
-        assertEquals(Sex.MALE, captor.getValue().getSex());
-        assertEquals("25/01/1953 01:01", captor.getValue().getWhenBorn());
-        assertEquals(fatherMock, captor.getValue().getFather());
-        assertEquals("Untracked Father", captor.getValue().getUntrackedFather());
-        assertEquals("Edinburgh", captor.getValue().getUntrackedWhereBorn());
-        assertEquals(placeMock, captor.getValue().getWhereBorn());
-        assertEquals(motherMock, captor.getValue().getMother());
-        assertEquals(fatherMock, captor.getValue().getInformant());
-        assertEquals("Untracked Informant", captor.getValue().getUntrackedInformant());
-        assertEquals("Qualification", captor.getValue().getInformantQualification());
-        assertEquals("Where Registered", captor.getValue().getWhereRegistered());
-        assertEquals("22/01/1978", captor.getValue().getWhenRegistered());
-        assertEquals("57 Back Street, Edinburgh", captor.getValue().getUntrackedFatherUsualResidence());
-        assertEquals(placeMock, captor.getValue().getFatherUsualResidence());
-        assertEquals("2 Wilson Avenue, Edinburgh", captor.getValue().getInformantResidence());
-        assertEquals(placeMock, captor.getValue().getFatherUsualResidence());
-        assertEquals("92 Broughton Road, Edinburgh", captor.getValue().getUntrackedMotherUsualResidence());
-        assertEquals(placeMock, captor.getValue().getMotherUsualResidence());
-        assertEquals("Drop", captor.getValue().getMotherPlaceOfBirth());
-        assertEquals("Drip", captor.getValue().getFatherPlaceOfBirth());
-    }
-
-}

+ 0 - 79
src/test/java/scot/carricksoftware/grants/bootstrap/DataLoadCertificatesDeathCertificatesTest.java

@@ -1,79 +0,0 @@
-package scot.carricksoftware.grants.bootstrap;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-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.commands.certificates.deathcertificates.DeathCertificateCommand;
-import scot.carricksoftware.grants.domains.people.Person;
-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.organisations.OrganisationService;
-import scot.carricksoftware.grants.services.places.places.PlaceService;
-
-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;
-
-
-@ExtendWith(MockitoExtension.class)
-public class DataLoadCertificatesDeathCertificatesTest {
-
-    private DataLoadCertificates dataLoadCertificates;
-
-    @Mock
-    private BirthCertificateService birthCertificateServiceMock;
-
-    @Mock
-    private DeathCertificateService deathCertificateServiceMock;
-
-    @Mock
-    private OrganisationService organisationServiceMock;
-
-    @Mock
-    private PersonService personServiceMock;
-
-    @Mock
-    private PlaceService placeServiceMock;
-
-    @SuppressWarnings("unused")
-    private final Person father = GetRandomPerson();
-    @SuppressWarnings("unused")
-    private final Person mother = GetRandomPerson();
-    @SuppressWarnings("unused")
-    private final Person deceased = GetRandomPerson();
-    @SuppressWarnings("unused")
-    private final Person spouse = GetRandomPerson();
-    @SuppressWarnings("unused")
-    private final Person informant = GetRandomPerson();
-
-
-    @BeforeEach
-    public void setup() {
-        dataLoadCertificates = new DataLoadCertificates(
-                organisationServiceMock,
-                birthCertificateServiceMock,
-                personServiceMock,
-                placeServiceMock,
-                deathCertificateServiceMock);
-        when(personServiceMock.findById(1L)).thenReturn(deceased);
-        when(personServiceMock.findById(2L)).thenReturn(father);
-        when(personServiceMock.findById(3L)).thenReturn(informant);
-    }
-
-    @Test
-    void DeathCertificateIsCreatedTest() {
-        ArgumentCaptor<DeathCertificateCommand> captor = ArgumentCaptor.forClass(DeathCertificateCommand.class);
-
-        dataLoadCertificates.load();
-        verify(deathCertificateServiceMock).saveDeathCertificateCommand(captor.capture());
-        assertEquals(deceased, captor.getValue().getDeceased());
-        assertEquals(father, captor.getValue().getFather());
-
-    }
-
-}