ContainerSearch { public List<Container> search(Collection<? extends HasMetadata> list) { return list.stream() .filter(this::matchMetadata) .flatMap(this::findContainers) .filter(this::matchContainer) .collect(toList()); } ContainerSearch(
      @Nullable String parentName,
      @Nullable Map<String, String> parentSelector,
      @Nullable String containerName); List<Container> search(Collection<? extends HasMetadata> list);  }
@Test public void shouldFindAllContainersIfNotRestricted() { ContainerSearch search = new ContainerSearch(null, null, null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 12); assertContainsContainer(results, "container1"); assertContainsContainer(results, "container2"); assertContainsContainer(results, "container3"); assertContainsContainer(results, "container4"); assertContainsContainer(results, "container5"); assertContainsContainer(results, "container6"); assertContainsContainer(results, "container7"); assertContainsContainer(results, "container8"); assertContainsContainer(results, "container9"); assertContainsContainer(results, "container10"); assertContainsContainer(results, "container11"); assertContainsContainer(results, "container12"); }
@Test public void shouldRestrictByName() { ContainerSearch search = new ContainerSearch("podWithName", null, null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 1); assertContainsContainer(results, "container1"); }
@Test public void shouldRestrictByGenerateName() { ContainerSearch search = new ContainerSearch("podWithGenerateName", null, null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 1); assertContainsContainer(results, "container2"); }
@Test public void shouldRestrictByContainerName() { ContainerSearch search = new ContainerSearch(null, null, "container7"); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 1); assertContainsContainer(results, "container7"); }
@Test public void shouldRestrictByParentSelector() { Map<String, String> selector = ImmutableMap.of("app", "che"); ContainerSearch search = new ContainerSearch(null, selector, null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 6); assertContainsContainer(results, "container1"); assertContainsContainer(results, "container3"); assertContainsContainer(results, "container5"); assertContainsContainer(results, "container7"); assertContainsContainer(results, "container9"); assertContainsContainer(results, "container11"); }
@Test public void shouldConsiderEmptySelectorAsNotPresent() { ContainerSearch search = new ContainerSearch(null, Collections.emptyMap(), null); List<Container> results = search.search(testList); Assert.assertEquals(results.size(), 12); assertContainsContainer(results, "container1"); assertContainsContainer(results, "container2"); assertContainsContainer(results, "container3"); assertContainsContainer(results, "container4"); assertContainsContainer(results, "container5"); assertContainsContainer(results, "container6"); assertContainsContainer(results, "container7"); assertContainsContainer(results, "container8"); assertContainsContainer(results, "container9"); assertContainsContainer(results, "container10"); assertContainsContainer(results, "container11"); assertContainsContainer(results, "container12"); }