DataFetchingUtils { public Set<String> getDeliveryDependencies(final RepositoryHandler repoHandler, final DependencyHandler depHandler, final Delivery delivery) { final FiltersHolder filters = new FiltersHolder(); filters.getDecorator().setShowCorporate(Boolean.FALSE); filters.getDecorator().setShowThirdparty(Boolean.TRUE); Set<String> deps = new HashSet<>(); delivery.getDependencies().forEach(d -> { final DbModule module = repoHandler.getModule(d); if (module != null) { final List<Dependency> allDependencies = depHandler.getModuleDependencies(module.getId(), filters); allDependencies.forEach(dep -> deps.add(dep.getTarget().getGavc())); } else { if(isFullGAVC(d)) { deps.add(strip(d, 2)); } else { deps.add(d); } } }); return deps; }  List<DbProduct> getProductWithCommercialDeliveries(final RepositoryHandler repoHandler); Optional<Delivery> getCommercialDelivery(final RepositoryHandler repoHandler,
                                                    final String name,
                                                    final String version); Set<String> getDeliveryDependencies(final RepositoryHandler repoHandler,
                                               final DependencyHandler depHandler,
                                               final Delivery delivery); void initCorporateIDs(final RepositoryHandler repoHandler,
                                 final String orgName); boolean isThirdParty(final DbArtifact artifact);  }
@Test public void getDDArtifactOnlyFullGAVC() { final Delivery delivery = DataModelFactory.createDelivery(SAMPLE_NAME, SAMPLE_VERSION, LocalDate.now().toString(), Arrays.asList("a1:a2:a3:a4", "b1:b2:b3:b4", "c1:c2:c3:c4")); final RepositoryHandler repoHandler = mock(RepositoryHandler.class); when(repoHandler.getModule(anyString())).thenReturn(null); final DataFetchingUtils sut = new DataFetchingUtils(); final Set<String> deliveryDependencies = sut.getDeliveryDependencies(repoHandler, mock(DependencyHandler.class), delivery); assertEquals(3, deliveryDependencies.size()); assertTrue(deliveryDependencies.contains("a1:a2")); assertTrue(deliveryDependencies.contains("b1:b2")); assertTrue(deliveryDependencies.contains("c1:c2")); }
@Test public void getDDArtifactOnlyNonFullGAVC() throws NoSuchFieldException, IllegalAccessException { final Delivery delivery = DataModelFactory.createDelivery( SAMPLE_NAME, SAMPLE_VERSION, LocalDate.now().toString(), Arrays.asList("one", "two", "three")); final RepositoryHandler repoHandler = mock(RepositoryHandler.class); when(repoHandler.getModule(anyString())).thenReturn(null); final DataFetchingUtils sut = new DataFetchingUtils(); final Set<String> deliveryDependencies = sut.getDeliveryDependencies(repoHandler, mock(DependencyHandler.class), delivery); assertEquals(3, deliveryDependencies.size()); }
@Test public void getDDMultipleModulesAvoidDuplicates() { final Delivery delivery = DataModelFactory.createDelivery( SAMPLE_NAME, SAMPLE_VERSION, "Today", Arrays.asList("one", "two")); final DbModule m1 = makeModule("one"); final DbModule m2 = makeModule("two"); final RepositoryHandler repoHandler = makeRepoHandler(m1, m2); final DependencyHandler depHandler = mock(DependencyHandler.class); withDeps(depHandler, "one", "one_a", "common_dep"); withDeps(depHandler, "two", "two_a", "two_b", "common_dep"); final DataFetchingUtils sut = new DataFetchingUtils(); final Set<String> results = sut.getDeliveryDependencies(repoHandler, depHandler, delivery); assertEquals(2 + 3 - 1, results.size()); assertTrue(results.contains(makeGAVC("one_a"))); assertTrue(results.contains(makeGAVC("two_a"))); assertTrue(results.contains(makeGAVC("two_b"))); assertTrue(results.contains(makeGAVC("common_dep"))); }
@Test public void getDDMultipleModulesJoinDeps() { final Delivery delivery = DataModelFactory.createDelivery( SAMPLE_NAME, SAMPLE_VERSION, LocalDate.now().toString(), Arrays.asList("one", "two", "three")); final DbModule m1 = makeModule("one"); final DbModule m2 = makeModule("two"); final DbModule m3 = makeModule("three"); final RepositoryHandler repoHandler = makeRepoHandler(m1, m2, m3); final DependencyHandler depHandler = mock(DependencyHandler.class); withDeps(depHandler, "one", "one_a"); withDeps(depHandler, "two", "two_a", "two_b"); withDeps(depHandler, "three", "three_a", "three_b", "three_c"); final DataFetchingUtils sut = new DataFetchingUtils(); final Set<String> deliveryDependencies = sut.getDeliveryDependencies(repoHandler, depHandler, delivery); assertEquals(1 + 2 + 3, deliveryDependencies.size()); assertTrue(deliveryDependencies.contains(makeGAVC("one_a"))); assertTrue(deliveryDependencies.contains(makeGAVC("two_a"))); assertTrue(deliveryDependencies.contains(makeGAVC("two_b"))); assertTrue(deliveryDependencies.contains(makeGAVC("three_a"))); assertTrue(deliveryDependencies.contains(makeGAVC("three_b"))); assertTrue(deliveryDependencies.contains(makeGAVC("three_c"))); }
@Test public void appropriateFiltersAreUsedOnModuleDepRetrieval() { final Delivery delivery = DataModelFactory.createDelivery( SAMPLE_NAME, SAMPLE_VERSION, LocalDate.now().toString(), Arrays.asList("one")); final DbModule m1 = makeModule("one"); final RepositoryHandler repoHandler = makeRepoHandler(m1); final DependencyHandler depHandler = mock(DependencyHandler.class); withDeps(depHandler, "one", "one_a"); final DataFetchingUtils sut = new DataFetchingUtils(); final Set<String> deliveryDependencies = sut.getDeliveryDependencies(repoHandler, depHandler, delivery); ArgumentCaptor<FiltersHolder> filterCollector = ArgumentCaptor.forClass(FiltersHolder.class); verify(depHandler, times(1)).getModuleDependencies(eq("one"), filterCollector.capture()); Decorator d = filterCollector.getValue().getDecorator(); assertFalse(d.getShowCorporate()); assertTrue(d.getShowThirdparty()); }