Search in sources :

Example 1 with ServiceImpl

use of org.codice.ddf.admin.core.impl.ServiceImpl in project ddf by codice.

the class ApplicationServiceBeanTest method testGetServicesASE.

/**
 * Tests the {@link ApplicationServiceBean#getServices(String)} method for the case where an
 * ApplicationServiceException is thrown
 *
 * @throws Exception
 */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetServicesASE() throws Exception {
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    root.setLevel(Level.ALL);
    ApplicationServiceBean serviceBean = newApplicationServiceBean();
    Bundle testBundle = mock(Bundle.class);
    Bundle[] bundles = { testBundle };
    when(bundleContext.getBundles()).thenReturn(bundles);
    List<Service> services = new ArrayList<>();
    Service testService1 = new ServiceImpl();
    services.add(testService1);
    when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
    when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
    serviceBean.getServices(TEST_APP_NAME);
}
Also used : Appender(ch.qos.logback.core.Appender) Bundle(org.osgi.framework.Bundle) ServiceImpl(org.codice.ddf.admin.core.impl.ServiceImpl) ArrayList(java.util.ArrayList) SystemService(org.apache.karaf.system.SystemService) Service(org.codice.ddf.admin.core.api.Service) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) MetaTypeService(org.osgi.service.metatype.MetaTypeService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(org.slf4j.Logger) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 2 with ServiceImpl

use of org.codice.ddf.admin.core.impl.ServiceImpl in project ddf by codice.

the class ApplicationServiceBeanTest method testGetServices.

/**
 * Tests the {@link ApplicationServiceBean#getServices(String)} method
 *
 * @throws Exception
 */
@Test
public void testGetServices() throws Exception {
    ApplicationServiceBean serviceBean = newApplicationServiceBean();
    Bundle testBundle = mock(Bundle.class);
    Bundle[] bundles = { testBundle };
    when(bundleContext.getBundles()).thenReturn(bundles);
    List<Service> services = new ArrayList<>();
    Service testService1 = new ServiceImpl();
    List<Map<String, Object>> testService1Configs = new ArrayList<>();
    Map<String, Object> testConfig1 = new HashMap<>();
    testConfig1.put("bundle_location", TEST_LOCATION);
    testService1Configs.add(testConfig1);
    services.add(testService1);
    testService1.put("configurations", testService1Configs);
    BundleInfo testBundle1 = mock(BundleInfo.class);
    Set<BundleInfo> testBundles = new HashSet<>();
    testBundles.add(testBundle1);
    when(testApp.getBundles()).thenReturn(testBundles);
    when(testBundle1.getLocation()).thenReturn(TEST_LOCATION);
    when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
    when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
    assertThat("Should find the given services.", serviceBean.getServices(TEST_APP_NAME).get(0), is(testService1));
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) ServiceImpl(org.codice.ddf.admin.core.impl.ServiceImpl) ArrayList(java.util.ArrayList) SystemService(org.apache.karaf.system.SystemService) Service(org.codice.ddf.admin.core.api.Service) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) MetaTypeService(org.osgi.service.metatype.MetaTypeService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BundleInfo(org.apache.karaf.features.BundleInfo) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 SystemService (org.apache.karaf.system.SystemService)2 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)2 Service (org.codice.ddf.admin.core.api.Service)2 ServiceImpl (org.codice.ddf.admin.core.impl.ServiceImpl)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Bundle (org.osgi.framework.Bundle)2 MetaTypeService (org.osgi.service.metatype.MetaTypeService)2 Appender (ch.qos.logback.core.Appender)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BundleInfo (org.apache.karaf.features.BundleInfo)1 Logger (org.slf4j.Logger)1