public ListResult<String> getResult() { return ListResult.of(tags); }
@Test public void shouldNotCountUsedExtensionsWhenIntegrationDoesntDependOnIt() { final ExtensionHandler handler = new ExtensionHandler(data, null, null, null, resource); when(data.fetchAll(Integration.class)).thenReturn(ListResult.of(integration)); when(data.fetchAll(IntegrationDeployment.class)).thenReturn(ListResult.of(publishedDeployment)); when(resource.collectDependencies(integration)).thenReturn(Collections.emptyList()); assertThat(handler.enhance(extension).getUses()).hasValue(0); } }
@Test public void shouldFilterEmptyResults() { assertThat(filter.apply(ListResult.of(emptyList()))).isEmpty(); }
@Test public void shouldFilterEmptyResults() { assertThat(filter.apply(ListResult.of(emptyList()))).isEmpty(); }
@Test public void shouldFilterOutOnlyDeletedIntegrations() { assertThat(filter.apply(ListResult.of(integration, deleted, integration))).containsExactly(integration, integration); } }
@Test public void shouldFilterOutTrivialWantedDeployments() { assertThat(filter.apply(ListResult.of(wanted))).containsOnly(wanted); }
@Test public void shouldFilterOutWantedDeployments() { assertThat(filter.apply(ListResult.of(unwanted, wanted, unwanted))).containsOnly(wanted); }
@Test public void shouldCountUsedExtensions() { final ExtensionHandler handler = new ExtensionHandler(data, null, null, null, resource); when(data.fetchAll(Integration.class)).thenReturn(ListResult.of(integration)); 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(1); }
@Test public void shouldNotCountUsedExtensionsOfUnpublishedDeployments() { final ExtensionHandler handler = new ExtensionHandler(data, null, null, null, resource); when(data.fetchAll(Integration.class)).thenReturn(ListResult.of(integration)); when(data.fetchAll(IntegrationDeployment.class)).thenReturn(ListResult.of(unpublishedDeployment)); when(resource.collectDependencies(integration)) .thenReturn(Collections.singleton(new Dependency.Builder().id("extension-1").type(Type.EXTENSION).build())); assertThat(handler.enhance(extension).getUses()).hasValue(0); }
@Test public void shouldFilterOutDeletedIntegrationsEmptyResults() { assertThat(filter.apply(ListResult.of(deleted))).isEmpty(); }
@Test public void withNoIntegrationsConnectionUsageShouldBeZero() { when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(emptyList())); 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); }
@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 connectionsUsedInDeletedIntegrationsShouldNotBeCountedAsUsed() { final Integration integration1 = testIntegration().withFlowConnections(c1).isDeleted(true).build(); final Integration integration2 = testIntegration().withFlowStepsUsingConnections(c1).isDeleted(true).build(); final Integration integration3 = testIntegration().addConnection(c1).isDeleted(true).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(integration1, integration2, integration3)); 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(0); }
@Test public void connectionsReferencedFromTheIntegrationShouldHaveTheirUseCounted() { final Integration usesC1 = testIntegration().withFlowConnections(c1).build(); final Integration usesC1andC2 = testIntegration().withFlowConnections(c1, c2).build(); final Integration usesC2andC3 = testIntegration().withFlowConnections(c2, c3).build(); final Integration usesC1andC2andC3 = testIntegration().withFlowConnections(c1, c2, c3).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(usesC1, usesC1andC2, usesC2andC3, usesC1andC2andC3)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(connectionUsed(c1, 3)); assertThat(handler.augmentedWithUsage(c2)).isEqualTo(connectionUsed(c2, 3)); assertThat(handler.augmentedWithUsage(c3)).isEqualTo(connectionUsed(c3, 2)); assertThat(handler.augmentedWithUsage(asList(c1, c2, c3))).containsOnly(connectionUsed(c1, 3), connectionUsed(c2, 3), connectionUsed(c3, 2)); }
@Test public void someStepsDoNotUseConnectionsAndShouldNotBeConsidered() { final Step stepWithoutConnection = new Step.Builder().build(); final Integration integration = testIntegration().withFlowConnections(c1, c2).withFlowStepsUsingConnections(c1, c3).addFlow(new Flow.Builder().addStep(stepWithoutConnection).build()).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(integration)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(connectionUsed(c1, 2)); assertThat(handler.augmentedWithUsage(c2)).isEqualTo(connectionUsed(c2, 1)); assertThat(handler.augmentedWithUsage(c3)).isEqualTo(connectionUsed(c3, 1)); assertThat(handler.augmentedWithUsage(asList(c1, c2, c3))).containsOnly(connectionUsed(c1, 2), connectionUsed(c2, 1), connectionUsed(c3, 1)); }
@Test public void connectionsReferencedFromTheStepsShouldHaveTheirUseCounted() { final Integration usesC1 = testIntegration().withFlowStepsUsingConnections(c1).build(); final Integration usesC1andC2 = testIntegration().withFlowStepsUsingConnections(c1, c2).build(); final Integration usesC2andC3 = testIntegration().withFlowStepsUsingConnections(c2, c3).build(); final Integration usesC1andC2andC3 = testIntegration().withFlowStepsUsingConnections(c1, c2, c3).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(usesC1, usesC1andC2, usesC2andC3, usesC1andC2andC3)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(connectionUsed(c1, 3)); assertThat(handler.augmentedWithUsage(c2)).isEqualTo(connectionUsed(c2, 3)); assertThat(handler.augmentedWithUsage(c3)).isEqualTo(connectionUsed(c3, 2)); assertThat(handler.augmentedWithUsage(asList(c1, c2, c3))).containsOnly(connectionUsed(c1, 3), connectionUsed(c2, 3), connectionUsed(c3, 2)); }
@Test public void mixedUseOfConnectionsFromIntegrationsAndStepsShouldBeCounted() { final Integration usesC1 = testIntegration().withFlowConnections(c1).build(); final Integration usesC1andC2 = testIntegration().withFlowConnections(c1).withFlowStepsUsingConnections(c2).build(); final Integration usesC2andC3 = testIntegration().withFlowStepsUsingConnections(c2, c3).build(); final Integration usesC1andC2andC3 = testIntegration().withFlowConnections(c1, c2).withFlowStepsUsingConnections(c3).build(); when(dataManager.fetchAll(Integration.class)).thenReturn(ListResult.of(usesC1, usesC1andC2, usesC2andC3, usesC1andC2andC3)); assertThat(handler.augmentedWithUsage(c1)).isEqualTo(connectionUsed(c1, 3)); assertThat(handler.augmentedWithUsage(c2)).isEqualTo(connectionUsed(c2, 3)); assertThat(handler.augmentedWithUsage(c3)).isEqualTo(connectionUsed(c3, 2)); assertThat(handler.augmentedWithUsage(asList(c1, c2, c3))).containsOnly(connectionUsed(c1, 3), connectionUsed(c2, 3), connectionUsed(c3, 2)); }
@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); }
@Test public void shouldFilterOutNonOAuthConnectors() { final Connector connector1 = new Connector.Builder().build(); final Connector connector2 = new Connector.Builder() .putProperty("clientId", new ConfigurationProperty.Builder().addTag(Credentials.CLIENT_ID_TAG).build()) .putConfiguredProperty("clientId", "my-client-id").build(); final Connector connector3 = new Connector.Builder() .putProperty("clientId", new ConfigurationProperty.Builder().addTag(Credentials.CLIENT_ID_TAG).build()).build(); final ListResult<Connector> result = ListResult.of(connector1, connector2, connector3); assertThat(OAuthConnectorFilter.INSTANCE.apply(result)).containsOnly(connector2, connector3); } }