Search in sources :

Example 16 with Work

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));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) ConnectorEntity(com.redhat.service.bridge.manager.models.ConnectorEntity) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with Work

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

Example 18 with 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));
}
Also used : Processor(com.redhat.service.bridge.manager.models.Processor) ZonedDateTime(java.time.ZonedDateTime) Work(com.redhat.service.bridge.manager.models.Work) EnumSource(org.junit.jupiter.params.provider.EnumSource) 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