@Override public Integration get(String id) { Integration integration = Getter.super.get(id); if ( integration.isDeleted() ) { //Not sure if we need to do that for both current and desired status, //but If we don't do include the desired state, IntegrationITCase is not going to pass anytime soon. Why? //Cause that test, is using NoopHandlerProvider, so that means no controllers. throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId())); } // Get the latest connection configs. List<Connection> connections = integration.getConnections().stream() .map(this::toCurrentConnection) .collect(Collectors.toList()); List<Step> steps = integration.getSteps().stream() .map(this::toCurrentSteps) .collect(Collectors.toList()); return new Integration.Builder() .createFrom(integration) .connections(connections) .steps(steps) .build(); }
@Before public void setupMocks() { validator.dataManager = mock(DataManager.class); when(validator.dataManager.fetchIdsByPropertyValue(Connection.class, "name", "Existing")) .thenReturn(new HashSet<>(Arrays.asList("same"))); when(validator.dataManager.fetchIdsByPropertyValue(Integration.class, "name", "Existing")) .thenReturn(new HashSet<>(Arrays.asList("deleted"))); when(validator.dataManager.fetch(Integration.class, "deleted")) .thenReturn(new Integration.Builder().name("Existing").id("deleted").isDeleted(true).build()); }
@Override public void delete(String id) { Integration existing = Getter.super.get(id); //Set all integration status to Undeployed. Set<String> deploymentIds = getDataManager().fetchIdsByPropertyValue(IntegrationDeployment.class, "integrationId", existing.getId().get()); if (deploymentIds != null && !deploymentIds.isEmpty()) { deploymentIds.stream() .map(i -> getDataManager().fetch(IntegrationDeployment.class, i)) .filter(r -> r != null) .map(r -> r.withTargetState(IntegrationDeploymentState.Unpublished)) .forEach(r -> getDataManager().update(r)); } Integration updatedIntegration = new Integration.Builder() .createFrom(existing) .updatedAt(System.currentTimeMillis()) .isDeleted(true) .build(); Updater.super.update(id, updatedIntegration); }
private void importIntegrations(SecurityContext sec, JsonDbDao<Integration> export, ArrayList<ChangeEvent> result) { for (Integration integration : export.fetchAll().getItems()) { Integration.Builder builder = new Integration.Builder() .createFrom(integration) .isDeleted(false) .updatedAt(System.currentTimeMillis()); // Do we need to create it? String id = integration.getId().get(); Integration previous = dataManager.fetch(Integration.class, id); if (previous == null) { LOG.info("Creating integration: {}", integration.getName()); integrationHandler.create(sec, builder.build()); result.add(ChangeEvent.of("created", integration.getKind().getModelName(), id)); } else { LOG.info("Updating integration: {}", integration.getName()); integrationHandler.update(id, builder.version(previous.getVersion()+1).build()); result.add(ChangeEvent.of("updated", integration.getKind().getModelName(), id)); } integrationHandler.updateBulletinBoard(id); break; } }
@Test public void findTags() { Integration integration = new Integration.Builder() .addTag("tag1") .addTag("tag2") .build(); Connection connection = new Connection.Builder() .addTag("tag2") .addTag("tag3") .build(); ListResult<String> allTags = new TagFinder() .add(ListResult.of(integration)) .add(ListResult.of(connection)) .getResult(); Assert.assertEquals( 3, allTags.getTotalCount()); Assert.assertTrue(allTags.getItems().contains("tag1") ); Assert.assertTrue(allTags.getItems().contains("tag2") ); Assert.assertTrue(allTags.getItems().contains("tag3") ); }
@Test public void deserializeModelDataTest() throws IOException { Integration integrationIn = new Integration.Builder() .tags(new TreeSet<>(Arrays.asList("tag1", "tag2"))) .createdAt(System.currentTimeMillis()) .build(); String integrationJson = Json.writer().writeValueAsString(integrationIn); // System.out.println(integrationJson); Integration integrationOut = Json.reader().forType(Integration.class).readValue(integrationJson); //serialize ConnectorGroup cg = new ConnectorGroup.Builder().id("label").name("label").build(); ModelData<ConnectorGroup> mdIn = new ModelData<>(Kind.ConnectorGroup, cg); Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdIn.getDataAsJson()); //deserialize String json = Json.writer().writeValueAsString(mdIn); ModelData<?> mdOut = Json.reader().forType(ModelData.class).readValue(json); Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdOut.getDataAsJson()); }
@Test public void testTrimming() throws IOException { final SortedSet<String> tags = new TreeSet<>(); tags.add(""); tags.add(" tag"); tags.add("\tTaggy McTagface\t"); final Integration original = new Integration.Builder() .id("test") .name(" some-name\t").description("") .tags(tags) .desiredStatus(IntegrationDeploymentState.Draft) .build(); final Integration created = Json.mapper().readValue(Json.mapper().writeValueAsBytes(original), Integration.class); assertThat(created.getName()).isEqualTo("some-name"); assertThat(created.getDescription()).isNotPresent(); assertThat(created.getTags()).containsExactly("Taggy McTagface", "tag"); } }
@Parameters public static Iterable<Object[]> parameters() { final Connection existingNameNoId = new Connection.Builder().name("Existing").build(); final Connection existingNameWithSameId = new Connection.Builder().name("Existing").id("same").build(); final Connection existingNameWithDifferentId = new Connection.Builder().name("Existing").id("different") .build(); final Connection uniqueNameNoId = new Connection.Builder().name("Unique").build(); final Integration existingButDeleted = new Integration.Builder().name("Existing").id("different").build(); return Arrays.asList(// new Object[] {existingNameNoId, false}, // new Object[] {existingNameWithSameId, true}, // new Object[] {existingNameWithDifferentId, false}, // new Object[] {uniqueNameNoId, true}, // new Object[] {existingButDeleted, true}// ); } }
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()); }
@Override public Integration create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Integration integration) { Integration encryptedIntegration = encryptionSupport.encrypt(integration); Integration updatedIntegration = new Integration.Builder() .createFrom(encryptedIntegration) .createdAt(System.currentTimeMillis()) .build(); // Create the the integration. return getDataManager().create(updatedIntegration); }
@Test public void shouldValidateForNameUniqueness() { UniqnenessValidator.VALID.set(true); final Set<ConstraintViolation<Integration>> violations = validator.validate(new Integration.Builder().build(), UniquenessRequired.class); assertThat(violations).isEmpty(); }
@Override public void update(String id, @ConvertGroup(from = Default.class, to = AllValidations.class) Integration integration) { Integration existing = Getter.super.get(id); Integration updatedIntegration = new Integration.Builder() .createFrom(encryptionSupport.encrypt(integration)) .version(existing.getVersion()+1) .updatedAt(System.currentTimeMillis()) .build(); getDataManager().update(updatedIntegration); updateBulletinBoard(id); }
protected final Integration newIntegration() { return new Integration.Builder() .id("test-integration") .name("Test Integration") .description("This is a test integration!") .steps(createSteps()) .build(); }
private void updateIntegration(IntegrationDeployment integrationDeployment, IntegrationDeploymentState state) { Integration current = dataManager.fetch(Integration.class, integrationDeployment.getIntegrationId().orElseThrow(() -> new IllegalStateException("IntegrationDeployment should have an integrationId"))); //Set the deployed integrationDeployment id. Integration updated = new Integration.Builder().createFrom(current) .deploymentId(integrationDeployment.getVersion().get()) .currentStatus(state) .build(); dataManager.update(updated); }
@Test public void shouldNotifyOfUniquenessConstraintViolation() { UniqnenessValidator.VALID.set(false); final Set<ConstraintViolation<Integration>> violations = validator.validate(new Integration.Builder().build(), UniquenessRequired.class); assertThat(violations).hasSize(1); }
public Integration encrypt(Integration integration) { return new Integration.Builder() .createFrom(integration) .steps(encrypt(integration.getSteps())) .build(); }
private static Integration newIntegration(List<Step> steps) { return new Integration.Builder() .id("test") .name("test") .steps(steps) .build(); } }