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);
}
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"));
}
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);
}
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);
}
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
}
Aggregations