Flow flow = new Flow.Builder() .id(String.format("%s:flows:%s", integrationId, operationId)) .putMetadata(EXCERPT_METADATA_KEY, "501 Not Implemented") .putMetadata(DEFAULT_RETURN_CODE_METADATA_KEY, defaultCode) .addStep(startStep) .addStep(endStep) .name(operationName) .description(operationDescription) .build();
.flows(Collections.singleton(new Flow.Builder().steps(Collections.singletonList(modStep)).build())) .build();
protected Flow flowWithExcerpts(Flow flow) { List<Step> steps = flow.getSteps(); if (steps == null || steps.isEmpty()) { return flow; } Step last = steps.get(steps.size() - 1); if (last.getConfiguredProperties().containsKey("httpResponseCode")) { String responseCode = last.getConfiguredProperties().get("httpResponseCode"); String responseDesc = decodeHttpReturnCode(steps, responseCode); return new Flow.Builder() .createFrom(flow) .putMetadata(EXCERPT_METADATA_KEY, responseDesc) .build(); } else if (flow.getMetadata(EXCERPT_METADATA_KEY).isPresent()) { Map<String, String> newMetadata = new HashMap<>(flow.getMetadata()); newMetadata.remove(EXCERPT_METADATA_KEY); return new Flow.Builder() .createFrom(flow) .metadata(newMetadata) .build(); } return flow; }
.name("Test Integration") .description("This is a test integration!") .addResource(new ResourceIdentifier.Builder() .kind(Kind.OpenApi) .id("petstore") .build()) .addFlow(new Flow.Builder() .steps(Arrays.asList(s1, s2)) .build()) .build();
.name("asw-integration") .addFlow(new Flow.Builder() .addStep(new Step.Builder() .stepKind(StepKind.endpoint) .connection(new Connection.Builder() .build()) .build()) .addStep(new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .build()) .build()) .build()) .build();
.flows(Collections.singleton(new Flow.Builder().id(id + ":flow").addStep(modStep).build())) .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 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); } }
/** * Creates an immutable copy of a {@link Flow} 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 Flow instance */ public static Flow copyOf(Flow instance) { if (instance instanceof ImmutableFlow) { return (ImmutableFlow) instance; } return new Flow.Builder() .createFrom(instance) .build(); }
default Flow.Builder builder() { return new Flow.Builder().createFrom(this); }
TestIntegrationBulder withFlowConnections(final Connection... connections) { return (TestIntegrationBulder) addFlow(new Flow.Builder().addConnection(connections).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(); }
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()); }
private static Integration newIntegration(List<Step> steps) { return new Integration.Builder() .id("test") .name("test") .addFlow(new Flow.Builder().steps(steps).build()) .build(); } }
@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); }
@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)); }
private Integration newSqlIntegration(String id, Connection connection) { return new Integration.Builder() .id(id) .name(id) .addFlow(new Flow.Builder().id(id + ":flow").addStep(newSqlStep(connection)).build()) .createdAt(INTEGRATION_CREATED_AT) .updatedAt(INTEGRATION_UPDATED_AT) .build(); }