FeatureLoader implements IFeatureLoader { @Override public IFeatureStatus loadGroup(final IPath groupPath) throws FeatureLoadException { try { FeatureStatusImpl metaFeatureStatus = getFeatureStatus0("group@" + groupPath.getPath()); if (metaFeatureStatus.isInitialized()) { return metaFeatureStatus; } Set<FeatureStatusImpl> statuses = new HashSet<>(); for (IPath path : fs.listSubdirectories(groupPath)) { FeatureStatusImpl status = loadFeature0(path); statuses.add(status); statuses.addAll(status.getDependencies()); } for (FeatureStatusImpl dependencyStatus : statuses) { if (!dependencyStatus.isInitialized()) { throw new FeatureLoadException( MessageFormat.format("Feature named {0} not found.", dependencyStatus.getId())); } metaFeatureStatus.addDependency(dependencyStatus); } metaFeatureStatus.init(groupPath, IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"))); preStartProcess(metaFeatureStatus); for (FeatureStatusImpl status : statuses) { status.load(); } metaFeatureStatus.load(); return metaFeatureStatus; } catch (IOException | FeatureLoadException | ActionExecuteException | ResolutionException e) { throw new FeatureLoadException( MessageFormat.format("Error occurred loading features from ''{0}''.", groupPath.getPath()), e); } } FeatureLoader(); @Override IFeatureStatus loadGroup(final IPath groupPath); @Override IFeatureStatus loadFeature(final IPath featurePath); @Override IFeatureStatus getFeatureStatus(final String featureId);  }
@Test public void Should_loadFeatureGroup_justReturnStatusIfItIsAlreadyInitialized() throws Exception { when(featureStatusMock1.isInitialized()).thenReturn(true); IPath pathMock = mock(IPath.class); FeatureLoader featureLoader = new FeatureLoader(); IFeatureStatus status = featureLoader.loadGroup(pathMock); assertSame(featureStatusMock1, status); verify(featureStatusMock1).isInitialized(); verifyNoMoreInteractions(featureStatusMock1); }
@Test public void Should_loadFeatureGroup_loadFeaturesFromDirectory() throws Exception { IPath groupPathMock = mock(IPath.class); IPath featurePathMock = mock(IPath.class); IPath featureConfigPathMock = mock(IPath.class); when(filesystemFacadeMock.listSubdirectories(same(groupPathMock))).thenReturn(Collections.singletonList(featurePathMock)); when(filesystemFacadeMock.joinPaths(same(featurePathMock), eq(new Path("config.json")))).thenReturn(featureConfigPathMock); when(featureConfigurationMock1.getValue(featureNameFN)).thenReturn("feature1"); when(featureConfigurationMock1.getValue(afterFeaturesFN)).thenReturn(Collections.emptyList()); when(IOC.resolve(same(iobjectKey))) .thenReturn(metafeatureConfigMock) .thenThrow(ResolutionException.class); when(IOC.resolve(same(featureStatusKey), any(), any())) .thenReturn(featureStatusMock1) .thenReturn(featureStatusMock2) .thenThrow(ResolutionException.class); when(IOC.resolve(same(configurationObjectKey), any())) .thenReturn(featureConfigurationMock1) .thenReturn(featureConfigurationMock2) .thenThrow(ResolutionException.class); when(IOC.resolve(same(pluginLoaderKey), any(), any(), any())) .thenReturn(pluginLoaderMock) .thenReturn(pluginLoaderMock) .thenThrow(ResolutionException.class); doAnswer(invocationOnMock -> { when(featureStatusMock2.isInitialized()).thenReturn(true); return null; }).when(featureStatusMock2).init(any(), any()); FeatureLoader featureLoader = new FeatureLoader(); IFeatureStatus status = featureLoader.loadGroup(groupPathMock); assertSame(featureStatusMock1, status); }