Search in sources :

Example 61 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class CswSubscriptionEndpointTest method setUp.

@Before
public void setUp() throws Exception {
    systemKeystoreFile = temporaryFolder.newFile("serverKeystore.jks");
    FileOutputStream systemKeyOutStream = new FileOutputStream(systemKeystoreFile);
    InputStream systemKeyStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverKeystore.jks");
    IOUtils.copy(systemKeyStream, systemKeyOutStream);
    systemTruststoreFile = temporaryFolder.newFile("serverTruststore.jks");
    FileOutputStream systemTrustOutStream = new FileOutputStream(systemTruststoreFile);
    InputStream systemTrustStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverTruststore.jks");
    IOUtils.copy(systemTrustStream, systemTrustOutStream);
    System.setProperty(SecurityConstants.KEYSTORE_TYPE, "jks");
    System.setProperty(SecurityConstants.TRUSTSTORE_TYPE, "jks");
    System.setProperty("ddf.home", "");
    System.setProperty(SecurityConstants.KEYSTORE_PATH, systemKeystoreFile.getAbsolutePath());
    System.setProperty(SecurityConstants.TRUSTSTORE_PATH, systemTruststoreFile.getAbsolutePath());
    System.setProperty(SecurityConstants.KEYSTORE_PASSWORD, password);
    System.setProperty(SecurityConstants.TRUSTSTORE_PASSWORD, password);
    eventProcessor = mock(EventProcessor.class);
    mockInputManager = mock(TransformerManager.class);
    mockContext = mock(BundleContext.class);
    mockMimeTypeManager = mock(TransformerManager.class);
    mockSchemaManager = mock(TransformerManager.class);
    validator = mock(Validator.class);
    queryFactory = mock(CswQueryFactory.class);
    query = mock(QueryRequest.class);
    when(queryFactory.getQuery(any(GetRecordsType.class))).thenReturn(query);
    serviceRegistration = mock(ServiceRegistration.class);
    subscriptionReference = mock(ServiceReference.class);
    bundle = mock(Bundle.class);
    osgiFilter = mock(org.osgi.framework.Filter.class);
    configAdminRef = mock(ServiceReference.class);
    configAdmin = mock(ConfigurationAdmin.class);
    config = mock(Configuration.class);
    Configuration[] configArry = { config };
    defaultRequest = createDefaultGetRecordsRequest();
    subscription = new CswSubscription(mockMimeTypeManager, defaultRequest.get202RecordsType(), query);
    when(osgiFilter.toString()).thenReturn(FILTER_STR);
    doReturn(serviceRegistration).when(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
    doReturn(configAdminRef).when(mockContext).getServiceReference(eq(ConfigurationAdmin.class.getName()));
    when(serviceRegistration.getReference()).thenReturn(subscriptionReference);
    doReturn(bundle).when(subscriptionReference).getBundle();
    when(subscriptionReference.getBundle()).thenReturn(bundle);
    when(bundle.getBundleId()).thenReturn(bundleId);
    when(mockContext.createFilter(anyString())).thenReturn(osgiFilter);
    when(mockContext.getService(eq(configAdminRef))).thenReturn(configAdmin);
    when(mockContext.getService(eq(subscriptionReference))).thenReturn(subscription);
    when(configAdmin.listConfigurations(eq(FILTER_STR))).thenReturn(configArry);
    when(configAdmin.createFactoryConfiguration(anyString(), isNull(String.class))).thenReturn(config);
    cswSubscriptionEndpoint = new CswSubscriptionEndpointStub(eventProcessor, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockContext);
}
Also used : Dictionary(java.util.Dictionary) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) QueryRequest(ddf.catalog.operation.QueryRequest) Configuration(org.osgi.service.cm.Configuration) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) ServiceReference(org.osgi.framework.ServiceReference) Filter(org.osgi.framework.Filter) FileOutputStream(java.io.FileOutputStream) EventProcessor(ddf.catalog.event.EventProcessor) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Before(org.junit.Before)

Example 62 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class ApplicationServiceImplTest method testServiceChanged.

/**
     * Tests  the {@link ApplicationServiceImpl#setConfigFileName(String)} method
     *
     * @throws Exception
     */
