Search in sources :

Example 11 with Work

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());
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 12 with Work

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());
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test)

Example 13 with Work

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);
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Work

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));
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with Work

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);
}
Also used : Work(com.redhat.service.bridge.manager.models.Work) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Work (com.redhat.service.bridge.manager.models.Work)18 Test (org.junit.jupiter.api.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)5 Processor (com.redhat.service.bridge.manager.models.Processor)5 ZonedDateTime (java.time.ZonedDateTime)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 Connector (com.openshift.cloud.api.connector.models.Connector)2 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Transactional (javax.transaction.Transactional)1