Skip to content

Commit

Permalink
Merge update_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanueleValentini1 committed Nov 14, 2023
1 parent 324dcb2 commit 6fcc49c
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 97 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;

import java.nio.file.Paths;
import org.junit.jupiter.api.Test;

Expand All @@ -20,10 +20,10 @@ void testConstructor() {
actualBpmnCreationDto.setFile(
Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile());
actualBpmnCreationDto.setFilename("foo.txt");
actualBpmnCreationDto.setFunctionType(FunctionTypeEnum.MENU.name());
actualBpmnCreationDto.setFunctionType("MENU");
String actualToStringResult = actualBpmnCreationDto.toString();
assertEquals("foo.txt", actualBpmnCreationDto.getFilename());
assertEquals(FunctionTypeEnum.MENU.name(), actualBpmnCreationDto.getFunctionType());
assertEquals("MENU", actualBpmnCreationDto.getFunctionType());
assertEquals(
String.join("", "BpmnCreationDto(file=",
Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toString(),
Expand All @@ -36,7 +36,7 @@ void testEquals() {
BpmnCreationDto bpmnCreationDto = new BpmnCreationDto();
bpmnCreationDto.setFile(Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile());
bpmnCreationDto.setFilename("foo.txt");
bpmnCreationDto.setFunctionType(FunctionTypeEnum.MENU.name());
bpmnCreationDto.setFunctionType("MENU");
assertNotEquals(bpmnCreationDto, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;

import java.nio.file.Paths;
import java.util.UUID;

Expand All @@ -26,12 +24,12 @@ void testConstructor() {
actualBpmnUpgradeDto.setFile(
Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile());
actualBpmnUpgradeDto.setFilename("foo.txt");
actualBpmnUpgradeDto.setFunctionType(FunctionTypeEnum.MENU.name());
actualBpmnUpgradeDto.setFunctionType("MENU");
UUID randomUUIDResult = UUID.randomUUID();
actualBpmnUpgradeDto.setUuid(randomUUIDResult);
actualBpmnUpgradeDto.toString();
assertEquals("foo.txt", actualBpmnUpgradeDto.getFilename());
assertEquals(FunctionTypeEnum.MENU.name(), actualBpmnUpgradeDto.getFunctionType());
assertEquals("MENU", actualBpmnUpgradeDto.getFunctionType());
assertSame(randomUUIDResult, actualBpmnUpgradeDto.getUuid());
}

Expand All @@ -40,7 +38,7 @@ void testEquals() {
BpmnUpgradeDto bpmnUpgradeDto = new BpmnUpgradeDto();
bpmnUpgradeDto.setFile(Paths.get(System.getProperty("java.io.tmpdir"), "test.txt").toFile());
bpmnUpgradeDto.setFilename("foo.txt");
bpmnUpgradeDto.setFunctionType(FunctionTypeEnum.MENU.name());
bpmnUpgradeDto.setFunctionType("MENU");
bpmnUpgradeDto.setUuid(UUID.randomUUID());
assertNotEquals(bpmnUpgradeDto, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.gov.pagopa.atmlayer.service.model.entity;

import io.quarkus.test.junit.QuarkusTest;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -26,9 +25,9 @@ public void testGettersAndSetters() {
bpmnBankConfig.setBpmnBankConfigPK(bpmnBankConfigPK);
assertEquals(bpmnBankConfigPK, bpmnBankConfig.getBpmnBankConfigPK());

FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
bpmnBankConfig.setFunctionType(functionType.name());
assertEquals(functionType.name(), bpmnBankConfig.getFunctionType());
String functionType = "MENU";
bpmnBankConfig.setFunctionType(functionType);
assertEquals(functionType, bpmnBankConfig.getFunctionType());

Timestamp createdAt = new Timestamp(System.currentTimeMillis());
bpmnBankConfig.setCreatedAt(createdAt);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
import java.util.UUID;
Expand All @@ -21,7 +20,7 @@ public void testNoArgsConstructor() {
public void testAllArgsConstructor() {
BpmnBankConfigDTO dto = new BpmnBankConfigDTO(
UUID.randomUUID(), 1L, "acquirer", "branch", "terminal",
FunctionTypeEnum.MENU.name(), new Timestamp(System.currentTimeMillis()),
"MENU", new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()), "creator", "updator");
assertNotNull(dto);
}
Expand All @@ -45,8 +44,8 @@ public void testGetterAndSetter() {
dto.setTerminalId("terminal");
assertEquals(dto.getTerminalId(), "terminal");

dto.setFunctionType(FunctionTypeEnum.MENU.name());
assertEquals(dto.getFunctionType(), FunctionTypeEnum.MENU.name());
dto.setFunctionType("MENU");
assertEquals(dto.getFunctionType(), "MENU");

Timestamp createdAt = new Timestamp(System.currentTimeMillis());
dto.setCreatedAt(createdAt);
Expand All @@ -67,11 +66,11 @@ public void testGetterAndSetter() {
public void testEqualsAndHashCode() {
BpmnBankConfigDTO dto1 = new BpmnBankConfigDTO(
UUID.randomUUID(), 1L, "acquirer", "branch", "terminal",
FunctionTypeEnum.MENU.name(), new Timestamp(System.currentTimeMillis()),
"MENU", new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()), "creator", "updator");
BpmnBankConfigDTO dto2 = new BpmnBankConfigDTO(
UUID.randomUUID(), 1L, "acquirer", "branch", "terminal",
FunctionTypeEnum.MENU.name(), new Timestamp(System.currentTimeMillis()),
"MENU", new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()), "creator", "updator");

assertNotEquals(dto1, dto2);
Expand All @@ -82,7 +81,7 @@ public void testEqualsAndHashCode() {
public void testToString() {
BpmnBankConfigDTO dto = new BpmnBankConfigDTO(
UUID.randomUUID(), 1L, "acquirer", "branch", "terminal",
FunctionTypeEnum.MENU.name(), new Timestamp(System.currentTimeMillis()),
"MENU", new Timestamp(System.currentTimeMillis()),
new Timestamp(System.currentTimeMillis()), "creator", "updator");

String expectedToString = "BpmnBankConfigDTO(bpmnId=" + dto.getBpmnId() +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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;
Expand All @@ -22,7 +21,7 @@ public void testGetterAndSetter() {
bpmnDTO.setModelVersion(1L);
bpmnDTO.setDeployedFileName("example.bpmn");
bpmnDTO.setDefinitionKey("process_key");
bpmnDTO.setFunctionType(FunctionTypeEnum.MENU.name());
bpmnDTO.setFunctionType("MENU");
bpmnDTO.setStatus(StatusEnum.CREATED);
bpmnDTO.setSha256("hash123");
bpmnDTO.setDefinitionVersionCamunda(2);
Expand All @@ -41,7 +40,7 @@ public void testGetterAndSetter() {
assertEquals(bpmnDTO.getModelVersion(), 1L);
assertEquals(bpmnDTO.getDeployedFileName(), "example.bpmn");
assertEquals(bpmnDTO.getDefinitionKey(), "process_key");
assertEquals(bpmnDTO.getFunctionType(), FunctionTypeEnum.MENU.name());
assertEquals(bpmnDTO.getFunctionType(), "MENU");
assertEquals(bpmnDTO.getStatus(), StatusEnum.CREATED);
assertEquals(bpmnDTO.getSha256(), "hash123");
assertEquals(bpmnDTO.getDefinitionVersionCamunda(), 2);
Expand All @@ -67,7 +66,7 @@ public void testAllArgsConstructor() {
UUID bpmnId = UUID.randomUUID();
Long modelVersion = 2L;
BpmnDTO bpmnDTO = new BpmnDTO(bpmnId, modelVersion, "file.bpmn", "key123",
FunctionTypeEnum.SPONTANEOUS_PAYMENT.name(), StatusEnum.DEPLOYED, "hash456", 3,
"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");
Expand All @@ -83,7 +82,7 @@ public void testBuilder() {
.modelVersion(3L)
.deployedFileName("file3.bpmn")
.definitionKey("key789")
.functionType(FunctionTypeEnum.SPONTANEOUS_PAYMENT.name())
.functionType("SPONTANEOUS_PAYMENT")
.status(StatusEnum.CREATED)
.sha256("hash789")
.definitionVersionCamunda(4)
Expand All @@ -108,7 +107,7 @@ public void testToString() {
.modelVersion(4L)
.deployedFileName("file4.bpmn")
.definitionKey("key999")
.functionType(FunctionTypeEnum.MENU.name())
.functionType("SPONTANEOUS_PAYMENT")
.status(StatusEnum.CREATED)
.sha256("hash999")
.definitionVersionCamunda(5)
Expand All @@ -125,7 +124,7 @@ public void testToString() {

String expectedToString = "BpmnDTO(bpmnId=" + bpmnDTO.getBpmnId() +
", modelVersion=4, deployedFileName=file4.bpmn, definitionKey=key999, " +
"functionType=MENU, status=CREATED, sha256=hash999, " +
"functionType=SPONTANEOUS_PAYMENT, 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() +
Expand All @@ -138,13 +137,13 @@ public void testToString() {
@Test
public void testEqualsAndHashCode() {
BpmnDTO bpmnDTO1 = new BpmnDTO(UUID.randomUUID(), 1L, "file1.bpmn", "key1",
FunctionTypeEnum.MENU.name(), StatusEnum.CREATED, "hash1", 2,
"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.name(), StatusEnum.CREATED, "hash1", 2,
"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");
Expand All @@ -155,7 +154,7 @@ public void testEqualsAndHashCode() {
assertNotEquals(bpmnDTO1, null);

BpmnDTO bpmnDTO3 = new BpmnDTO(UUID.randomUUID(), 3L, "file3.bpmn", "key3",
FunctionTypeEnum.SPONTANEOUS_PAYMENT.name(), StatusEnum.DEPLOYED, "hash3", 4,
"MENU", 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersionPK;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.mapper.BpmnConfigMapperImpl;
import it.gov.pagopa.atmlayer.service.model.mapper.BpmnVersionMapper;
import it.gov.pagopa.atmlayer.service.model.model.BpmnBankConfigDTO;
Expand Down Expand Up @@ -140,13 +139,13 @@ void testAssociateBPMNOK() {
BpmnBankConfigDTO bpmnBankConfigDTO = new BpmnBankConfigDTO();
dtoList.add(bpmnBankConfigDTO);
String acquirerId = "testAcq";
FunctionTypeEnum functionTypeEnum = FunctionTypeEnum.MENU;
String functionType = "MENU";
when(bpmnEntityValidator.validateExistenceStatusAndFunctionType(any(), any())).thenReturn(Uni.createFrom().nullItem());
when(bpmnVersionService.putAssociations(any(), any(), any())).thenReturn(Uni.createFrom().item(bankConfigList));
when(bpmnConfigMapper.toDTOList(bankConfigList)).thenReturn(dtoList);
given()
.pathParam("acquirerId", acquirerId)
.pathParam("functionType", functionTypeEnum)
.pathParam("functionType", functionType)
.contentType(MediaType.APPLICATION_JSON)
.body(bpmnAssociationDto)
.when().put("api/v1/model/bpmn/bank/{acquirerId}/associations/function/{functionType}")
Expand All @@ -165,7 +164,7 @@ void createBPMNOK() throws NoSuchAlgorithmException, IOException {
.contentType(MediaType.MULTIPART_FORM_DATA)
.multiPart("file", new File("src/test/resources/TestMalformed.bpmn"))
.formParam("filename", "testFileName")
.formParam("functionType", FunctionTypeEnum.MENU)
.formParam("functionType", "MENU")
.when().post("/api/v1/model/bpmn")
.then()
.statusCode(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.smallrye.mutiny.Uni;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfig;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnBankConfigPK;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.repository.BpmnBankConfigRepository;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -53,14 +52,14 @@ public void testSaveList() {
@Test
public void testFindByAcquirerIdAndFunctionType() {
String acquirerId = "acquirer1";
FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
String functionType = "MENU";

List<BpmnBankConfig> mockResult = Collections.singletonList(new BpmnBankConfig());

when(bankConfigRepository.findByAcquirerIdAndFunctionType(acquirerId, functionType.name()))
when(bankConfigRepository.findByAcquirerIdAndFunctionType(acquirerId, functionType))
.thenReturn(Uni.createFrom().item(mockResult));

Uni<List<BpmnBankConfig>> result = bankConfigService.findByAcquirerIdAndFunctionType(acquirerId, functionType.name());
Uni<List<BpmnBankConfig>> result = bankConfigService.findByAcquirerIdAndFunctionType(acquirerId, functionType);

assertNotNull(result);

Expand All @@ -71,12 +70,12 @@ public void testFindByAcquirerIdAndFunctionType() {
@Test
public void testDeleteByAcquirerIdAndFunctionType() {
String acquirerId = "acquirer1";
FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
String functionType = "MENU";

when(bankConfigRepository.deleteByAcquirerIdAndFunctionType(acquirerId, functionType.name()))
when(bankConfigRepository.deleteByAcquirerIdAndFunctionType(acquirerId, functionType))
.thenReturn(Uni.createFrom().item(1L));

Uni<Long> result = bankConfigService.deleteByAcquirerIdAndFunctionType(acquirerId, functionType.name());
Uni<Long> result = bankConfigService.deleteByAcquirerIdAndFunctionType(acquirerId, functionType);

assertNotNull(result);

Expand All @@ -89,22 +88,22 @@ public void testFindByConfigurationsAndFunction() {
String acquirerId = "acquirer1";
String branchId = "branch1";
String terminalId = "terminal1";
FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
String functionType = "MENU";

BpmnBankConfig bpmnBankConfig = new BpmnBankConfig();
BpmnBankConfigPK bpmnBankConfigPK = new BpmnBankConfigPK();
bpmnBankConfigPK.setAcquirerId(acquirerId);
bpmnBankConfigPK.setBranchId(branchId);
bpmnBankConfigPK.setTerminalId(terminalId);
bpmnBankConfig.setBpmnBankConfigPK(bpmnBankConfigPK);
bpmnBankConfig.setFunctionType(functionType.name());
bpmnBankConfig.setFunctionType(functionType);

List<BpmnBankConfig> mockResult = Collections.singletonList(bpmnBankConfig);

when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType.name()))
when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType))
.thenReturn(Uni.createFrom().item(mockResult));

Uni<Optional<BpmnBankConfig>> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType.name());
Uni<Optional<BpmnBankConfig>> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType);

assertNotNull(result);

Expand All @@ -115,20 +114,20 @@ public void testFindByConfigurationsAndFunction() {
assertEquals(acquirerId, retrievedConfig.getBpmnBankConfigPK().getAcquirerId());
assertEquals(branchId, retrievedConfig.getBpmnBankConfigPK().getBranchId());
assertEquals(terminalId, retrievedConfig.getBpmnBankConfigPK().getTerminalId());
assertEquals(functionType.name(), retrievedConfig.getFunctionType());
assertEquals(functionType, retrievedConfig.getFunctionType());
}

@Test
public void testFindByConfigurationsAndFunctionWithEmptyList() {
String acquirerId = "acquirer1";
String branchId = "branch1";
String terminalId = "terminal1";
FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
String functionType = "MENU";

when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType.name()))
when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType))
.thenReturn(Uni.createFrom().item(Collections.emptyList()));

Uni<Optional<BpmnBankConfig>> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType.name());
Uni<Optional<BpmnBankConfig>> result = bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType);

assertNotNull(result);

Expand All @@ -141,18 +140,18 @@ public void testFindByConfigurationsAndFunctionWithMultipleResults() {
String acquirerId = "acquirer1";
String branchId = "branch1";
String terminalId = "terminal1";
FunctionTypeEnum functionType = FunctionTypeEnum.MENU;
String functionType = "MENU";

BpmnBankConfig config1 = new BpmnBankConfig();
BpmnBankConfig config2 = new BpmnBankConfig();
List<BpmnBankConfig> mockResult = List.of(config1, config2);

when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType.name()))
when(bankConfigRepository.findByConfigAndFunctionType(acquirerId, branchId, terminalId, functionType))
.thenReturn(Uni.createFrom().item(mockResult));

// Modifica il test per catturare l'eccezione AtmLayerException
assertThrows(AtmLayerException.class, () -> {
bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType.name())
bankConfigService.findByConfigurationsAndFunction(acquirerId, branchId, terminalId, functionType)
.await().indefinitely();
}, "Multiple BPMN found for a single configuration.");
}
Expand Down
Loading

0 comments on commit 6fcc49c

Please sign in to comment.