ComponentFilesImpl implements ComponentFiles { @Override public List<String> getPaths() { if (paths == null) { paths = new LinkedList<>(); try (ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, COMPONENTS_SERVICE))) { Set<String> seenResourceTypes = new HashSet<>(); for (String resourceType : resourceTypeSet) { addPaths(resourceType, paths, seenResourceTypes, resourceResolver); } } catch (LoginException e) { LOG.error("Cannot login as a service user", e); } } return paths; }  @PostConstruct void init(); @Override List<String> getPaths(); static final String COMPONENTS_SERVICE; }
@Test void testGetPathWithOneResourceType() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("core/wcm/components/accordion/v1/accordion"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = Objects.requireNonNull(getComponentFilesUnderTest(ROOT_PAGE, attributes)); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/accordion/v1/accordion/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); assertSame(componentFiles.getPaths(), componentFiles.getPaths()); }
@Test void testGetPathWithOneResourceTypeWithLoginException() throws Exception { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("core/wcm/components/accordion/v1/accordion"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = Objects.requireNonNull(getComponentFilesUnderTest(ROOT_PAGE, attributes)); ResourceResolverFactory factory = mock(ResourceResolverFactory.class); Mockito.doThrow(new LoginException()).when(factory).getServiceResourceResolver(anyMap()); ((ComponentFilesImpl) componentFiles).resolverFactory = factory; assertEquals(new LinkedList<>(), componentFiles.getPaths()); }
@Test void testGetPathWithOneResourceTypeAndInheritance() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("core/wcm/components/carousel/v2/carousel"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = getComponentFilesUnderTest(ROOT_PAGE, attributes); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/carousel/v1/carousel/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); }
@Test void testGetPathWithOneResourceTypeAndDoubleInheritance() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("core/wcm/components/carousel/v3/carousel"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = getComponentFilesUnderTest(ROOT_PAGE, attributes); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/carousel/v1/carousel/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); }
@Test void testGetPathWithOneResourceTypeMultipleInheritanceAndOverride() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("core/wcm/components/carousel/v4/carousel"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = getComponentFilesUnderTest(ROOT_PAGE, attributes); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/carousel/v4/carousel/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); }
@Test void testGetPathWithMultipleResourceType() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet() {{ add("/apps/core/wcm/components/accordion/v1/accordion"); add("/apps/core/wcm/components/carousel/v2/carousel"); add("/apps/core/wcm/components/teaser/v1/teaser"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); }}; ComponentFiles componentFiles = getComponentFilesUnderTest(ROOT_PAGE, attributes); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/accordion/v1/accordion/customheadlibs.amp.html"); add("/apps/core/wcm/components/carousel/v1/carousel/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); }
@Test void testGetPathWithMultipleResourceTypesAndNoInheritance() { Map<String, Object> attributes = new HashMap<String, Object>() {{ put(ComponentFiles.OPTION_RESOURCE_TYPES, new LinkedHashSet<String>() {{ add("/apps/core/wcm/components/accordion/v1/accordion"); add("/apps/core/wcm/components/carousel/v2/carousel"); add("/apps/core/wcm/components/teaser/v1/teaser"); }}); put(ComponentFiles.OPTION_FILTER_REGEX, "customheadlibs\\.amp\\.html"); put(ComponentFiles.OPTION_INHERITED, false); }}; ComponentFiles componentFiles = getComponentFilesUnderTest(ROOT_PAGE, attributes); List<String> expected = new LinkedList<String>() {{ add("/apps/core/wcm/components/accordion/v1/accordion/customheadlibs.amp.html"); }}; assertEquals(expected, componentFiles.getPaths()); }