Search in sources :

Example 1 with APIFormData

use of io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData in project syndesis by syndesisio.

the class IntegrationSpecificationHandlerTest method shouldStoreUpdatedSpecificationForNonFlowChanges.

@Test
public void shouldStoreUpdatedSpecificationForNonFlowChanges() {
    final Step step = new Step.Builder().action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().build()).build()).build();
    final Integration integration = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").addSteps(step, step).build()).build();
    final byte[] updatedSpecificationDocument = "updated specification".getBytes(StandardCharsets.UTF_8);
    final OpenApi updatedSpecification = new OpenApi.Builder().document(updatedSpecificationDocument).build();
    final APIIntegration updatedApiIntegration = new APIIntegration(integration, updatedSpecification);
    when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
    when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
    when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(integration);
    when(encryptionSupport.encrypt(integration)).thenReturn(integration);
    when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
    when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
    final APIFormData openApiUpdate = new APIFormData();
    openApiUpdate.setSpecification(new ByteArrayInputStream(updatedSpecificationDocument));
    handler.update("integration-1", openApiUpdate);
    verify(dataManager).store(updatedSpecification, OpenApi.class);
    verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
        assertThat(v).isEqualToIgnoringGivenFields(integration, "version", "updatedAt");
        assertThat(v.getVersion()).isEqualTo(2);
        return true;
    }));
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) OpenApi(io.syndesis.common.model.openapi.OpenApi) ArgumentMatchers(org.mockito.ArgumentMatchers) Step(io.syndesis.common.model.integration.Step) ResourceIdentifier(io.syndesis.common.model.ResourceIdentifier) Kind(io.syndesis.common.model.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) APIIntegration(io.syndesis.server.api.generator.APIIntegration) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) Integration(io.syndesis.common.model.integration.Integration) Status(javax.ws.rs.core.Response.Status) Connector(io.syndesis.common.model.connection.Connector) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Flow(io.syndesis.common.model.integration.Flow) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) APIGenerator(io.syndesis.server.api.generator.APIGenerator) APIFormData(io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData) Mockito.mock(org.mockito.Mockito.mock) APIIntegration(io.syndesis.server.api.generator.APIIntegration) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Flow(io.syndesis.common.model.integration.Flow) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) APIIntegration(io.syndesis.server.api.generator.APIIntegration) OpenApi(io.syndesis.common.model.openapi.OpenApi) APIFormData(io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData) Test(org.junit.Test)

Example 2 with APIFormData

use of io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData in project syndesis by syndesisio.

the class IntegrationSpecificationHandlerTest method shouldPerformUpdatesBasedOnNewSpecification.

@Test
public void shouldPerformUpdatesBasedOnNewSpecification() {
    final Integration existing = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").build()).build();
    final Integration given = new Integration.Builder().id("integration-2").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
    final Integration expected = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
    final OpenApi updatedSpecification = new OpenApi.Builder().build();
    final APIIntegration updatedApiIntegration = new APIIntegration(given, updatedSpecification);
    when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
    when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
    when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(existing);
    when(encryptionSupport.encrypt(expected)).thenReturn(expected);
    when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
    when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
    final APIFormData openApiUpdate = new APIFormData();
    openApiUpdate.setSpecification(new ByteArrayInputStream("updated specification".getBytes(StandardCharsets.UTF_8)));
    handler.update("integration-1", openApiUpdate);
    verify(dataManager).store(updatedSpecification, OpenApi.class);
    verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
        assertThat(v).isEqualToIgnoringGivenFields(expected, "version", "updatedAt");
        assertThat(v.getVersion()).isEqualTo(2);
        return true;
    }));
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) OpenApi(io.syndesis.common.model.openapi.OpenApi) ArgumentMatchers(org.mockito.ArgumentMatchers) Step(io.syndesis.common.model.integration.Step) ResourceIdentifier(io.syndesis.common.model.ResourceIdentifier) Kind(io.syndesis.common.model.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) APIIntegration(io.syndesis.server.api.generator.APIIntegration) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) Integration(io.syndesis.common.model.integration.Integration) Status(javax.ws.rs.core.Response.Status) Connector(io.syndesis.common.model.connection.Connector) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Flow(io.syndesis.common.model.integration.Flow) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) APIGenerator(io.syndesis.server.api.generator.APIGenerator) APIFormData(io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData) Mockito.mock(org.mockito.Mockito.mock) APIIntegration(io.syndesis.server.api.generator.APIIntegration) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) ByteArrayInputStream(java.io.ByteArrayInputStream) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) APIIntegration(io.syndesis.server.api.generator.APIIntegration) OpenApi(io.syndesis.common.model.openapi.OpenApi) APIFormData(io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData) Test(org.junit.Test)

Aggregations

Kind (io.syndesis.common.model.Kind)2 ResourceIdentifier (io.syndesis.common.model.ResourceIdentifier)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)2 Connection (io.syndesis.common.model.connection.Connection)2 Connector (io.syndesis.common.model.connection.Connector)2 Flow (io.syndesis.common.model.integration.Flow)2 Integration (io.syndesis.common.model.integration.Integration)2 Step (io.syndesis.common.model.integration.Step)2 OpenApi (io.syndesis.common.model.openapi.OpenApi)2 IntegrationResourceManager (io.syndesis.integration.api.IntegrationResourceManager)2 APIGenerator (io.syndesis.server.api.generator.APIGenerator)2 APIIntegration (io.syndesis.server.api.generator.APIIntegration)2 ProvidedApiTemplate (io.syndesis.server.api.generator.ProvidedApiTemplate)2 DataManager (io.syndesis.server.dao.manager.DataManager)2 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)2 APIFormData (io.syndesis.server.endpoint.v1.handler.api.ApiHandler.APIFormData)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Optional (java.util.Optional)2