Search in sources :

Example 21 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationsITCase method shouldDetermineValidityForInvalidIntegrations.

@Test
public void shouldDetermineValidityForInvalidIntegrations() {
    dataManager.create(new Integration.Builder().name("Existing integration").build());
    final Integration integration = new Integration.Builder().name("Existing integration").build();
    final ResponseEntity<List<Violation>> got = post("/api/v1/integrations/validation", integration, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
    assertThat(got.getBody()).hasSize(1);
}
Also used : Integration(io.syndesis.common.model.integration.Integration) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 22 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class IntegrationsITCase method patchIntegrationDescription.

@Test
public void patchIntegrationDescription() {
    Integration integration = new Integration.Builder().id("3001").name("test").description("My first description").build();
    post("/api/v1/integrations", integration, Integration.class);
    ResponseEntity<IntegrationOverview> result = get("/api/v1/integrations/3001", IntegrationOverview.class);
    assertThat(result.getBody().getDescription()).as("description").isEqualTo(Optional.of("My first description"));
    // Do the PATCH API call:
    Map<String, Object> patchDoc = Collections.singletonMap("description", "The second description");
    patch("/api/v1/integrations/3001", patchDoc);
    result = get("/api/v1/integrations/3001", IntegrationOverview.class);
    assertThat(result.getBody().getDescription()).as("description").isEqualTo(Optional.of("The second description"));
}
Also used : Integration(io.syndesis.common.model.integration.Integration) IntegrationOverview(io.syndesis.common.model.integration.IntegrationOverview) Test(org.junit.Test)

Example 23 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class JsonHandlingITCase method valuesGivenInJsonShouldBeTrimmedToNull.

@Test
public void valuesGivenInJsonShouldBeTrimmedToNull() {
    final SortedSet<String> tags = new TreeSet<>();
    tags.add("");
    tags.add(" tag");
    tags.add("\tTaggy McTagface\t");
    final Integration integration = new Integration.Builder().id(id).name("  some-name\t").description("").tags(tags).build();
    post("/api/v1/integrations", integration, Integration.class);
    final ResponseEntity<Integration> result = get("/api/v1/integrations/" + id, Integration.class);
    final Integration created = result.getBody();
    assertThat(created.getName()).isEqualTo("some-name");
    assertThat(created.getDescription()).isNotPresent();
    assertThat(created.getTags()).containsExactly("Taggy McTagface", "tag");
}
Also used : Integration(io.syndesis.common.model.integration.Integration) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 24 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class T3stSupportITCase method createAndGetIntegration.

@Test
public void createAndGetIntegration() {
    // Reset to fresh startup state..
    get("/api/v1/test-support/reset-db", Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // We should have some initial data in the snapshot since we start up with deployment.json
    @SuppressWarnings({ "unchecked", "rawtypes" }) Class<ModelData<?>[]> type = (Class) ModelData[].class;
    ResponseEntity<ModelData<?>[]> r1 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r1.getBody().length).isGreaterThan(1);
    // restoring to no data should.. leave us with no data.
    ModelData<?>[] noData = new ModelData<?>[] {};
    post("/api/v1/test-support/restore-db", noData, (Class<?>) null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Lets add an integration...
    Integration integration = new Integration.Builder().id("3001").name("test").build();
    post("/api/v1/integrations", integration, Integration.class);
    // Snapshot should only contain the integration entity..
    ResponseEntity<ModelData<?>[]> r2 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r2.getBody()).isNotEmpty();
    long r2Integrations = Arrays.stream(r2.getBody()).filter(b -> b.getKind() == Kind.Integration).count();
    assertThat(r2Integrations).isEqualTo(1);
    // Reset to fresh startup state..
    get("/api/v1/test-support/reset-db", Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Verify that the new state has the same number of entities as the original
    ResponseEntity<ModelData<?>[]> r3 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r3.getBody().length).isEqualTo(r1.getBody().length);
    // restoring 1 item of data
    post("/api/v1/test-support/restore-db", r2.getBody(), (Class<?>) null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Snapshot should only contain the integration entity..
    ResponseEntity<ModelData<?>[]> r4 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r4.getBody()).isNotEmpty();
    long r4Integrations = Arrays.stream(r4.getBody()).filter(b -> b.getKind() == Kind.Integration).count();
    assertThat(r4Integrations).isEqualTo(1);
}
Also used : ModelData(io.syndesis.common.model.ModelData) HttpStatus(org.springframework.http.HttpStatus) Arrays(java.util.Arrays) Kind(io.syndesis.common.model.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) ResponseEntity(org.springframework.http.ResponseEntity) Integration(io.syndesis.common.model.integration.Integration) ModelData(io.syndesis.common.model.ModelData) Integration(io.syndesis.common.model.integration.Integration) Test(org.junit.Test)

Example 25 with Integration

use of io.syndesis.common.model.integration.Integration in project syndesis by syndesisio.

the class ProjectGenerator method generateApplicationProperties.

@SuppressWarnings("PMD")
@Override
public Properties generateApplicationProperties(final Integration integrationDefinition) {
    final Integration integration = sanitize(integrationDefinition, resourceManager);
    final Properties properties = new Properties();
    final List<? extends Step> steps = integration.getSteps();
    for (int i = 0; i < steps.size(); i++) {
        final Step step = steps.get(i);
        // Check if a step is of supported type.
        if (StepKind.endpoint != step.getStepKind()) {
            continue;
        }
        // Check if a step has the required options
        if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent() && step.getConnection().isPresent()) {
            final String index = Integer.toString(i + 1);
            final Connection connection = step.getConnection().get();
            final ConnectorAction action = ConnectorAction.class.cast(step.getAction().get());
            final ConnectorDescriptor descriptor = action.getDescriptor();
            final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
            if (connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()) {
                // Grab the component scheme from the component descriptor or
                // from the connector
                final String componentScheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
                final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
                // Workaround for https://github.com/syndesisio/syndesis/issues/1713
                for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
                    if (entry.getValue() != null && entry.getValue().getDefaultValue() != null && !entry.getValue().getDefaultValue().isEmpty()) {
                        if (connector.isSecret(entry.getKey()) || action.isSecret(entry.getKey())) {
                            addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue().getDefaultValue());
                        }
                    }
                }
                for (Map.Entry<String, String> entry : connection.getConfiguredProperties().entrySet()) {
                    if (connector.isSecret(entry) || action.isSecret(entry)) {
                        addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
                    }
                }
                for (Map.Entry<String, String> entry : step.getConfiguredProperties().entrySet()) {
                    if (connector.isSecret(entry) || action.isSecret(entry)) {
                        addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
                    }
                }
            } else {
                // The component scheme is defined as camel connector prefix
                // for 'old' style connectors.
                final String componentScheme = descriptor.getCamelConnectorPrefix();
                // endpoint secrets
                Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> {
                    addDecryptedKeyProperty(properties, index, componentScheme, e.getKey(), e.getValue());
                });
                // Component properties triggers connectors aliasing so we
                // can have multiple instances of the same connectors
                Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isComponentProperty, action::isComponentProperty)).forEach(e -> {
                    String propKeyPrefix = String.format("%s.configurations.%s", componentScheme, componentScheme);
                    addDecryptedKeyProperty(properties, index, propKeyPrefix, e.getKey(), e.getValue());
                });
            }
        }
    }
    return properties;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ProjectGeneratorHelper.sanitize(io.syndesis.integration.project.generator.ProjectGeneratorHelper.sanitize) ProjectGeneratorHelper.mandatoryDecrypt(io.syndesis.integration.project.generator.ProjectGeneratorHelper.mandatoryDecrypt) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ProjectGeneratorHelper.addTarEntry(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addTarEntry) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) MavenProperties(io.syndesis.common.util.MavenProperties) StringUtils(org.apache.commons.lang3.StringUtils) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) PipedInputStream(java.io.PipedInputStream) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Integration(io.syndesis.common.model.integration.Integration) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Set(java.util.Set) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ProjectGeneratorHelper.addResource(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addResource) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Stream(java.util.stream.Stream) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) MavenGav(io.syndesis.integration.project.generator.mvn.MavenGav) PomContext(io.syndesis.integration.project.generator.mvn.PomContext) Step(io.syndesis.common.model.integration.Step) Mustache(com.github.mustachejava.Mustache) Names(io.syndesis.common.util.Names) TreeSet(java.util.TreeSet) MustacheFactory(com.github.mustachejava.MustacheFactory) CollectionsUtils(io.syndesis.common.util.CollectionsUtils) StepKind(io.syndesis.common.model.integration.StepKind) Optionals(io.syndesis.common.util.Optionals) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) Predicates(io.syndesis.common.util.Predicates) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) Dependency(io.syndesis.common.model.Dependency) ProjectGeneratorHelper.compile(io.syndesis.integration.project.generator.ProjectGeneratorHelper.compile) Paths(java.nio.file.Paths) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) MavenProperties(io.syndesis.common.util.MavenProperties) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Properties(java.util.Properties) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Map(java.util.Map)

Aggregations

Integration (io.syndesis.common.model.integration.Integration)57 Test (org.junit.Test)19 Step (io.syndesis.common.model.integration.Step)17 List (java.util.List)16 Connection (io.syndesis.common.model.connection.Connection)15 Connector (io.syndesis.common.model.connection.Connector)11 DataManager (io.syndesis.server.dao.manager.DataManager)11 IOException (java.io.IOException)11 Set (java.util.Set)10 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)8 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)7 Map (java.util.Map)7 Action (io.syndesis.common.model.action.Action)6 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)6 StepKind (io.syndesis.common.model.integration.StepKind)6