ExternalComponentLoaderImpl implements ExternalComponentLoader { @Override public List<ExternalComponent> load() { if (!isExternalComponentEnabled) { return Collections.emptyList(); } try (Stream<Path> walker = Files.walk(Paths.get(externalComponentsDir), 1)) { return walker.filter(p -> p.toFile().isDirectory()) .map(this::getComponentDescriptor) .filter(File::exists) .map(this::readComponent) .filter(Objects::nonNull) .collect(Collectors.toList()); } catch (IOException e) { logger.error("Error loading components from {}. Error: {}", externalComponentsDir, e.getMessage()); logger.debug("Error loading external components.", e); } return Collections.emptyList(); }  @PostConstruct void init(); @Override List<ExternalComponent> load(); @Override String getExternalComponentsDir(); boolean isEnabled(); static final String EXTERNAL_COMP_DIR_PROP; static final String EXTERNAL_COMP_ENABLE_PROP; static final String DESCRIPTOR_FILE; }
@Test public void testLoad() { externalComponentLoaderImpl.init(); createComponentsFiles(); List<ExternalComponent> components = externalComponentLoaderImpl.load(); assertEquals(2, components.size()); ExternalComponent c1 = getComponent(components, C1_ID); ExternalComponent c2 = getComponent(components, C2_ID); assertEquals(1, c1.getParameters().size()); assertEquals(C1, c1.getName()); assertEquals(C1_ICON, c1.getIcon()); ComponentParameter cp1 = c1.getParameters().get(0); assertEquals(C1P1, cp1.getName()); assertEquals(C1P1_DEFAULT, cp1.getDefaultValue()); assertEquals(C1P1_LABEL, cp1.getLabel()); assertEquals(1, c2.getParameters().size()); assertEquals(C2, c2.getName()); assertEquals(C2_ICON, c2.getIcon()); ComponentParameter cp2 = c2.getParameters().get(0); assertEquals(C2P1, cp2.getName()); assertEquals(C2P1_DEFAULT, cp2.getDefaultValue()); assertEquals(C2P1_LABEL, cp2.getLabel()); }