default IntegrationDeployment unpublished() { Map<String, String> stepsDone = new HashMap<>(getStepsDone()); stepsDone.remove("deploy"); return builder().currentState(IntegrationDeploymentState.Unpublished).stepsDone(stepsDone).build(); }
final IntegrationDeployment updated = current.builder() .statusMessage(Optional.ofNullable(update.getStatusMessage())) .currentState(update.getState()) .stepsDone(update.getStepsPerformed()) .build(); dataManager.update(new IntegrationDeployment.Builder() .createFrom(current) .currentState(IntegrationDeploymentState.Error) .statusMessage(Exceptions.toString(e)) .updatedAt(System.currentTimeMillis())
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 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"); }
default IntegrationDeployment withCurrentState(IntegrationDeploymentState state) { return builder().currentState(state).build(); }