@Override public Integration updateFlowExcerpts(Integration integration) { // Update excerpt for api provider endpoints only if (integration == null || !integration.getTags().contains("api-provider")) { return integration; } return new Integration.Builder() .createFrom(integration) .flows(integration.getFlows().stream() .map(this::flowWithExcerpts) .collect(Collectors.toList())) .build(); }
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()); }
@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)); }
.build(); Integration modSqlIntegration = new Integration.Builder() .createFrom(sqlIntegration) .flows(Collections.singleton(new Flow.Builder().steps(Collections.singletonList(modStep)).build()))
.build(); return new Integration.Builder() .createFrom(integration) .flows(singleton(flowWithScheduler))
.build(); return new Integration.Builder() .createFrom(integration) .flows(singleton(flowWithScheduler))
@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); }
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); } }
@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); }
/** * 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(); }
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(); }
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(); }
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(); }
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 unusedConnectionsShouldHaveUseOfZero() { final Integration emptyIntegration = new Integration.Builder().build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(emptyIntegration, emptyIntegration)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(new Connection.Builder().createFrom(c1).uses(0).build()); }
@Test public void shouldNotCountUsedExtensionsInDeletedIntegrations() { final ExtensionHandler handler = new ExtensionHandler(data, null, null, null, resource); when(data.fetchAll(Integration.class)) .thenReturn(ListResult.of(new Integration.Builder().createFrom(integration).isDeleted(true).build())); when(data.fetchAll(IntegrationDeployment.class)).thenReturn(ListResult.of(publishedDeployment)); when(resource.collectDependencies(integration)) .thenReturn(Collections.singleton(new Dependency.Builder().id("extension-1").type(Type.EXTENSION).build())); assertThat(handler.enhance(extension).getUses()).hasValue(0); }
protected final Integration newIntegration() { return new Integration.Builder() .id("test-integration") .name("Test Integration") .description("This is a test integration!") .addFlow(new Flow.Builder().steps(createSteps()).build()) .build(); }