From 52cd1744f34a909a124820f471c619fb1b38bfc7 Mon Sep 17 00:00:00 2001 From: Elis Date: Mon, 6 Nov 2023 18:03:31 +0100 Subject: [PATCH] BpmnDTOTest & BpmnIdDtoTest --- .../service/model/model/BpmnDTOTest.java | 162 ++++++++++++++++++ .../service/model/model/BpmnIdDtoTest.java | 47 +++++ 2 files changed, 209 insertions(+) create mode 100644 src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnDTOTest.java create mode 100644 src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnIdDtoTest.java diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnDTOTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnDTOTest.java new file mode 100644 index 00000000..432108a2 --- /dev/null +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnDTOTest.java @@ -0,0 +1,162 @@ +package it.gov.pagopa.atmlayer.service.model.model; + +import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum; +import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum; +import org.junit.jupiter.api.Test; +import java.util.UUID; +import java.sql.Timestamp; + +import static org.junit.jupiter.api.Assertions.*; + +public class BpmnDTOTest { + + @Test + public void testGetterAndSetter() { + BpmnDTO bpmnDTO = new BpmnDTO(); + + + bpmnDTO.setBpmnId(UUID.randomUUID()); + bpmnDTO.setModelVersion(1L); + bpmnDTO.setDeployedFileName("example.bpmn"); + bpmnDTO.setDefinitionKey("process_key"); + bpmnDTO.setFunctionType(FunctionTypeEnum.MENU); + bpmnDTO.setStatus(StatusEnum.CREATED); + bpmnDTO.setSha256("hash123"); + bpmnDTO.setDefinitionVersionCamunda(2); + bpmnDTO.setCamundaDefinitionId("camunda123"); + bpmnDTO.setDescription("BPMN Description"); + bpmnDTO.setResourceFile(new ResourceFileDTO()); + bpmnDTO.setResource("Resource Content"); + bpmnDTO.setDeploymentId(UUID.randomUUID()); + bpmnDTO.setCreatedAt(new Timestamp(System.currentTimeMillis())); + bpmnDTO.setLastUpdatedAt(new Timestamp(System.currentTimeMillis())); + bpmnDTO.setCreatedBy("User1"); + bpmnDTO.setLastUpdatedBy("User2"); + + + assertEquals(bpmnDTO.getBpmnId(), bpmnDTO.getBpmnId()); + assertEquals(bpmnDTO.getModelVersion(), 1L); + assertEquals(bpmnDTO.getDeployedFileName(), "example.bpmn"); + assertEquals(bpmnDTO.getDefinitionKey(), "process_key"); + assertEquals(bpmnDTO.getFunctionType(), FunctionTypeEnum.MENU); + assertEquals(bpmnDTO.getStatus(), StatusEnum.CREATED); + assertEquals(bpmnDTO.getSha256(), "hash123"); + assertEquals(bpmnDTO.getDefinitionVersionCamunda(), 2); + assertEquals(bpmnDTO.getCamundaDefinitionId(), "camunda123"); + assertEquals(bpmnDTO.getDescription(), "BPMN Description"); + assertEquals(bpmnDTO.getResourceFile(), new ResourceFileDTO()); + assertEquals(bpmnDTO.getResource(), "Resource Content"); + assertEquals(bpmnDTO.getDeploymentId(), bpmnDTO.getDeploymentId()); + assertNotNull(bpmnDTO.getCreatedAt()); + assertNotNull(bpmnDTO.getLastUpdatedAt()); + assertEquals(bpmnDTO.getCreatedBy(), "User1"); + assertEquals(bpmnDTO.getLastUpdatedBy(), "User2"); + } + + @Test + public void testNoArgsConstructor() { + BpmnDTO bpmnDTO = new BpmnDTO(); + assertNotNull(bpmnDTO); + } + + @Test + public void testAllArgsConstructor() { + UUID bpmnId = UUID.randomUUID(); + Long modelVersion = 2L; + BpmnDTO bpmnDTO = new BpmnDTO(bpmnId, modelVersion, "file.bpmn", "key123", + FunctionTypeEnum.SPONTANEOUS_PAYMENT, StatusEnum.DEPLOYED, "hash456", 3, + "camunda456", "BPMN Description", new ResourceFileDTO(), + "Resource Content", UUID.randomUUID(), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), "User3", "User4"); + + assertEquals(bpmnDTO.getBpmnId(), bpmnId); + assertEquals(bpmnDTO.getModelVersion(), modelVersion); + } + + @Test + public void testBuilder() { + BpmnDTO bpmnDTO = BpmnDTO.builder() + .bpmnId(UUID.randomUUID()) + .modelVersion(3L) + .deployedFileName("file3.bpmn") + .definitionKey("key789") + .functionType(FunctionTypeEnum.SPONTANEOUS_PAYMENT) + .status(StatusEnum.CREATED) + .sha256("hash789") + .definitionVersionCamunda(4) + .camundaDefinitionId("camunda789") + .description("BPMN Description 3") + .resourceFile(new ResourceFileDTO()) + .resource("Resource Content 3") + .deploymentId(UUID.randomUUID()) + .createdAt(new Timestamp(System.currentTimeMillis())) + .lastUpdatedAt(new Timestamp(System.currentTimeMillis())) + .createdBy("User5") + .lastUpdatedBy("User6") + .build(); + + assertNotNull(bpmnDTO); + } + + @Test + public void testToString() { + BpmnDTO bpmnDTO = BpmnDTO.builder() + .bpmnId(UUID.randomUUID()) + .modelVersion(4L) + .deployedFileName("file4.bpmn") + .definitionKey("key999") + .functionType(FunctionTypeEnum.MENU) + .status(StatusEnum.CREATED) + .sha256("hash999") + .definitionVersionCamunda(5) + .camundaDefinitionId("camunda999") + .description("BPMN Description 4") + .resourceFile(new ResourceFileDTO()) + .resource("Resource Content 4") + .deploymentId(UUID.randomUUID()) + .createdAt(new Timestamp(System.currentTimeMillis())) + .lastUpdatedAt(new Timestamp(System.currentTimeMillis())) + .createdBy("User7") + .lastUpdatedBy("User8") + .build(); + + String expectedToString = "BpmnDTO(bpmnId=" + bpmnDTO.getBpmnId() + + ", modelVersion=4, deployedFileName=file4.bpmn, definitionKey=key999, " + + "functionType=MENU, status=CREATED, sha256=hash999, " + + "definitionVersionCamunda=5, camundaDefinitionId=camunda999, " + + "description=BPMN Description 4, resourceFile=ResourceFileDTO(id=null, resourceType=null, storageKey=null, fileName=null, extension=null, createdAt=null, lastUpdatedAt=null, createdBy=null, lastUpdatedBy=null), " + + "resource=Resource Content 4, deploymentId=" + bpmnDTO.getDeploymentId() + + ", createdAt=" + bpmnDTO.getCreatedAt() + ", lastUpdatedAt=" + bpmnDTO.getLastUpdatedAt() + + ", createdBy=User7, lastUpdatedBy=User8)"; + + assertEquals(expectedToString, bpmnDTO.toString()); + } + + @Test + public void testEqualsAndHashCode() { + BpmnDTO bpmnDTO1 = new BpmnDTO(UUID.randomUUID(), 1L, "file1.bpmn", "key1", + FunctionTypeEnum.MENU, StatusEnum.CREATED, "hash1", 2, + "camunda1", "BPMN Description 1", new ResourceFileDTO(), + "Resource Content 1", UUID.randomUUID(), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), "User1", "User2"); + + BpmnDTO bpmnDTO2 = new BpmnDTO(UUID.randomUUID(), 1L, "file1.bpmn", "key1", + FunctionTypeEnum.MENU, StatusEnum.CREATED, "hash1", 2, + "camunda1", "BPMN Description 1", new ResourceFileDTO(), + "Resource Content 1", UUID.randomUUID(), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), "User1", "User2"); + + assertEquals(bpmnDTO1, bpmnDTO1); + assertNotEquals(bpmnDTO1, bpmnDTO2); + + assertNotEquals(bpmnDTO1, null); + + BpmnDTO bpmnDTO3 = new BpmnDTO(UUID.randomUUID(), 3L, "file3.bpmn", "key3", + FunctionTypeEnum.SPONTANEOUS_PAYMENT, StatusEnum.DEPLOYED, "hash3", 4, + "camunda3", "BPMN Description 3", new ResourceFileDTO(), + "Resource Content 3", UUID.randomUUID(), new Timestamp(System.currentTimeMillis()), + new Timestamp(System.currentTimeMillis()), "User3", "User4"); + + assertNotEquals(bpmnDTO1, bpmnDTO3); + } +} diff --git a/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnIdDtoTest.java b/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnIdDtoTest.java new file mode 100644 index 00000000..a3cf55f8 --- /dev/null +++ b/src/test/java/it/gov/pagopa/atmlayer/service/model/model/BpmnIdDtoTest.java @@ -0,0 +1,47 @@ +package it.gov.pagopa.atmlayer.service.model.model; + +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +public class BpmnIdDtoTest { + + @Test + public void testEqualsAndHashCode() { + BpmnIdDto dto1 = new BpmnIdDto(UUID.randomUUID(), 1L); + BpmnIdDto dto2 = new BpmnIdDto(UUID.randomUUID(), 1L); + + assertEquals(dto1, dto1); + assertNotEquals(dto1, dto2); + assertNotEquals(dto1, null); + + BpmnIdDto dto3 = new BpmnIdDto(UUID.randomUUID(), 2L); + assertNotEquals(dto1, dto3); + } + + @Test + public void testToString() { + UUID uuid = UUID.randomUUID(); + BpmnIdDto dto = new BpmnIdDto(uuid, 1L); + + String expectedToString = "BpmnIdDto(bpmnId=" + uuid + ", modelVersion=1)"; + assertEquals(expectedToString, dto.toString()); + } + + @Test + public void testGetterAndSetter() { + BpmnIdDto dto = new BpmnIdDto(UUID.randomUUID(), 1L); + + UUID newUuid = UUID.randomUUID(); + dto.setBpmnId(newUuid); + assertEquals(newUuid, dto.getBpmnId()); + + Long newModelVersion = 2L; + dto.setModelVersion(newModelVersion); + assertEquals(newModelVersion, dto.getModelVersion()); + } +} +