Search in sources :

Example 81 with Bridge

use of com.redhat.service.smartevents.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgesAPITest method testGetBridgesFilterByStatus.

@Test
@TestSecurity(user = DEFAULT_CUSTOMER_ID)
public void testGetBridgesFilterByStatus() {
    Bridge bridge1 = Fixtures.createBridge();
    bridge1.setName(DEFAULT_BRIDGE_NAME + "1");
    bridge1.setStatus(READY);
    bridgeDAO.persist(bridge1);
    Bridge bridge2 = Fixtures.createBridge();
    bridge2.setName(DEFAULT_BRIDGE_NAME + "2");
    bridge2.setStatus(ACCEPTED);
    bridgeDAO.persist(bridge2);
    BridgeListResponse bridgeListResponse = TestUtils.getBridgesFilterByStatus(ACCEPTED).as(BridgeListResponse.class);
    assertThat(bridgeListResponse.getItems().size()).isEqualTo(1);
    BridgeResponse bridgeResponse = bridgeListResponse.getItems().get(0);
    assertThat(bridgeResponse.getName()).isEqualTo(bridge2.getName());
    assertThat(bridgeResponse.getStatus()).isEqualTo(bridge2.getStatus());
    assertThat(bridgeResponse.getHref()).isEqualTo(USER_API_BASE_PATH + bridgeResponse.getId());
    assertThat(bridgeResponse.getSubmittedAt()).isNotNull();
    assertThat(bridgeResponse.getEndpoint()).isNotNull();
}
Also used : BridgeListResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeListResponse) BridgeResponse(com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse) Bridge(com.redhat.service.smartevents.manager.models.Bridge) TestSecurity(io.quarkus.test.security.TestSecurity) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 82 with Bridge

use of com.redhat.service.smartevents.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class AbstractWorkerTest method workIsCompletedWhenResourceIsNotFound.

@Test
@Transactional
void workIsCompletedWhenResourceIsNotFound() {
    Bridge bridge = Fixtures.createBridge();
    // It is intentional that we do not persist the Bridge here
    Work work = workManager.schedule(bridge);
    assertThat(workManager.exists(work)).isTrue();
    assertThatThrownBy(() -> worker.handleWork(work)).isInstanceOf(IllegalStateException.class);
}
Also used : Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Transactional(javax.transaction.Transactional)

Example 83 with Bridge

use of com.redhat.service.smartevents.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeWorkerTest method testDeletionWorkWithKnownResource.

@Transactional
@ParameterizedTest
@MethodSource("deletionWorkWithKnownResourceParams")
void testDeletionWorkWithKnownResource(ManagedResourceStatus status, ManagedResourceStatus dependencyStatusWhenComplete, boolean throwRhoasError, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    bridge.setStatus(status);
    bridgeDAO.persist(bridge);
    Work work = workManager.schedule(bridge);
    when(processorServiceMock.getHiddenProcessors(any(), any())).thenReturn(new ListResult<>(Collections.emptyList(), 0, 0));
    if (throwRhoasError) {
        doThrow(new InternalPlatformException("error")).when(rhoasServiceMock).deleteTopicAndRevokeAccessFor(eq(TEST_TOPIC_NAME), any());
    }
    Bridge refreshed = worker.handleWork(work);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
    verify(rhoasServiceMock).deleteTopicAndRevokeAccessFor(TEST_TOPIC_NAME, RhoasTopicAccessType.CONSUMER_AND_PRODUCER);
}
Also used : InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Example 84 with Bridge

use of com.redhat.service.smartevents.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorWorkerTest method handleWorkProvisioningWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForCreateTest")
void handleWorkProvisioningWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType, ManagedResourceStatus expectedResourceStatus) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    ConnectorEntity connectorEntity = useSourceConnectorEntity ? Fixtures.createSourceConnector(processor, resourceStatus) : Fixtures.createSinkConnector(processor, resourceStatus);
    // The publishedAt date is set by the Worker so reset that set by the Fixture
    connectorEntity.setPublishedAt(null);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(connectorEntity);
    Connector connector = new Connector();
    connector.setId(TEST_CONNECTOR_EXTERNAL_ID);
    connector.setStatus(new ConnectorStatusStatus().state(connectorState));
    when(connectorsApi.getConnector(TEST_CONNECTOR_EXTERNAL_ID)).thenReturn(null, connector);
    when(connectorsApi.createConnector(connectorEntity)).thenReturn(connector);
    ConnectorEntity refreshed = worker.handleWork(work);
    verify(rhoasService).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.PREPARING);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.PROVISIONING);
    // This emulates a subsequent invocation by WorkManager
    refreshed = worker.handleWork(work);
    verify(rhoasService, times(2)).createTopicAndGrantAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    verify(connectorsApi, atMostOnce()).createConnector(connectorEntity);
    assertThat(refreshed.getStatus()).isEqualTo(expectedResourceStatus);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(expectedResourceStatus);
    if (expectedResourceStatus == ManagedResourceStatus.READY) {
        assertThat(refreshed.getPublishedAt()).isNotNull();
    } else {
        assertThat(refreshed.getPublishedAt()).isNull();
    }
    assertThat(workManager.exists(work)).isTrue();
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ConnectorStatusStatus(com.openshift.cloud.api.connector.models.ConnectorStatusStatus) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Example 85 with Bridge

