use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.
the class TreeApplicationCommandTest method testTreeApplicationCommand.
/**
* Tests the {@link TreeApplicationCommand} class and its associated methods
*
* @throws Exception
*/
@Test
public void testTreeApplicationCommand() throws Exception {
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
TreeApplicationCommand treeApplicationCommand = new TreeApplicationCommand();
Set<ApplicationNode> treeSet = new TreeSet<>();
ApplicationNode testNode1 = mock(ApplicationNodeImpl.class);
ApplicationNode testNode2 = mock(ApplicationNodeImpl.class);
treeSet.add(testNode1);
Set<ApplicationNode> childSet = new TreeSet<>();
childSet.add(testNode2);
Application testApp = mock(ApplicationImpl.class);
when(testApp.getName()).thenReturn("TestApp");
when(testNode1.getApplication()).thenReturn(testApp);
when(testNode2.getApplication()).thenReturn(testApp);
when(testNode2.getChildren()).thenReturn(new TreeSet<ApplicationNode>());
when(testNode1.getChildren()).thenReturn(childSet);
when(testAppService.getApplicationTree()).thenReturn(treeSet);
treeApplicationCommand.doExecute(testAppService);
verify(testAppService).getApplicationTree();
}
use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.
the class ApplicationNodeImplTest method testApplicationNodeImplConstructorAppParam.
/**
* Tests the {@link ApplicationNodeImpl#ApplicationNodeImpl(Application)} constructor
* for the case where the application exists
*/
@Test
public void testApplicationNodeImplConstructorAppParam() {
Application testApp = mock(Application.class);
ApplicationNode testNode = new ApplicationNodeImpl(testApp);
assertEquals(testApp, testNode.getApplication());
}
use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.
the class ApplicationNodeImplTest method testEqualsObjParam.
/**
* Tests the {@link ApplicationNodeImpl#equals(Object)} method for the case where the
* parameter is null, the parameter is the same object, the parameter is not an
* ApplicationNodeImpl object, and where the parameter is a different ApplicationNodeImpl
* which has the same application
*/
@Test
public void testEqualsObjParam() {
Application testApp = mock(Application.class);
ApplicationNode testNode = new ApplicationNodeImpl(testApp);
ApplicationNode testNode2 = new ApplicationNodeImpl(testApp);
// Case 1:
assertFalse(testNode.equals(null));
// Case 2:
assertTrue(testNode.equals(testNode));
// Case 3:
assertFalse(testNode.equals(testApp));
// Case 4:
assertTrue(testNode.equals(testNode2));
}
use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.
the class ApplicationServiceImpl method getApplicationTree.
@Override
public Set<ApplicationNode> getApplicationTree() {
Set<ApplicationNode> applicationTree = new TreeSet<ApplicationNode>();
Set<Application> unfilteredApplications = getApplications();
Set<Application> filteredApplications = new HashSet<Application>();
for (Application application : unfilteredApplications) {
if (!ignoredApplicationNames.contains(application.getName())) {
filteredApplications.add(application);
}
}
Map<Application, ApplicationNodeImpl> appMap = new HashMap<Application, ApplicationNodeImpl>(filteredApplications.size());
// add all values into a map
for (Application curApp : filteredApplications) {
appMap.put(curApp, new ApplicationNodeImpl(curApp, getApplicationStatus(curApp)));
}
// The boolean is used because this function is used twice in a row.
// The proper output should be that of the second call rather than the first.
traverseDependencies(appMap, filteredApplications, false);
traverseDependencies(appMap, filteredApplications, true);
// determine the root applications (contain no parent) and return those
for (Entry<Application, ApplicationNodeImpl> curAppNode : appMap.entrySet()) {
if (curAppNode.getValue().getParent() == null) {
LOGGER.debug("Adding {} as a root application.", curAppNode.getKey().getName());
applicationTree.add(curAppNode.getValue());
}
}
return applicationTree;
}
use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.
the class ApplicationServiceImplTest method testApplicationTree.
/**
* Tests that an application tree is passed back correctly.
*
* @throws Exception
*/
@Test
public void testApplicationTree() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<ApplicationNode> rootApps = appService.getApplicationTree();
assertNotNull(rootApps);
assertEquals(1, rootApps.size());
ApplicationNode mainAppNode = rootApps.iterator().next();
assertEquals(1, mainAppNode.getChildren().size());
assertNull(mainAppNode.getParent());
assertEquals("main-feature2", mainAppNode.getChildren().iterator().next().getApplication().getName());
assertEquals(mainAppNode, mainAppNode.getChildren().iterator().next().getParent());
Application mainApp = mainAppNode.getApplication();
assertEquals("main-feature", mainApp.getName());
}
Aggregations