Search in sources :

Example 11 with ApplicationNode

use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.

the class ApplicationServiceBeanTest method testGetApplicationsMultiChildDependencies.

/**
     * Tests the {@link ApplicationServiceBean#getApplications()} method for the case where
     * more than one child node has dependencies
     *
     * @throws Exception
     */
@Test
public void testGetApplicationsMultiChildDependencies() throws Exception {
    setUpTree();
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    serviceBean.init();
    ApplicationNode testNode4 = mock(ApplicationNodeImpl.class);
    when(testNode4.getApplication()).thenReturn(testApp);
    when(testNode4.getStatus()).thenReturn(testStatus);
    Set<ApplicationNode> testNode1ChildrenSet = new TreeSet<>();
    testNode1ChildrenSet.add(testNode2);
    testNode1ChildrenSet.add(testNode4);
    when(testNode1.getChildren()).thenReturn(testNode1ChildrenSet);
    List<Map<String, Object>> result = serviceBean.getApplications();
    assertThat("Should return the applications set up previously.", (String) result.get(0).get("name"), is(TEST_APP_NAME));
    assertThat("Size of root should be three.", result.size(), is(3));
}
Also used : TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 12 with ApplicationNode

use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.

the class ApplicationServiceBeanTest method testGetApplicationsChildDependencies.

/**
     * Tests the {@link ApplicationServiceBean#getApplications()} method for the case where
     * a child node has dependencies
     *
     * @throws Exception
     */
@Test
public void testGetApplicationsChildDependencies() throws Exception {
    setUpTree();
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    serviceBean.init();
    ApplicationNode testNode4 = mock(ApplicationNodeImpl.class);
    when(testNode4.getApplication()).thenReturn(testApp);
    when(testNode4.getStatus()).thenReturn(testStatus);
    Set<ApplicationNode> testNode3ChildrenSet = new TreeSet<>();
    testNode3ChildrenSet.add(testNode4);
    when(testNode3.getChildren()).thenReturn(testNode3ChildrenSet);
    List<Map<String, Object>> result = serviceBean.getApplications();
    assertThat("Should return the applications set up previously.", (String) result.get(0).get("name"), is(TEST_APP_NAME));
    assertThat("Size of root should be three.", result.size(), is(3));
}
Also used : TreeSet(java.util.TreeSet) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 13 with ApplicationNode

use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.

the class ApplicationNodeImplTest method testHashCode.

/**
     * Tests the {@link ApplicationNodeImpl#hashCode()} method
     */
@Test
public void testHashCode() {
    try {
        Repository testRepo = new RepositoryImpl(ApplicationNodeImpl.class.getClassLoader().getResource(FEATURES_FILE_NAME).toURI());
        Application testApp = new ApplicationImpl(testRepo);
        ApplicationNode testNode = new ApplicationNodeImpl(testApp);
        assertEquals(testApp.hashCode(), testNode.hashCode());
    } catch (Exception e) {
        LOGGER.info("Exception: ", e);
        fail();
    }
}
Also used : Repository(org.apache.karaf.features.Repository) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 14 with ApplicationNode

use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.

the class TreeApplicationCommand method printNode.

private void printNode(ApplicationNode appNode, String appender) {
    PrintStream console = System.out;
    String appendStr = appender;
    console.println(appendStr + "+- " + appNode.getApplication().getName());
    appendStr += "|   ";
    for (ApplicationNode curChild : appNode.getChildren()) {
        printNode(curChild, appendStr);
    }
}
Also used : PrintStream(java.io.PrintStream) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode)

Example 15 with ApplicationNode

use of org.codice.ddf.admin.application.service.ApplicationNode in project ddf by codice.

the class ApplicationServiceBean method convertApplicationNode.

private Map<String, Object> convertApplicationNode(ApplicationNode application) {
    LOGGER.debug("Converting {} to a map", application.getApplication().getName());
    Map<String, Object> appMap = new HashMap<String, Object>();
    Application internalApplication = application.getApplication();
    appMap.put(MAP_NAME, internalApplication.getName());
    appMap.put(MAP_VERSION, internalApplication.getVersion());
    appMap.put(MAP_DESCRIPTION, internalApplication.getDescription());
    appMap.put(MAP_STATE, application.getStatus().getState().toString());
    appMap.put(MAP_URI, internalApplication.getURI().toString());
    List<Map<String, Object>> children = new ArrayList<Map<String, Object>>();
    for (ApplicationNode curNode : application.getChildren()) {
        children.add(convertApplicationNode(curNode));
    }
    appMap.put(MAP_CHILDREN, children);
    return appMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) Application(org.codice.ddf.admin.application.service.Application) HashMap(java.util.HashMap) Map(java.util.Map)

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