use of com.redhat.service.smartevents.manager.models.Bridge in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorWorkerTest method handleWorkProvisioningWithKnownResourceWithConnector.

@Transactional
@ParameterizedTest
@MethodSource("srcHandleWorkProvisioningWithKnownResourceWithConnector")
void handleWorkProvisioningWithKnownResourceWithConnector(ManagedResourceStatus status, ManagedResourceStatus statusWhenComplete, ManagedResourceStatus dependencyStatusWhenComplete, boolean isWorkComplete) {
    Bridge bridge = Fixtures.createBridge();
    Processor processor = Fixtures.createProcessor(bridge, ManagedResourceStatus.READY);
    processor.setStatus(status);
    ConnectorEntity connectorEntity = Fixtures.createSinkConnector(processor, ManagedResourceStatus.ACCEPTED);
    connectorEntity.setStatus(ManagedResourceStatus.ACCEPTED);
    bridgeDAO.persist(bridge);
    processorDAO.persist(processor);
    connectorsDAO.persist(connectorEntity);
    Work work = workManager.schedule(processor);
    doAnswer((i) -> {
        // Emulate ConnectorWorker completing work
        connectorEntity.setStatus(dependencyStatusWhenComplete);
        return connectorEntity;
    }).when(connectorWorker).handleWork(any(Work.class));
    Processor refreshed = worker.handleWork(work);
    assertThat(refreshed.getStatus()).isEqualTo(statusWhenComplete);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(dependencyStatusWhenComplete);
    ArgumentCaptor<Work> workArgumentCaptor = ArgumentCaptor.forClass(Work.class);
    verify(connectorWorker).handleWork(workArgumentCaptor.capture());
    Work connectorWork = workArgumentCaptor.getValue();
    assertThat(connectorWork).isNotNull();
    assertThat(connectorWork.getId()).isEqualTo(work.getId());
    assertThat(connectorWork.getManagedResourceId()).isEqualTo(connectorEntity.getId());
    assertThat(connectorWork.getSubmittedAt()).isEqualTo(work.getSubmittedAt());
    assertThat(workManager.exists(work)).isNotEqualTo(isWorkComplete);
}
Also used : Processor(com.redhat.service.smartevents.manager.models.Processor) ConnectorEntity(com.redhat.service.smartevents.manager.models.ConnectorEntity) Work(com.redhat.service.smartevents.manager.models.Work) Bridge(com.redhat.service.smartevents.manager.models.Bridge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Transactional(javax.transaction.Transactional)

Aggregations

Bridge (com.redhat.service.smartevents.manager.models.Bridge)99 QuarkusTest (io.quarkus.test.junit.QuarkusTest)68 Test (org.junit.jupiter.api.Test)68 Processor (com.redhat.service.smartevents.manager.models.Processor)45 Transactional (javax.transaction.Transactional)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 TestSecurity (io.quarkus.test.security.TestSecurity)14 BridgeResponse (com.redhat.service.smartevents.manager.api.models.responses.BridgeResponse)13 Work (com.redhat.service.smartevents.manager.models.Work)13 QueryProcessorResourceInfo (com.redhat.service.smartevents.infra.models.QueryProcessorResourceInfo)12 QueryResourceInfo (com.redhat.service.smartevents.infra.models.QueryResourceInfo)11 ProcessorRequest (com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest)11 ProcessorResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorResponse)10 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)9 BridgeRequest (com.redhat.service.smartevents.manager.api.models.requests.BridgeRequest)8 ProcessorListResponse (com.redhat.service.smartevents.manager.api.models.responses.ProcessorListResponse)8 Response (io.restassured.response.Response)8 Connector (com.openshift.cloud.api.connector.models.Connector)7 Action (com.redhat.service.smartevents.infra.models.gateways.Action)7 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)7