@Test
public void testServiceChanged() throws Exception {
    Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    appService.setConfigFileName("foo");
    ServiceReference<ConfigurationAdmin> testConfigAdminRef = mock(ServiceReference.class);
    ConfigurationAdmin testConfigAdmin = mock(ConfigurationAdmin.class);
    Configuration testConfig = mock(Configuration.class);
    when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(testConfigAdminRef);
    when(bundleContext.getService(testConfigAdminRef)).thenReturn(testConfigAdmin);
    when(testConfigAdmin.getConfiguration(ApplicationServiceImpl.class.getName())).thenReturn(testConfig);
    Dictionary<String, Object> testProperties = new Hashtable<>();
    testProperties.put("test1", "foo");
    testProperties.put("test2", "bar");
    when(testConfig.getProperties()).thenReturn(testProperties);
    ServiceEvent serviceEvent = mock(ServiceEvent.class);
    when(serviceEvent.getType()).thenReturn(ServiceEvent.REGISTERED);
    appService.serviceChanged(serviceEvent);
    assertThat(testConfig.getProperties().size(), is(testProperties.size()));
    assertThat(testConfig.getProperties().get("test1"), is("foo"));
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Mockito.anyString(org.mockito.Mockito.anyString) Repository(org.apache.karaf.features.Repository) ServiceEvent(org.osgi.framework.ServiceEvent) FeaturesService(org.apache.karaf.features.FeaturesService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class SecurityTest method configureMocksForBundleContext.

private void configureMocksForBundleContext(String systemHostname) throws Exception {
    System.setProperty("org.codice.ddf.system.hostname", systemHostname);
    Bundle bundle = mock(Bundle.class);
    when(FrameworkUtil.getBundle(any(Class.class))).thenReturn(bundle);
    BundleContext bundleContext = mock(BundleContext.class);
    when(bundle.getBundleContext()).thenReturn(bundleContext);
    ServiceReference adminRef = mock(ServiceReference.class);
    ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
    Configuration config = mock(Configuration.class);
    when(configAdmin.getConfiguration(anyString(), anyString())).thenReturn(config);
    when(bundleContext.getService(adminRef)).thenReturn(configAdmin);
    ServiceReference securityRef = mock(ServiceReference.class);
    SecurityManager securityManager = mock(SecurityManager.class);
    when(securityManager.getSubject(any())).thenReturn(systemSubject);
    when(bundleContext.getService(securityRef)).thenReturn(securityManager);
    when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(adminRef);
    when(bundleContext.getServiceReference(SecurityManager.class)).thenReturn(securityRef);
}
Also used : Configuration(org.osgi.service.cm.Configuration) SecurityManager(ddf.security.service.SecurityManager) Bundle(org.osgi.framework.Bundle) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 64 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class TestRegistryReportActionProvider method setup.

@Before
public void setup() {
    metacard = new MetacardImpl();
    source = mock(Source.class);
    configurationAdmin = mock(ConfigurationAdmin.class);
    configuration = mock(Configuration.class);
    actionProvider = new RegistryReportActionProvider(ACTION_PROVIDER_ID);
    metacard.setId(SAMPLE_ID);
    metacard.setTags(SAMPLE_REGISTRY_TAGS);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, SAMPLE_REGISTRY_ID);
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Source(ddf.catalog.source.Source) Before(org.junit.Before)

Example 65 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class TestSingleSignOn method setConfig.

private void setConfig(String pid, String param, Object value) throws Exception {
    // Update the config
    Configuration config = getAdminConfig().getConfiguration(pid, null);
    // @formatter:off
    config.update(new Hashtable<String, Object>() {

        {
            put(param, value);
        }
    });
    // @formatter:on
    // We have to make sure the config has been updated before we can use it
    // @formatter:off
    expect("Configs to update").within(2, TimeUnit.MINUTES).until(() -> config.getProperties() != null && (config.getProperties().get(param) != null));
// @formatter:on
}
Also used : Configuration(org.osgi.service.cm.Configuration) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

Configuration (org.osgi.service.cm.Configuration)226 Test (org.junit.Test)85 Hashtable (java.util.Hashtable)75 IOException (java.io.IOException)55 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)49 Dictionary (java.util.Dictionary)36 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 ServiceReference (org.osgi.framework.ServiceReference)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)18 Matchers.anyString (org.mockito.Matchers.anyString)16 BundleContext (org.osgi.framework.BundleContext)15 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)11 Map (java.util.Map)10 Bundle (org.osgi.framework.Bundle)10 File (java.io.File)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Mockito.anyString (org.mockito.Mockito.anyString)9 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)8 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)7