Search in sources :

Example 1 with IntegrationDeploymentHandler

use of io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler in project syndesis by syndesisio.

the class PublicApiHandlerTest method testPublishIntegration.

@Test
public void testPublishIntegration() {
    final DataManager dataManager = mock(DataManager.class);
    final Integration integration = new Integration.Builder().id("integration-id").build();
    final SecurityContext securityContext = newMockSecurityContext();
    when(dataManager.fetch(Integration.class, "integration-id")).thenReturn(integration);
    final IntegrationDeploymentHandler deploymentHandler = mock(IntegrationDeploymentHandler.class);
    when(deploymentHandler.update(securityContext, "integration-id")).thenReturn(new IntegrationDeployment.Builder().spec(integration).targetState(IntegrationDeploymentState.Published).build());
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(dataManager, null, deploymentHandler, null, null, new EnvironmentHandler(dataManager), null, null);
    final IntegrationDeployment deployment = handler.publishIntegration(securityContext, "integration-id");
    assertThat(deployment.getTargetState()).isEqualTo(IntegrationDeploymentState.Published);
}
Also used : Integration(io.syndesis.common.model.integration.Integration) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) SecurityContext(javax.ws.rs.core.SecurityContext) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) DataManager(io.syndesis.server.dao.manager.DataManager) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) Test(org.junit.Test)

Example 2 with IntegrationDeploymentHandler

use of io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler in project syndesis by syndesisio.

the class PublicApiHandlerTest method testStopIntegration.

@Test
public void testStopIntegration() {
    final DataManager dataManager = mock(DataManager.class);
    final Integration integration = new Integration.Builder().id("integration-id").build();
    final SecurityContext securityContext = newMockSecurityContext();
    when(dataManager.fetch(Integration.class, "integration-id")).thenReturn(integration);
    when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", "integration-id")).thenReturn(Stream.of(new IntegrationDeployment.Builder().targetState(IntegrationDeploymentState.Published).version(2).spec(integration).build()));
    final IntegrationDeploymentHandler deploymentHandler = mock(IntegrationDeploymentHandler.class);
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(dataManager, null, deploymentHandler, null, null, new EnvironmentHandler(dataManager), null, null);
    handler.stopIntegration(securityContext, "integration-id");
    verify(deploymentHandler).updateTargetState("integration-id", 2, new TargetStateRequest(IntegrationDeploymentState.Unpublished));
}
Also used : Integration(io.syndesis.common.model.integration.Integration) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) SecurityContext(javax.ws.rs.core.SecurityContext) DataManager(io.syndesis.server.dao.manager.DataManager) TargetStateRequest(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler.TargetStateRequest) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) Test(org.junit.Test)

Example 3 with IntegrationDeploymentHandler

use of io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler in project syndesis by syndesisio.

the class PublicApiHandlerTest method importResources.

