@Test public void testSanitizeConnectors() { TestResourceManager resourceManager = new TestResourceManager(); resourceManager.put(TestConstants.TIMER_CONNECTOR.getId().get(), TestConstants.TIMER_CONNECTOR); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connectorId(TestConstants.TIMER_CONNECTOR.getId().get()) .build()) .putConfiguredProperty("period", "5000") .action(TestConstants.PERIODIC_TIMER_ACTION) .build() ); final Optional<Connection> unsanitizedConnection = source.getFlows().get(0).getSteps().get(0).getConnection(); assertThat(unsanitizedConnection.isPresent()).isTrue(); assertThat(unsanitizedConnection.get().getConnector().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); final Optional<Connection> sanitizedConnection = sanitized.getFlows().get(0).getSteps().get(0).getConnection(); assertThat(sanitizedConnection.isPresent()).isTrue(); assertThat(sanitizedConnection.get().getConnector().isPresent()).isTrue(); assertThat(sanitizedConnection.get().getConnector().get()).isEqualTo(TestConstants.TIMER_CONNECTOR); }
@Test public void testSanitizeDefaultScheduler() { TestResourceManager resourceManager = new TestResourceManager(); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connector(TestConstants.HTTP_CONNECTOR) .build()) .putConfiguredProperty("schedulerExpression", "1s") .action(TestConstants.HTTP_GET_ACTION) .build() ); assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); 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"); }
@Test public void testGenerateApplicationWithRestDSL() throws Exception { TestResourceManager resourceManager = new TestResourceManager(); byte[] content = Files.readAllBytes(Paths.get(location.toURI())); resourceManager.put("petstore", new OpenApi.Builder().document(content).id("petstore").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(); } }
@Test public void testSanitizeScheduler() { TestResourceManager resourceManager = new TestResourceManager(); Integration source = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .id("timer-connection") .connector(TestConstants.HTTP_CONNECTOR) .build()) .putConfiguredProperty("schedulerType", "timer") .putConfiguredProperty("schedulerExpression", "1s") .action(TestConstants.HTTP_GET_ACTION) .build() ); assertThat(source.getFlows().get(0).getScheduler().isPresent()).isFalse(); Integration sanitized = ProjectGeneratorHelper.sanitize(source, resourceManager); 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"); }
@Test public void testGenerateProject() throws Exception { TestResourceManager resourceManager = new TestResourceManager(); Integration integration = resourceManager.newIntegration( new Step.Builder() .stepKind(StepKind.endpoint)
.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, s2)) .putConfiguredProperty("integration", "property") .build();