use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method completeWhenNotExists.
@Test
void completeWhenNotExists() {
when(workDAO.findById(anyString())).thenReturn(null);
manager.complete(new Work());
verify(workDAO, never()).deleteById(anyString());
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class WorkManagerImplTest method recordAttemptIncreasesRetry.
@Test
void recordAttemptIncreasesRetry() {
Work work = new Work();
work.setAttempts(0);
when(workDAO.findById(anyString())).thenReturn(work);
manager.recordAttempt(work);
assertThat(work.getAttempts()).isEqualTo(1);
// A bit of an overkill checking our mocked invocation was called... but it is important
verify(workDAO, atLeastOnce()).findById(work.getId());
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkProvisioningWithUnknownResource.
@Test
void handleWorkProvisioningWithUnknownResource() {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
when(connectorsDAO.findById(RESOURCE_ID)).thenReturn(null);
assertThatCode(() -> worker.handleWork(work)).isInstanceOf(IllegalStateException.class);
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.
@ParameterizedTest
@EnumSource(value = ManagedResourceStatus.class, names = { "DEPROVISION", "DELETING" })
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus status) {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
work.setSubmittedAt(ZonedDateTime.now());
ConnectorEntity connectorEntity = spy(new ConnectorEntity());
connectorEntity.setStatus(status);
connectorEntity.setTopicName("topicName");
connectorEntity.setConnectorExternalId("connectorExternalId");
Connector connector = new Connector();
connector.setStatus(new ConnectorStatusStatus().state(ConnectorState.READY));
when(connectorsDAO.findById(RESOURCE_ID)).thenReturn(connectorEntity);
when(connectorsDAO.getEntityManager()).thenReturn(entityManager);
when(entityManager.merge(connectorEntity)).thenReturn(connectorEntity);
// Managed Connector will initially be available before it is deleted
when(connectorsApi.getConnector(connectorEntity)).thenReturn(connector, null);
worker.handleWork(work);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
// This emulates a subsequent invocation by WorkManager
worker.handleWork(work);
assertThat(connectorEntity.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
assertThat(connectorEntity.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
verify(connectorsDAO).deleteById(connectorEntity.getId());
verify(workManager, never()).complete(work);
verify(connectorEntity, atLeastOnce()).setModifiedAt(any(ZonedDateTime.class));
}
use of com.redhat.service.bridge.manager.models.Work in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorWorkerTest method handleWorkProvisioningWithUnknownResource.
@Test
void handleWorkProvisioningWithUnknownResource() {
Work work = new Work();
work.setManagedResourceId(RESOURCE_ID);
when(processorDAO.findById(RESOURCE_ID)).thenReturn(null);
assertThatCode(() -> worker.handleWork(work)).isInstanceOf(IllegalStateException.class);
}
Aggregations