dataManager.update(new IntegrationDeployment.Builder() .createFrom(current) .currentState(IntegrationDeploymentState.Error)
@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 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 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"); }
private IntegrationDeployment newIntegrationDeployment(String id, int version, Integration integration, boolean published) { Map<String, String> stepsDone = new HashMap<>(); stepsDone.put("buildv1", "ip:port/syndesis/buildName"); stepsDone.put("deploy", "2"); IntegrationDeployment.Builder builder = new IntegrationDeployment.Builder() .id(id + ":" + version) .createdAt(DEPLOYMENT_CREATED_AT) .spec(integration) .integrationId(Optional.of(id)) .stepsDone(stepsDone) .targetState(IntegrationDeploymentState.Published) .userId("developer") .version(version) .updatedAt(DEPLOYMENT_UPDATED_AT); if (published) { builder = builder.currentState(IntegrationDeploymentState.Published); } return builder.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 IntegrationDeployment} 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 IntegrationDeployment instance */ public static IntegrationDeployment copyOf(IntegrationDeployment instance) { if (instance instanceof ImmutableIntegrationDeployment) { return (ImmutableIntegrationDeployment) instance; } return new IntegrationDeployment.Builder() .createFrom(instance) .build(); }
default Builder builder() { return new Builder().createFrom(this); }
private static IntegrationDeployment deployment(final int version) { return new IntegrationDeployment.Builder().spec(new Integration.Builder().build()).version(version).build(); }
@Test public void shouldUpdateIntegrationDeploymentTargetState() { final TargetStateRequest targetState = new TargetStateRequest(); targetState.targetState = IntegrationDeploymentState.Published; final IntegrationDeployment existing = deployment(0); when(dataManager.fetch(IntegrationDeployment.class, compositeId(INTEGRATION_ID, 3))).thenReturn(existing); handler.updateTargetState(INTEGRATION_ID, 3, targetState); final IntegrationDeployment expected = new IntegrationDeployment.Builder().createFrom(existing) .targetState(IntegrationDeploymentState.Published).build(); verify(dataManager).update(expected); }
private static IntegrationDeployment unpublished(final int version) { return new IntegrationDeployment.Builder().createFrom(deployment(version)) .targetState(IntegrationDeploymentState.Unpublished).build(); } }