private Optional<Step> getConnectorSplitAsStep(Step step) { if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); if (descriptor.getSplit().isPresent()) { final Split split = descriptor.getSplit().get(); final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split); split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s)); split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s)); return Optional.of(splitBuilder.build()); } } return Optional.empty(); }
private Optional<ProcessorDefinition<?>> configureConnectorSplit(Step step, ProcessorDefinition<?> route, String flowIndex, String stepIndex) { if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); if (descriptor.getSplit().isPresent()) { final Split split = descriptor.getSplit().get(); final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split); split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s)); split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s)); return new SplitStepHandler().handle( splitBuilder.build(), route, this, flowIndex, stepIndex); } } return Optional.empty(); }
TestIntegrationBulder withFlowStepsUsingConnections(final Connection... connections) { return (TestIntegrationBulder) addFlow( new Flow.Builder().addAllSteps(Arrays.stream(connections).map(c -> new Step.Builder().connection(c).build()).collect(Collectors.toList())).build()); }
Integration newIntegration(Step... steps) { for (int i = 0; i < steps.length; i++) { steps[i].getConnection().filter(r -> r.getId().isPresent()).ifPresent( resource -> this.put(resource.getId().get(), resource) ); steps[i].getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).filter(r -> r.getId().isPresent()).ifPresent( resource -> this.put(resource.getId().get(), resource) ); steps[i].getExtension().filter(r -> r.getId().isPresent()).ifPresent( resource -> this.put(resource.getId().get(), resource) ); steps[i] = new Step.Builder().createFrom(steps[i]).build(); } return new Integration.Builder() .id("test-integration") .name("Test Integration") .description("This is a test integration!") .addFlow(new Flow.Builder() .steps(Arrays.asList(steps)) .build()) .build(); } }
protected Step newSqlEndpointStep(String actionId, Consumer<Step.Builder> stepConsumer, Consumer<ConnectorDescriptor.Builder> descriptorConsumer) { final Connector connector = getResourceManager().mandatoryLoadConnector("sql"); final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId); final ConnectorDescriptor.Builder descriptorBuilder = new ConnectorDescriptor.Builder().createFrom(action.getDescriptor()); descriptorConsumer.accept(descriptorBuilder); final Step.Builder builder = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder().createFrom(action).descriptor(descriptorBuilder.build()).build()) .connection(new io.syndesis.common.model.connection.Connection.Builder() .connector(connector) .putConfiguredProperty("user", db.properties.getProperty("sql-connector.user")) .putConfiguredProperty("password", db.properties.getProperty("sql-connector.password")) .putConfiguredProperty("url", db.properties.getProperty("sql-connector.url")) .build()); stepConsumer.accept(builder); return builder.build(); } }
@Test public void shouldGenerateMessages() { final Step step = new Step.Builder().putConfiguredProperty("customText", "Log me baby one more time").build(); assertThat(LogStepHandler.createMessage(step)).isEqualTo("Log me baby one more time"); final Step withContext = new Step.Builder().createFrom(step) .putConfiguredProperty("contextLoggingEnabled", "true").build(); assertThat(LogStepHandler.createMessage(withContext)) .isEqualTo("Message Context: [${in.headers}] Log me baby one more time"); final Step withBody = new Step.Builder().createFrom(step).putConfiguredProperty("bodyLoggingEnabled", "true") .build(); assertThat(LogStepHandler.createMessage(withBody)).isEqualTo("Body: [${body}] Log me baby one more time"); final Step withContextAndBody = new Step.Builder().createFrom(step) .putConfiguredProperty("contextLoggingEnabled", "true").putConfiguredProperty("bodyLoggingEnabled", "true") .build(); assertThat(LogStepHandler.createMessage(withContextAndBody)) .isEqualTo("Message Context: [${in.headers}] Body: [${body}] Log me baby one more time"); }
@Test public void shouldAugmentWithConnectorUsage() { final Connector connector1 = newConnector("1"); final Connector connector2 = newConnector("2"); final Connector connector3 = newConnector("3"); final Step step1a = new Step.Builder().action(newActionBy(connector1)).build(); final Step step1b = new Step.Builder().action(newActionBy(connector1)).build(); final Step step2 = new Step.Builder().action(newActionBy(connector2)).build(); final Integration deployment1 = newIntegration(Arrays.asList(step1a, step1b)); final Integration deployment2 = newIntegration(Collections.singletonList(step2)); final Integration deployment3 = newIntegration(Collections.singletonList(step2)); when(dataManager.fetchAll(Integration.class)) .thenReturn(new ListResult.Builder<Integration>().addItem(deployment1, deployment2, deployment3).build()); final List<Connector> augmented = handler.augmentedWithUsage(Arrays.asList(connector1, connector2, connector3)); assertThat(augmented).contains(usedConnector(connector1, 1), usedConnector(connector2, 2), usedConnector(connector3, 0)); }
@Test public void shouldNotExposeWebHooksVia3scaleWhen3scaleIsEnabled() { final ControllersConfigurationProperties properties = new ControllersConfigurationProperties(); properties.setExposeVia3scale(true); final ExposureDeploymentDataCustomizer customizer = new ExposureDeploymentDataCustomizer(properties); final IntegrationDeployment webHookIntegration = new IntegrationDeployment.Builder() .spec(new Integration.Builder() .addFlow(new Flow.Builder().addStep(new Step.Builder().action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder().connectorId("webhook").build()).addTag("expose") .build()).build()).build()) .build()) .build(); assertThat(customizer.determineExposure(webHookIntegration)).containsOnly(Exposure.SERVICE, Exposure.ROUTE); } }
private Step newSqlStep(Connection connection) { ConnectorAction action = new ConnectorAction.Builder() .actionType("connector") .id(SQL_CONNECTOR_ACTION_ID) .name("Invoke SQL") .pattern(Pattern.To) .addTag("dynamic") .build(); return new Step.Builder() .connection(connection) .id("SomeLongId") .action(action) .build(); }
protected Step newSqlEndpointStep(String actionId, Consumer<Step.Builder> consumer) { final Connector connector = getResourceManager().mandatoryLoadConnector("sql"); final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId); final Step.Builder builder = new Step.Builder() .stepKind(StepKind.endpoint) .action(action) .connection(new io.syndesis.common.model.connection.Connection.Builder() .connector(connector) .putConfiguredProperty("user", db.properties.getProperty("sql-connector.user")) .putConfiguredProperty("password", db.properties.getProperty("sql-connector.password")) .putConfiguredProperty("url", db.properties.getProperty("sql-connector.url")) .build()); consumer.accept(builder); return builder.build(); }
/** * Creates an immutable copy of a {@link Step} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable Step instance */ public static Step copyOf(Step instance) { if (instance instanceof ImmutableStep) { return (ImmutableStep) instance; } return new Step.Builder() .createFrom(instance) .build(); }
protected static Integration newIntegration(Step... steps) { for (int i = 0; i < steps.length; i++) { steps[i] = new Step.Builder().createFrom(steps[i]).build(); } return new Integration.Builder() .id("test-integration") .name("Test Integration") .description("This is a test integration!") .addFlow(new Flow.Builder() .steps(Arrays.asList(steps)) .build()) .build(); }
@Test public void someStepsDoNotUseConnectionsAndShouldNotBeConsidered() { final Step stepWithoutConnection = new Step.Builder().build(); final Integration integration = testIntegration().withFlowConnections(c1, c2).withFlowStepsUsingConnections(c1, c3).addFlow(new Flow.Builder().addStep(stepWithoutConnection).build()).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(integration)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(connectionUsed(c1, 2)); assertThat(handler.augmentedWithUsage(c2)).isEqualTo(connectionUsed(c2, 1)); assertThat(handler.augmentedWithUsage(c3)).isEqualTo(connectionUsed(c3, 1)); assertThat(handler.augmentedWithUsage(asList(c1, c2, c3))).containsOnly(connectionUsed(c1, 2), connectionUsed(c2, 1), connectionUsed(c3, 1)); }
protected final Step newSimpleEndpointStep(String scheme, Consumer<ConnectorDescriptor.Builder> consumer) { ConnectorDescriptor.Builder builder = new ConnectorDescriptor.Builder().componentScheme(scheme); consumer.accept(builder); return new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(builder.build()) .build()) .build(); }
@Test public void testRuleFilterExpression() { String expression = new RuleFilterStepHandler().getFilterExpression( new Step.Builder() .stepKind(StepKind.ruleFilter) .putConfiguredProperty("predicate", FilterPredicate.AND.toString()) .putConfiguredProperty("rules","[ { \"path\": \"person.name\", \"op\": \"==\", \"value\": \"Ioannis\"}, " + " { \"path\": \"person.favoriteDrinks\", \"op\": \"contains\", \"value\": \"Gin\" } ]") .build() ); // Reading notes: Unit tests are like personal diaries. Feel honoured when you have the chance to be part of them ;-) assertThat("${body.person.name} == 'Ioannis' && ${body.person.favoriteDrinks} contains 'Gin'").isEqualTo(expression); }
@Test public void overviewGetShouldAugmentWithConnectionUsage() { final Step stepWithoutConnection = new Step.Builder().build(); final Integration usesC1 = testIntegration().withFlowConnections(c1).build(); final Integration usesC1andC2 = testIntegration().withFlowConnections(c1, c2).build(); final Integration usesC1andC2andC3 = testIntegration().withFlowConnections(c1, c2).withFlowStepsUsingConnections(c1, c3).addFlow(new Flow.Builder().addStep(stepWithoutConnection).build()).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(usesC1, usesC1andC2, usesC1andC2andC3)); when(dataManager.fetch(Connection.class, "c1")).thenReturn(c1); final ConnectionOverview overview = handler.get("c1"); assertThat(overview).isNotNull(); assertThat(overview.getUses()).isPresent(); assertThat(overview.getUses()).hasValue(4); }
protected final Step newEndpointStep(String connectorId, String actionId, Consumer<Connection.Builder> connectionConsumer, Consumer<Step.Builder> stepConsumer) { Connector connector = resourceManager.mandatoryLoadConnector(connectorId); ConnectorAction action = resourceManager.mandatoryLookupAction(connector, actionId); Connection.Builder connectionBuilder = new Connection.Builder().connector(connector); connectionConsumer.accept(connectionBuilder); Step.Builder stepBuilder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(connectionBuilder.build()); stepConsumer.accept(stepBuilder); return stepBuilder.build(); }
@Test public void shouldNotAddLogProcessorWhenNotingIsSpecifiedToLog() { final Step step = new Step.Builder().build(); assertThat(handler.handle(step, route, NOT_USED, "1", "2")).isEmpty(); verifyZeroInteractions(route); } }
@Test public void shouldAddLogProcessorWithCustomMessage() { final Step step = new Step.Builder().putConfiguredProperty("customText", "Log me baby one more time").build(); assertThat(handler.handle(step, route, NOT_USED, "1", "2")).contains(route); verify(route).log(LoggingLevel.INFO, "Log me baby one more time"); }
@Test public void shouldAddLogProcessorWithCustomMessageAndStepId() { final Step step = new Step.Builder().id("step-id") .putConfiguredProperty("customText", "Log me baby one more time").build(); assertThat(handler.handle(step, route, NOT_USED, "1", "2")).contains(route); verify(route).log(LoggingLevel.INFO, (String) null, "step-id", "Log me baby one more time"); }