use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithConnector.
@ParameterizedTest
@MethodSource("srcHandleWorkDeletingWithKnownResourceWithConnector")
void handleWorkDeletingWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus connectorStatusWhenComplete, boolean isWorkComplete) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = spy(new Processor());
processor.setStatus(status);
ConnectorEntity connector = new ConnectorEntity();
connector.setStatus(ManagedResourceStatus.ACCEPTED);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
when(connectorsDAO.findByProcessorId(processor.getId())).thenReturn(connector);
doAnswer((i) -> {
// Emulate ConnectorWorker completing work
connector.setStatus(connectorStatusWhenComplete);
return connector;
}).when(connectorWorker).handleWork(any(Work.class));
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(connectorStatusWhenComplete);
verify(connectorWorker).handleWork(workArgumentCaptor.capture());
Work connectorWork = workArgumentCaptor.getValue();
assertThat(connectorWork).isNotNull();
assertThat(connectorWork.getId()).isEqualTo(work.getId());
assertThat(connectorWork.getManagedResourceId()).isEqualTo(connector.getId());
assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
verify(workManager, times(isWorkComplete ? 1 : 0)).complete(any(Work.class));
verify(processor, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithoutConnector.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "ACCEPTED", "PROVISIONING" })
void handleWorkProvisioningWithKnownResourceWithoutConnector(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = new Processor();
processor.setStatus(status);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(ManagedResourceStatus.READY);
verify(workManager).complete(work);
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkDeletingWithKnownResourceWithoutConnector.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceWithoutConnector(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
Processor processor = spy(new Processor());
processor.setStatus(status);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(processor);
when(processorDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(processor)).thenReturn(processor);
worker.handleWork(work);
assertThat(processor.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
verify(workManager).complete(work);
verify(processor, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
Aggregations