@Test
public void importResources() {
    final DataManager dataManager = mock(DataManager.class);
    final SecurityContext securityContext = newMockSecurityContext();
    final InputStream givenDataStream = new ByteArrayInputStream(new byte[0]);
    // too convoluted to use the implementation directly
    final IntegrationSupportHandler supportHandler = mock(IntegrationSupportHandler.class);
    final Connection testConnection = new Connection.Builder().id("connection-id").connectorId("connector-id").name("test-connection").build();
    final Integration integration = new Integration.Builder().id("integration-id").addConnection(testConnection).build();
    Map<String, List<WithResourceId>> resultMap = new HashMap<>();
    resultMap.put("integration-id", Collections.singletonList(integration));
    resultMap.put("connection-id", Collections.singletonList(testConnection));
    when(supportHandler.importIntegration(securityContext, givenDataStream)).thenReturn(resultMap);
    final Environment env = newEnvironment("env");
    when(dataManager.fetchByPropertyValue(Environment.class, "name", "env")).thenReturn(Optional.of(env));
    when(dataManager.fetch(Connector.class, "connector-id")).thenReturn(new Connector.Builder().putProperty("prop", new ConfigurationProperty.Builder().build()).build());
    when(dataManager.fetchAll(eq(Integration.class), any())).then((Answer<ListResult<Integration>>) invocation -> {
        final Object[] arguments = invocation.getArguments();
        ListResult<Integration> result = new ListResult.Builder<Integration>().addItem(integration).build();
        for (int i = 1; i < arguments.length; i++) {
            @SuppressWarnings("unchecked") Function<ListResult<Integration>, ListResult<Integration>> operator = (Function<ListResult<Integration>, ListResult<Integration>>) arguments[i];
            result = operator.apply(result);
        }
        return result;
    });
    final EnvironmentHandler environmentHandler = new EnvironmentHandler(dataManager);
    final IntegrationDeploymentHandler deploymentHandler = mock(IntegrationDeploymentHandler.class);
    final EncryptionComponent encryptionComponent = mock(EncryptionComponent.class);
    when(encryptionComponent.encryptPropertyValues(any(), any())).thenReturn(Collections.singletonMap("prop", "value"));
    IntegrationHandler integrationHandler = mock(IntegrationHandler.class);
    when(integrationHandler.getOverview(any())).thenReturn(new IntegrationOverview.Builder().createFrom(integration).connections(Collections.singletonList(testConnection.builder().putConfiguredProperty("prop", "value").build())).build());
    // null's are not used
    final PublicApiHandler handler = new PublicApiHandler(dataManager, encryptionComponent, deploymentHandler, null, null, environmentHandler, supportHandler, integrationHandler);
    final PublicApiHandler.ImportFormDataInput formInput = new PublicApiHandler.ImportFormDataInput();
    formInput.setData(givenDataStream);
    formInput.setProperties(new ByteArrayInputStream("test-connection.prop=value".getBytes(StandardCharsets.UTF_8)));
    formInput.setRefreshIntegrations(Boolean.TRUE);
    formInput.setEnvironment("env");
    formInput.setDeploy(Boolean.TRUE);
    final ContinuousDeliveryImportResults importResults = handler.importResources(securityContext, formInput);
    verify(deploymentHandler).update(securityContext, "integration-id");
    assertThat(importResults.getLastImportedAt()).isNotNull();
    assertThat(importResults.getResults().size()).isEqualTo(2);
    // verify the integration connection was refreshed
    final Integration importedIntegration = (Integration) importResults.getResults().get(0);
    assertThat(importedIntegration.getConnections().get(0).getConfiguredProperties().get("prop")).isEqualTo("value");
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityContext(javax.ws.rs.core.SecurityContext) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) WithResourceId(io.syndesis.common.model.WithResourceId) ClientErrorException(javax.ws.rs.ClientErrorException) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Integration(io.syndesis.common.model.integration.Integration) Connector(io.syndesis.common.model.connection.Connector) StreamingOutput(javax.ws.rs.core.StreamingOutput) ListResult(io.syndesis.common.model.ListResult) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) IntegrationSupportHandler(io.syndesis.server.endpoint.v1.handler.integration.support.IntegrationSupportHandler) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ContinuousDeliveryImportResults(io.syndesis.common.model.integration.ContinuousDeliveryImportResults) HashMap(java.util.HashMap) Function(java.util.function.Function) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DataManager(io.syndesis.server.dao.manager.DataManager) Status(javax.ws.rs.core.Response.Status) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Assertions.entry(org.assertj.core.api.Assertions.entry) Mockito.verify(org.mockito.Mockito.verify) WithName(io.syndesis.common.model.WithName) TargetStateRequest(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler.TargetStateRequest) MonitoringProvider(io.syndesis.server.endpoint.monitoring.MonitoringProvider) IntegrationDeploymentStateDetails(io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails) Condition(org.assertj.core.api.Condition) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) Collections(java.util.Collections) InputStream(java.io.InputStream) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) Function(java.util.function.Function) EnvironmentHandler(io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler) ContinuousDeliveryImportResults(io.syndesis.common.model.integration.ContinuousDeliveryImportResults) List(java.util.List) IntegrationSupportHandler(io.syndesis.server.endpoint.v1.handler.integration.support.IntegrationSupportHandler) IntegrationDeploymentHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler) IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) Integration(io.syndesis.common.model.integration.Integration) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) ListResult(io.syndesis.common.model.ListResult) ByteArrayInputStream(java.io.ByteArrayInputStream) SecurityContext(javax.ws.rs.core.SecurityContext) ContinuousDeliveryEnvironment(io.syndesis.common.model.integration.ContinuousDeliveryEnvironment) Environment(io.syndesis.common.model.environment.Environment) Test(org.junit.Test)

Aggregations

Integration (io.syndesis.common.model.integration.Integration)3 DataManager (io.syndesis.server.dao.manager.DataManager)3 EnvironmentHandler (io.syndesis.server.endpoint.v1.handler.environment.EnvironmentHandler)3 IntegrationDeploymentHandler (io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler)3 SecurityContext (javax.ws.rs.core.SecurityContext)3 Test (org.junit.Test)3 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)2 TargetStateRequest (io.syndesis.server.endpoint.v1.handler.integration.IntegrationDeploymentHandler.TargetStateRequest)2 ListResult (io.syndesis.common.model.ListResult)1 WithName (io.syndesis.common.model.WithName)1 WithResourceId (io.syndesis.common.model.WithResourceId)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 Environment (io.syndesis.common.model.environment.Environment)1 ContinuousDeliveryEnvironment (io.syndesis.common.model.integration.ContinuousDeliveryEnvironment)1 ContinuousDeliveryImportResults (io.syndesis.common.model.integration.ContinuousDeliveryImportResults)1 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)1 IntegrationOverview (io.syndesis.common.model.integration.IntegrationOverview)1 IntegrationDeploymentStateDetails (io.syndesis.common.model.monitoring.IntegrationDeploymentStateDetails)1