Andrew Grant 6 сар өмнө
parent
commit
ba0d0c1640

+ 22 - 0
src/main/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationCommandConverter.java

@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+
+import jakarta.validation.constraints.NotNull;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+@Component
+public interface OrganisationCommandConverter extends Converter<OrganisationCommand, Organisation> {
+
+    @Override
+    Organisation convert(@SuppressWarnings("NullableProblems") @NotNull OrganisationCommand source);
+
+
+}

+ 26 - 0
src/main/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationCommandConverterImpl.java

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+
+import jakarta.validation.constraints.NotNull;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+@Component
+public class OrganisationCommandConverterImpl implements OrganisationCommandConverter {
+
+    @Override
+    public Organisation convert(@NotNull OrganisationCommand source) {
+        Organisation target = new Organisation();
+        target.setId(source.getId());
+        target.setName(source.getName());
+        return target;
+    }
+
+
+}

+ 19 - 0
src/main/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationConverter.java

@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+@SuppressWarnings("unused")
+@Component
+public interface OrganisationConverter extends Converter<Organisation, OrganisationCommand> {
+
+    @SuppressWarnings("NullableProblems")
+    OrganisationCommand convert(Organisation source);
+}

+ 24 - 0
src/main/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationConverterImpl.java

@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommandImpl;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+@Component
+public class OrganisationConverterImpl implements OrganisationConverter {
+
+    @Override
+    public OrganisationCommand convert(Organisation source) {
+        OrganisationCommand target = new OrganisationCommandImpl();
+        target.setId(source.getId());
+        target.setName(source.getName());
+        return target;
+    }
+}

+ 1 - 1
src/test/java/scot/carricksoftware/grants/converters/places/countries/CountryCensusCommandConverterImplTest.java → src/test/java/scot/carricksoftware/grants/converters/places/countries/CountryCommandConverterImplTest.java

@@ -21,7 +21,7 @@ import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLo
 import static scot.carricksoftware.grants.GenerateRandomPlaceValues.GetRandomRegion;
 
 
-public class CountryCensusCommandConverterImplTest {
+public class CountryCommandConverterImplTest {
 
     final CountryCommandConverterImpl converter = new CountryCommandConverterImpl();
     CountryCommand source;

+ 42 - 0
src/test/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationCommandConverterImplTest.java

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c)  19 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommandImpl;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
+
+
+public class OrganisationCommandConverterImplTest {
+
+    final OrganisationCommandConverterImpl converter = new OrganisationCommandConverterImpl();
+    OrganisationCommand source;
+
+    @BeforeEach
+    public void setUp() {
+        source = new OrganisationCommandImpl();
+    }
+
+    @Test
+    public void convert() {
+        Long id = GetRandomLong();
+        String name = GetRandomString();
+
+        source.setId(id);
+        source.setName(name);
+
+        Organisation target = converter.convert(source);
+        assert target != null;
+        assertEquals(id, target.getId());
+        assertEquals(name, target.getName());
+    }
+}

+ 45 - 0
src/test/java/scot/carricksoftware/grants/converters/places/organisations/OrganisationConverterImplTest.java

@@ -0,0 +1,45 @@
+/*
+ * Copyright (c)  19 Feb 2025, Andrew Grant of Carrick Software .
+ * All rights reserved.
+ */
+
+package scot.carricksoftware.grants.converters.places.organisations;
+
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.places.organisations.OrganisationCommand;
+import scot.carricksoftware.grants.domains.places.Organisation;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
+
+
+@Component
+public class OrganisationConverterImplTest {
+
+    final OrganisationConverterImpl converter = new OrganisationConverterImpl();
+    Organisation source;
+
+    @BeforeEach
+    public void setUp() {
+        source = new Organisation();
+    }
+
+    @Test
+    public void convertTest() {
+        Long id = GetRandomLong();
+        String name = GetRandomString();
+
+        source.setId(id);
+        source.setName(name);
+
+        OrganisationCommand target = converter.convert(source);
+        assert target != null;
+        assertEquals(id, target.getId());
+        assertEquals(name, target.getName());
+    }
+
+}