@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 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"); }