Integration.Builder integration = new Integration.Builder() .id(integrationId) .addTag("api-provider") .createdAt(System.currentTimeMillis()) .name(name); .build(); integration = integration.addFlow(flow); .build(); integration.addResource(new ResourceIdentifier.Builder() .id(apiId) .kind(Kind.OpenApi) .build()); return new APIIntegration(integration.build(), api);
private void setVersion(IntegrationDeployment integrationDeployment) { Integration integration = integrationDeployment.getIntegrationId().map(i -> dataManager.fetch(Integration.class, i)).orElseThrow(()-> new IllegalStateException("Integration not found!")); dataManager.update(new Integration.Builder().createFrom(integration).version(integrationDeployment.getVersion()).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(); } }
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(); Properties properties = generator.generateApplicationProperties(integration);
.build(); Integration modSqlIntegration = new Integration.Builder() .createFrom(sqlIntegration) .flows(Collections.singleton(new Flow.Builder().id(id + ":flow").addStep(modStep).build())) .build();
.build(); integration = new Integration.Builder() .createFrom(integration) .flows(singleton(flowWithScheduler)) .build();
.build(); Integration integration = new Integration.Builder() .id("test-integration") .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();
@Override protected Integration loadIntegration() throws IOException { return new Integration.Builder() .id("asw-integration") .name("asw-integration") .addFlow(new Flow.Builder() .addStep(new Step.Builder() .stepKind(StepKind.endpoint) .build()) .build()) .build();
.build(); Integration modSqlIntegration = new Integration.Builder() .createFrom(sqlIntegration) .flows(Collections.singleton(new Flow.Builder().steps(Collections.singletonList(modStep)).build())) .build();
.build(); return new Integration.Builder() .createFrom(integration) .flows(singleton(flowWithScheduler)) .build();
.build(); return new Integration.Builder() .createFrom(integration) .flows(singleton(flowWithScheduler)) .build();
@Test public void shouldDeleteIntegrationsUpdatingDeploymentsAndDeletingOpensShiftResources() { final Integration integration = new Integration.Builder().id("to-delete").build(); when(dataManager.fetch(Integration.class, "to-delete")).thenReturn(integration); final Integration firstIntegration = new Integration.Builder().createFrom(integration).name("first to delete") .build(); final IntegrationDeployment deployment1 = new IntegrationDeployment.Builder().spec(firstIntegration).version(1) .targetState(IntegrationDeploymentState.Unpublished) .stepsDone(Collections.singletonMap("deploy", "something")).build(); final Integration secondIntegration = new Integration.Builder().createFrom(integration).name("second to delete") .build(); final IntegrationDeployment deployment2 = new IntegrationDeployment.Builder().spec(secondIntegration).version(2) .currentState(IntegrationDeploymentState.Published).targetState(IntegrationDeploymentState.Published) .stepsDone(Collections.singletonMap("deploy", "something")).build(); when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", "to-delete")) .thenReturn(Stream.of(deployment1, deployment2)); final ArgumentCaptor<Integration> updated = ArgumentCaptor.forClass(Integration.class); doNothing().when(dataManager).update(updated.capture()); handler.delete("to-delete"); assertThat(updated.getValue()).isEqualToIgnoringGivenFields( new Integration.Builder().createFrom(integration).isDeleted(true).build(), "updatedAt"); verify(dataManager).update(new IntegrationDeployment.Builder().spec(firstIntegration).version(1) .currentState(IntegrationDeploymentState.Pending).targetState(IntegrationDeploymentState.Unpublished) .build().deleted()); verify(dataManager).update(new IntegrationDeployment.Builder().spec(secondIntegration).version(2) .currentState(IntegrationDeploymentState.Published).targetState(IntegrationDeploymentState.Unpublished) .build().deleted().deleted()); verify(openShiftService).delete("first to delete"); verify(openShiftService).delete("second to delete"); }
@Test public void shouldUpdateIntegrationDeployments() { final SecurityContext security = mock(SecurityContext.class); final Principal principal = mock(Principal.class); when(security.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); final Integration integration = new Integration.Builder().build(); when(dataManager.fetch(Integration.class, INTEGRATION_ID)).thenReturn(integration); final IntegrationDeployment deployment1 = new IntegrationDeployment.Builder().createFrom(deployment(0)) .targetState(IntegrationDeploymentState.Unpublished).build(); final IntegrationDeployment deployment2 = deployment(1); final IntegrationDeployment deployment3 = deployment(2); when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", INTEGRATION_ID)) .thenReturn(Stream.of(deployment1, deployment2, deployment3)); handler.update(security, INTEGRATION_ID); final IntegrationDeployment expected = new IntegrationDeployment.Builder().id(compositeId(INTEGRATION_ID, 3)) .spec(integration).version(3).userId("user").build(); verify(dataManager).update(unpublished(1)); verify(dataManager).update(unpublished(2)); verify(dataManager).create(expected); }
@Test public void shouldSetVersionTo1ForInitialUpdate() { final SecurityContext security = mock(SecurityContext.class); final Principal principal = mock(Principal.class); when(security.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); final Integration integration = new Integration.Builder().build(); when(dataManager.fetch(Integration.class, INTEGRATION_ID)).thenReturn(integration); when(dataManager.fetchAllByPropertyValue(IntegrationDeployment.class, "integrationId", INTEGRATION_ID)) .thenReturn(Stream.empty()); handler.update(security, INTEGRATION_ID); final IntegrationDeployment expected = new IntegrationDeployment.Builder().id(compositeId(INTEGRATION_ID, 1)) .spec(integration).version(1).userId("user").build(); verify(dataManager).create(expected); }
@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); } }
@Test public void shouldCreateIntegrations() { final SecurityContext security = mock(SecurityContext.class); final Principal principal = mock(Principal.class); when(security.getUserPrincipal()).thenReturn(principal); when(principal.getName()).thenReturn("user"); final Integration integration = new Integration.Builder().build(); final Integration created = new Integration.Builder().build(); final Integration encrypted = new Integration.Builder().addTag("encrypted").build(); when(encryptionSupport.encrypt(integration)).thenReturn(encrypted); final ArgumentCaptor<Integration> persisted = ArgumentCaptor.forClass(Integration.class); when(dataManager.create(persisted.capture())).thenReturn(created); assertThat(handler.create(security, integration)).isSameAs(created); assertThat(persisted.getValue()).isEqualToIgnoringGivenFields(encrypted, "createdAt"); verify(encryptionSupport).encrypt(same(integration)); }
/** * Creates an immutable copy of a {@link Integration} 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 Integration instance */ public static Integration copyOf(Integration instance) { if (instance instanceof ImmutableIntegration) { return (ImmutableIntegration) instance; } return new Integration.Builder() .createFrom(instance) .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); }
default IntegrationDeployment deleted() { final Integration integration = new Integration.Builder().createFrom(getSpec()).isDeleted(true).build(); return builder().spec(integration).build(); }
private static IntegrationDeployment deployment(final int version) { return new IntegrationDeployment.Builder().spec(new Integration.Builder().build()).version(version).build(); }