Search in sources :

Example 6 with ApplicationNode

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();
}
Also used : TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 7 with ApplicationNode

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());
}
Also used : ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 8 with ApplicationNode

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));
}
Also used : ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 9 with ApplicationNode

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;
}
Also used : HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet)

Example 10 with ApplicationNode

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());
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)17 Application (org.codice.ddf.admin.application.service.Application)11 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 HashSet (java.util.HashSet)5 Map (java.util.Map)5 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)4 Repository (org.apache.karaf.features.Repository)3 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)3 FeaturesService (org.apache.karaf.features.FeaturesService)2 SecurityServiceException (ddf.security.service.SecurityServiceException)1 PrintStream (java.io.PrintStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1 Dependency (org.apache.karaf.features.Dependency)1 Feature (org.apache.karaf.features.Feature)1 RepositoryImpl (org.apache.karaf.features.internal.service.RepositoryImpl)1 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)1