use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGeneratorTest method testGenerateApplicationProperties.
@Test
public void testGenerateApplicationProperties() throws IOException {
// ******************
// NEW STYLE
// ******************
final ConnectorAction newAction = new ConnectorAction.Builder().id(KeyGenerator.createKey()).descriptor(new ConnectorDescriptor.Builder().connectorId("new").componentScheme("http4").build()).build();
final Connector newConnector = new Connector.Builder().id("new").addAction(newAction).putProperty("username", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("password", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("token", new ConfigurationProperty.Builder().componentProperty(true).secret(true).build()).build();
// ******************
// Integration
// ******************
Step s1 = new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id(KeyGenerator.createKey()).connector(newConnector).build()).putConfiguredProperty("username", "my-username-2").putConfiguredProperty("password", "my-password-2").putConfiguredProperty("token", "my-token-2").action(newAction).build();
TestResourceManager resourceManager = new TestResourceManager();
ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
ProjectGenerator generator = new ProjectGenerator(configuration, resourceManager, TestConstants.MAVEN_PROPERTIES);
Integration integration = new Integration.Builder().createFrom(resourceManager.newIntegration(s1)).putConfiguredProperty("integration", "property").build();
Properties properties = generator.generateApplicationProperties(integration);
assertThat(properties).containsOnly(entry("integration", "property"), entry("flow-0.http4-0.token", "my-token-2"), entry("flow-0.http4-0.username", "my-username-2"), entry("flow-0.http4-0.password", "my-password-2"));
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class ProjectGeneratorTest method testDependencyCollection.
// *****************************
// Helpers
// *****************************
// ***************************
// Tests
// ***************************
@Test
public void testDependencyCollection() throws Exception {
TestResourceManager resourceManager = new TestResourceManager();
Integration integration = resourceManager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(TestConstants.TIMER_CONNECTOR).build()).putConfiguredProperty("period", "5000").action(TestConstants.PERIODIC_TIMER_ACTION).build(), new Step.Builder().stepKind(StepKind.mapper).putConfiguredProperty("atlasmapping", "{}").build(), new Step.Builder().stepKind(StepKind.ruleFilter).putConfiguredProperty("predicate", "AND").putConfiguredProperty("rules", "[{ \"path\": \"in.header.counter\", \"op\": \">\", \"value\": \"10\" }]").addDependency(Dependency.maven("org.myStep:someLib1:1.0")).addDependency(Dependency.maven("org.myStep:someLib2:1.0")).addDependency(Dependency.maven("org.myStep:someLib3:1.0")).build(), new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("http-connection").connector(TestConstants.HTTP_CONNECTOR).build()).putConfiguredProperty("httpUri", "http://localhost:8080/hello").putConfiguredProperty("username", "admin").putConfiguredProperty("password", "admin").putConfiguredProperty("token", "mytoken").action(TestConstants.HTTP_GET_ACTION).build());
Collection<Dependency> dependencies = resourceManager.collectDependencies(integration);
/*
* Should return
* - 3 step dependencies from the rule filter step
*/
assertEquals(3, dependencies.size());
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class IntegrationResourceManager method collectDependencies.
default Collection<Dependency> collectDependencies(Collection<? extends Step> steps, boolean resolveExtensionTags) {
final List<Dependency> dependencies = new ArrayList<>();
for (Step step : steps) {
dependencies.addAll(step.getDependencies());
step.getAction().filter(WithDependencies.class::isInstance).map(WithDependencies.class::cast).map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
List<Dependency> connectorDependencies = step.getConnection().flatMap(Connection::getConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
dependencies.addAll(connectorDependencies);
List<Dependency> lookedUpConnectorDependencies = step.getConnection().filter(c -> !c.getConnector().isPresent()).map(Connection::getConnectorId).flatMap(this::loadConnector).map(WithDependencies::getDependencies).orElse(Collections.emptyList());
dependencies.addAll(lookedUpConnectorDependencies);
// Custom Icon
step.getConnection().flatMap(ConnectionBase::getConnector).flatMap(ctr -> Optional.ofNullable(ctr.getIcon())).filter(icon -> icon.startsWith("db:")).ifPresent(icon -> dependencies.add(Dependency.from(Dependency.Type.ICON, icon)));
// Connector extension
Stream.concat(connectorDependencies.stream(), lookedUpConnectorDependencies.stream()).filter(Dependency::isExtension).map(Dependency::getId).map(this::loadExtension).filter(Optional::isPresent).map(Optional::get).map(Extension::getDependencies).forEach(dependencies::addAll);
// Step extension
step.getExtension().map(WithDependencies::getDependencies).ifPresent(dependencies::addAll);
step.getExtension().map(Extension::getExtensionId).map(Dependency::extension).ifPresent(dependencies::add);
}
if (resolveExtensionTags) {
return dependencies.stream().flatMap(dep -> {
if (dep.isExtensionTag()) {
List<Extension> extensions = this.loadExtensionsByTag(dep.getId());
Stream<Dependency> extensionDependency = extensions.stream().map(ext -> Dependency.extension(ext.getExtensionId()));
Stream<Dependency> transitive = extensions.stream().map(Extension::getDependencies).flatMap(Collection::stream);
return Stream.concat(extensionDependency, transitive);
} else {
return Stream.of(dep);
}
}).collect(Collectors.toCollection(ArrayList::new));
} else {
return dependencies;
}
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class IntegrationResourceManagerTest method testSanitizeScheduler.
@Test
public void testSanitizeScheduler() {
Integration source = newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(getHttpConnector()).build()).putConfiguredProperty("schedulerType", "timer").putConfiguredProperty("schedulerExpression", "1s").action(getHttpGetAction()).build());
assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse();
Integration sanitized = resourceManager.sanitize(source);
final Flow sanitizedFlow = sanitized.getFlows().get(0);
assertThat(sanitizedFlow.getScheduler().isPresent()).isTrue();
assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("type", Scheduler.Type.timer);
assertThat(sanitizedFlow.getScheduler().get()).hasFieldOrPropertyWithValue("expression", "1s");
assertThat(sanitizedFlow.getSteps().get(0).getStepKind()).isEqualTo(StepKind.endpoint);
assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-type");
assertThat(sanitizedFlow.getSteps().get(0).getConfiguredProperties()).doesNotContainKey("scheduler-expression");
}
use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.
the class KnativeCustomizerTest method testKnativeCustomizerEndpoints.
@Test
public void testKnativeCustomizerEndpoints() throws IOException {
Connector connector;
ConnectorAction sinkAction;
ConnectorAction sourceAction;
try (InputStream is = KnativeCustomizerTest.class.getResourceAsStream("/META-INF/syndesis/connector/knative.json")) {
connector = JsonUtils.readFromStream(is, Connector.class);
sinkAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-endpoint-call-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
sourceAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:knative-endpoint-expose-connector")).findFirst().orElseThrow(() -> new IllegalArgumentException());
}
TestResourceManager manager = new TestResourceManager();
Integration integration = manager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-endpoint-sink").action(sinkAction).connection(new Connection.Builder().connector(connector).build()).build(), new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("name", "my-endpoint-source").action(sourceAction).connection(new Connection.Builder().connector(connector).build()).build());
IntegrationDeployment deployment = new IntegrationDeployment.Builder().userId("user").id("idId").spec(integration).build();
CamelKIntegrationCustomizer customizer = new KnativeCustomizer();
io.syndesis.server.controller.integration.camelk.crd.Integration i = customizer.customize(deployment, new io.syndesis.server.controller.integration.camelk.crd.Integration(), EnumSet.of(Exposure.SERVICE));
assertThat(i.getSpec().getTraits()).containsKey("knative");
assertThat(i.getSpec().getTraits().get("knative").getConfiguration()).containsOnly(entry("enabled", "true"), entry("channel-sources", ""), entry("channel-sinks", ""), entry("endpoint-sources", "default"), entry("endpoint-sinks", "my-endpoint-sink"));
}
Aggregations