Browse Source

Add appendixImage to converters

Andrew Grant 1 month ago
parent
commit
aa52266d7c

+ 22 - 0
src/main/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageCommandConverter.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.images.appendiximage;
+
+
+import jakarta.validation.constraints.NotNull;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+
+@Component
+public interface AppendixImageCommandConverter extends Converter<AppendixImageCommand, AppendixImage> {
+
+    @Override
+    AppendixImage convert(@SuppressWarnings("NullableProblems") @NotNull AppendixImageCommand source);
+
+
+}

+ 32 - 0
src/main/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageCommandConverterImpl.java

@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.images.appendiximage;
+
+
+import jakarta.validation.constraints.NotNull;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+
+@Component
+public class AppendixImageCommandConverterImpl implements AppendixImageCommandConverter {
+
+    @SuppressWarnings("DuplicatedCode")
+    @Override
+    public AppendixImage convert(@NotNull AppendixImageCommand source) {
+        AppendixImage target = new AppendixImage();
+        target.setId(source.getId());
+        target.setImage(source.getImage());
+        target.setLevel(source.getLevel());
+        target.setOrder(source.getOrder());
+        target.setCaption(source.getCaption());
+        target.setHeight(source.getHeight());
+        target.setWidth(source.getWidth());
+        return target;
+    }
+
+
+}

+ 19 - 0
src/main/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageConverter.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.images.appendiximage;
+
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+
+@SuppressWarnings("unused")
+@Component
+public interface AppendixImageConverter extends Converter<AppendixImage, AppendixImageCommand> {
+
+    @SuppressWarnings("NullableProblems")
+    AppendixImageCommand convert(AppendixImage source);
+}

+ 31 - 0
src/main/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageConverterImpl.java

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 11/03/2025, 18:55. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.images.appendiximage;
+
+
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommandImpl;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+
+@Component
+public class AppendixImageConverterImpl implements AppendixImageConverter {
+
+    @SuppressWarnings("DuplicatedCode")
+    @Override
+    public AppendixImageCommand convert(AppendixImage source) {
+        AppendixImageCommand target = new AppendixImageCommandImpl();
+        target.setId(source.getId());
+        target.setOrder(source.getOrder());
+        target.setCaption(source.getCaption());
+        target.setHeight(source.getHeight());
+        target.setWidth(source.getWidth());
+        target.setImage(source.getImage());
+        target.setLevel(source.getLevel());
+
+        return target;
+    }
+}

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/images/personimage/PersonImageCommandConverterImpl.java

@@ -14,6 +14,7 @@ import scot.carricksoftware.grants.domains.images.PersonImage;
 @Component
 public class PersonImageCommandConverterImpl implements PersonImageCommandConverter {
 
+    @SuppressWarnings("DuplicatedCode")
     @Override
     public PersonImage convert(@NotNull PersonImageCommand source) {
         PersonImage target = new PersonImage();

+ 1 - 0
src/main/java/scot/carricksoftware/grants/converters/images/personimage/PersonImageConverterImpl.java

@@ -14,6 +14,7 @@ import scot.carricksoftware.grants.domains.images.PersonImage;
 @Component
 public class PersonImageConverterImpl implements PersonImageConverter {
 
+    @SuppressWarnings("DuplicatedCode")
     @Override
     public PersonImageCommand convert(PersonImage source) {
         PersonImageCommand target = new PersonImageCommandImpl();

+ 62 - 0
src/test/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageCommandConverterTest.java

@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 28/03/2025, 10:44. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.images.appendiximage;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommandImpl;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+import scot.carricksoftware.grants.domains.images.Image;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
+
+class AppendixImageCommandConverterTest {
+
+    private AppendixImageCommandConverter converter;
+
+    @BeforeEach
+    void setUp() {
+        converter = new AppendixImageCommandConverterImpl();
+    }
+
+    @Test
+    void covertTest() {
+        Long Id = GetRandomLong();
+        Image image = new Image();
+        String level = GetRandomString();
+        String order = GetRandomString();
+        String caption = GetRandomString();
+        String height = GetRandomString();
+        String width = GetRandomString();
+
+
+        AppendixImageCommand source = new AppendixImageCommandImpl();
+
+        source.setId(Id);
+        source.setImage(image);
+        source.setLevel(level);
+        source.setOrder(order);
+        source.setCaption(caption);
+        source.setHeight(height);
+        source.setWidth(width);
+
+
+        AppendixImage target = converter.convert(source);
+
+        assertNotNull(target);
+        assertEquals(Id, target.getId());
+        assertEquals(image, target.getImage());
+        assertEquals(level, target.getLevel());
+        assertEquals(order, target.getOrder());
+        assertEquals(caption, target.getCaption());
+        assertEquals(height, target.getHeight());
+        assertEquals(width, target.getWidth());
+    }
+}

+ 60 - 0
src/test/java/scot/carricksoftware/grants/converters/images/appendiximage/AppendixImageConverterTest.java

@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) Andrew Grant of Carrick Software 28/03/2025, 10:44. All rights reserved.
+ *
+ */
+
+package scot.carricksoftware.grants.converters.images.appendiximage;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import scot.carricksoftware.grants.commands.images.AppendixImageCommand;
+import scot.carricksoftware.grants.domains.images.AppendixImage;
+import scot.carricksoftware.grants.domains.images.Image;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static scot.carricksoftware.grants.GenerateCertificateRandomValues.GetRandomString;
+import static scot.carricksoftware.grants.GenerateRandomNumberValues.GetRandomLong;
+
+class AppendixImageConverterTest {
+
+    private AppendixImageConverter converter;
+
+    @BeforeEach
+    void setUp() {
+        converter = new AppendixImageConverterImpl();
+    }
+
+    @Test
+    void covertTest() {
+        Long Id = GetRandomLong();
+        Image image = new Image();
+        String level = GetRandomString();
+        String order = GetRandomString();
+        String caption = GetRandomString();
+        String height = GetRandomString();
+        String width = GetRandomString();
+
+        AppendixImage source = new AppendixImage();
+
+        source.setId(Id);
+        source.setImage(image);
+        source.setLevel(level);
+        source.setOrder(order);
+        source.setCaption(caption);
+        source.setHeight(height);
+        source.setWidth(width);
+
+        AppendixImageCommand target = converter.convert(source);
+
+        assertNotNull(target);
+        assertEquals(Id, target.getId());
+        assertEquals(image, target.getImage());
+        assertEquals(level, target.getLevel());
+        assertEquals(order, target.getOrder());
+        assertEquals(caption, target.getCaption());
+        assertEquals(height, target.getHeight());
+        assertEquals(width, target.getWidth());
+
+    }
+}