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();
}
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;
}
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));
}
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;
}
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();
}
Aggregations