Search in sources :

Example 16 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorWorkerTest method handleWorkDeletingWithKnownResourceMultiplePasses.

@Transactional
@ParameterizedTest
@MethodSource("provideArgsForDeleteTest")
void handleWorkDeletingWithKnownResourceMultiplePasses(ManagedResourceStatus resourceStatus, ConnectorState connectorState, boolean useSourceConnectorEntity, RhoasTopicAccessType expectedTopicAccessType) {
    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.setStatus(new ConnectorStatusStatus().state(connectorState));
    // Managed Connector will initially be available before it is deleted
    when(connectorsApi.getConnector(connectorEntity.getConnectorExternalId())).thenReturn(connector, (Connector) null);
    ConnectorEntity refreshed = worker.handleWork(work);
    if (connectorState != ConnectorState.DELETED) {
        assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETING);
        verify(rhoasService, never()).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), RhoasTopicAccessType.PRODUCER);
        verify(connectorsApi).deleteConnector(connectorEntity.getConnectorExternalId());
        // This emulates a subsequent invocation by WorkManager
        refreshed = worker.handleWork(work);
    }
    verify(rhoasService).deleteTopicAndRevokeAccessFor(connectorEntity.getTopicName(), expectedTopicAccessType);
    assertThat(connectorsDAO.findById(connectorEntity.getId())).isNull();
    assertThat(refreshed.getStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    assertThat(refreshed.getDependencyStatus()).isEqualTo(ManagedResourceStatus.DELETED);
    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 17 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ConnectorsApiClientTest method testConnector.

private Connector testConnector() {
    Connector connector = new Connector();
    connector.setId(TEST_CONNECTOR_EXTERNAL_ID);
    return connector;
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector)

Example 18 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method createConnectorFailureOnKafkaTopicCreation.

@Test
void createConnectorFailureOnKafkaTopicCreation() {
    Bridge b = createPersistBridge(READY);
    Action slackAction = createSlackAction();
    ProcessorRequest processorRequest = new ProcessorRequest("ManagedConnectorProcessor", slackAction);
    when(rhoasService.createTopicAndGrantAccessFor(anyString(), any())).thenThrow(new InternalPlatformException(RhoasServiceImpl.createFailureErrorMessageFor("errorTopic"), new RuntimeException("error")));
    when(connectorsApiClient.createConnector(any(ConnectorRequest.class))).thenReturn(new Connector());
    Processor processor = processorService.createProcessor(b.getId(), b.getCustomerId(), b.getOwner(), processorRequest);
    waitForProcessorAndConnectorToFail(processor);
    verify(rhoasService, atLeast(1)).createTopicAndGrantAccessFor(anyString(), eq(RhoasTopicAccessType.PRODUCER));
    verify(connectorsApiClient, never()).createConnector(any(ConnectorRequest.class));
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector) Action(com.redhat.service.smartevents.infra.models.gateways.Action) SlackAction(com.redhat.service.smartevents.processor.actions.slack.SlackAction) ConnectorRequest(com.openshift.cloud.api.connector.models.ConnectorRequest) Processor(com.redhat.service.smartevents.manager.models.Processor) InternalPlatformException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException) ProcessorRequest(com.redhat.service.smartevents.manager.api.models.requests.ProcessorRequest) Bridge(com.redhat.service.smartevents.manager.models.Bridge) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 19 with Connector

use of com.openshift.cloud.api.connector.models.Connector in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorServiceConnectorTest method stubbedExternalConnector.

private Connector stubbedExternalConnector(String connectorExternalId) {
    Connector connector = new Connector();
    connector.setId(connectorExternalId);
    return connector;
}
Also used : Connector(com.openshift.cloud.api.connector.models.Connector)

Example 20 with Connector

use of com.openshift.cloud.api.connector.models.Connector 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)

Aggregations

Connector (com.openshift.cloud.api.connector.models.Connector)29 ConnectorStatusStatus (com.openshift.cloud.api.connector.models.ConnectorStatusStatus)16 QuarkusTest (io.quarkus.test.junit.QuarkusTest)12 Test (org.junit.jupiter.api.Test)12 Bridge (com.redhat.service.smartevents.manager.models.Bridge)7 Processor (com.redhat.service.smartevents.manager.models.Processor)7 ConnectorRequest (com.openshift.cloud.api.connector.models.ConnectorRequest)6 ConnectorEntity (com.redhat.service.bridge.manager.models.ConnectorEntity)6 Bridge (com.redhat.service.bridge.manager.models.Bridge)5 Processor (com.redhat.service.bridge.manager.models.Processor)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InternalPlatformException (com.redhat.service.bridge.infra.exceptions.definitions.platform.InternalPlatformException)3 SlackConnector (com.redhat.service.dto.request.SlackConnector)3 InternalPlatformException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.InternalPlatformException)3 ConnectorEntity (com.redhat.service.smartevents.manager.models.ConnectorEntity)3 ConnectorsApi (com.openshift.cloud.api.connector.ConnectorsApi)2 Topic (com.openshift.cloud.api.kas.auth.models.Topic)2 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)2 ProcessorRequest (com.redhat.service.bridge.manager.api.models.requests.ProcessorRequest)2 Work (com.redhat.service.bridge.manager.models.Work)2