Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test rollback #59

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.properties.ObjectStoreProperties;
import it.gov.pagopa.atmlayer.service.model.repository.ResourceFileRepository;

import java.util.UUID;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.UUID;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -270,17 +271,6 @@ void deleteNotDeletableStatus() {
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class);
}
// @Test
// void getAll() {
// WorkflowResource expectedWorkflowResource=new WorkflowResource();
// List<WorkflowResource> expectedList=new ArrayList<>();
// expectedList.add(expectedWorkflowResource);
// when(workflowResourceRepository.findAll()).thenReturn((PanacheQuery)expectedWorkflowResource);
// workflowResourceService.getAll()
// .subscribe().withSubscriber(UniAssertSubscriber.create())
// .assertCompleted()
// .assertItem(expectedList);
// }

@Test
void updateResourceDoesNotExist() throws NoSuchAlgorithmException, IOException {
Expand All @@ -290,4 +280,66 @@ void updateResourceDoesNotExist() throws NoSuchAlgorithmException, IOException {
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class, "The referenced Workflow Resource file does not exist");
}

@Test
void testRollbackOK() throws NoSuchAlgorithmException, IOException {
File expectedFile = new File("src/test/resources/Test.bpmn");
WorkflowResource expectedWorkflowResource=new WorkflowResource();
expectedWorkflowResource.setStatus(StatusEnum.UPDATED_BUT_NOT_DEPLOYED);
expectedWorkflowResource.setCamundaDefinitionId("camundaId");
expectedWorkflowResource.setResourceType(DeployableResourceType.BPMN);
expectedWorkflowResource.setSha256("sha256");
ResourceFile resourceFile=new ResourceFile();
resourceFile.setStorageKey("storageKey");
expectedWorkflowResource.setResourceFile(resourceFile);
expectedWorkflowResource.setDefinitionKey("demo11_06");
when(workflowResourceRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().item(expectedWorkflowResource));
when(processClient.getDeployedResource(any(String.class))).thenReturn(Uni.createFrom().item(expectedFile));
when(workflowResourceRepository.persist(any(WorkflowResource.class))).thenReturn(Uni.createFrom().item(expectedWorkflowResource));
when(workflowResourceStorageService.updateFile(any(WorkflowResource.class),any(File.class))).thenReturn(Uni.createFrom().item(new ResourceFile()));
workflowResourceService.rollback(UUID.randomUUID())
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertCompleted();
}

@Test
void testRollbackResourceDoesNotExist(){
when(workflowResourceRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().nullItem());
workflowResourceService.rollback(UUID.randomUUID())
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class,"The referenced workflow resource does not exist");
}

@Test
void testRollbackResourceDeployed(){
WorkflowResource expectedWorkflowResource=new WorkflowResource();
expectedWorkflowResource.setStatus(StatusEnum.DEPLOYED);
when(workflowResourceRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().item(expectedWorkflowResource));
workflowResourceService.rollback(UUID.randomUUID())
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class,"Cannot rollback: the referenced resource is the latest version deployed");
}

@Test
void testRollbackNeverDeployed(){
WorkflowResource expectedWorkflowResource=new WorkflowResource();
expectedWorkflowResource.setStatus(StatusEnum.UPDATED_BUT_NOT_DEPLOYED);
when(workflowResourceRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().item(expectedWorkflowResource));
workflowResourceService.rollback(UUID.randomUUID())
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class,"CamundaDefinitionId of the referenced resource is null: cannot rollback");
}

@Test
void testRollbackProcessFailure(){
WorkflowResource expectedWorkflowResource=new WorkflowResource();
expectedWorkflowResource.setStatus(StatusEnum.UPDATED_BUT_NOT_DEPLOYED);
expectedWorkflowResource.setCamundaDefinitionId("camundaId");
when(workflowResourceRepository.findById(any(UUID.class))).thenReturn(Uni.createFrom().item(expectedWorkflowResource));
when(processClient.getDeployedResource(any(String.class))).thenReturn(Uni.createFrom().failure(new RuntimeException()));
workflowResourceService.rollback(UUID.randomUUID())
.subscribe().withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class,"Error retrieving workflow resource from Process");
}

}
Loading