List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java
/** * Tests the {@link AdminConsoleService#update(String, Map)} and {@link * AdminConsoleService#updateForLocation(String, String, Map)} methods and verifies when * attempting to update a password with "password", it will not update it. * * @throws Exception//w w w .j av a2 s .c o m */ @Test public void testUpdatePasswordWithPassword() throws Exception { AdminConsoleService configAdmin = getConfigAdmin(); // Initialize password to "secret". Dictionary<String, Object> currentProps = new Hashtable<>(); currentProps.put("TestKey_0_12", "secret"); when(testConfig.getProperties()).thenReturn(currentProps); // Attempt updating the password with "password", the password should not actually update. Hashtable<String, Object> values = new Hashtable<>(); values.put("TestKey_0_12", "password"); ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class); configAdmin.update(TEST_PID, values); verify(testConfig, times(1)).update(captor.capture()); // Assert the password did not update to "password". assertThat(captor.getValue().get("TestKey_0_12"), equalTo("secret")); }
From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java
/** * Tests the {@link AdminConsoleService#disableConfiguration(String)} method for the case where * the source is already disabled/*from ww w . j a va2 s . co m*/ * * @throws Exception */ @Test(expected = Exception.class) public void testDisableConfigurationsAlreadyDisabled() throws Exception { org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class); AdminConsoleService configAdmin = new AdminConsoleService(testConfigAdmin, configurationAdminImpl); Configuration testConfig = mock(Configuration.class); Configuration testFactoryConfig = mock(Configuration.class); Dictionary<String, Object> testProperties = new Hashtable<>(); testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACT_PID_DISABLED); when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')')) .thenReturn(new Configuration[] { testConfig }); when(testConfig.getProperties()).thenReturn(testProperties); when(testFactoryConfig.getPid()).thenReturn(TEST_FACT_PID_DISABLED); configAdmin.disableConfiguration(TEST_PID); }
From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java
/** * Tests the {@link AdminConsoleService#enableConfiguration(String)} method for the case where the * configuration is already enabled//from w w w. jav a2 s. c o m * * @throws Exception */ @Test(expected = IOException.class) public void testEnableConfigurationsAlreadyEnabled() throws Exception { org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class); AdminConsoleService configAdmin = new AdminConsoleService(testConfigAdmin, configurationAdminImpl) { @Override public boolean isPermittedToViewService(String servicePid) { return true; } }; Configuration testConfig = mock(Configuration.class); Configuration testFactoryConfig = mock(Configuration.class); Dictionary<String, Object> testProperties = new Hashtable<>(); testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACTORY_PID); when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')')) .thenReturn(new Configuration[] { testConfig }); when(testConfig.getProperties()).thenReturn(testProperties); when(testFactoryConfig.getPid()).thenReturn(TEST_FACTORY_PID); when(testConfigAdmin.createFactoryConfiguration(TEST_FACTORY_PID, null)).thenReturn(testFactoryConfig); configAdmin.enableConfiguration(TEST_PID); }
From source file:ddf.catalog.test.TestCatalog.java
@Test public void testIngestPlugin() throws Exception { //ingest a data set to make sure we don't have any issues initially String id1 = ingestGeoJson(Library.getSimpleGeoJson()); String xPath1 = String.format(METACARD_X_PATH, id1); //verify ingest by querying ValidatableResponse response = executeOpenSearch("xml", "q=*"); response.body(hasXPath(xPath1));/*from ww w. j a va 2 s . c om*/ //change ingest plugin role to ingest IngestProperties ingestProperties = new IngestProperties(); ingestProperties.put("permissionStrings", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=ingest" }); Configuration config = configAdmin.getConfiguration("ddf.catalog.security.ingest.IngestPlugin", null); Dictionary<String, Object> configProps = new Hashtable<>(ingestProperties); config.update(configProps); waitForAllBundles(); //try ingesting again - it should fail this time given().body(Library.getSimpleGeoJson()).header("Content-Type", "application/json").expect().log().all() .statusCode(500).when().post(REST_PATH.getUrl()); //verify query for first id works response = executeOpenSearch("xml", "q=*"); response.body(hasXPath(xPath1)); //revert to original configuration configProps.put("permissionStrings", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=anonymous" }); config.update(configProps); waitForAllBundles(); deleteMetacard(id1); }
From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java
private AdminConsoleService getConfigAdmin() throws IOException, InvalidSyntaxException, NotCompliantMBeanException { final BundleContext testBundleContext = mock(BundleContext.class); final MetaTypeService testMTS = mock(MetaTypeService.class); ConfigurationAdminImpl configurationAdminImpl = new ConfigurationAdminImpl(CONFIGURATION_ADMIN, new ArrayList<>()) { @Override// w w w . j a v a2s . c o m BundleContext getBundleContext() { return testBundleContext; } @Override MetaTypeService getMetaTypeService() { return testMTS; } @Override public boolean isPermittedToViewService(String servicePid) { return true; } @Override public boolean isPermittedToViewService(String servicePid, Subject subject) { return true; } }; AdminConsoleService configurationAdmin = new AdminConsoleService(CONFIGURATION_ADMIN, configurationAdminImpl) { @Override public boolean isPermittedToViewService(String servicePid) { return true; } }; configurationAdmin.setGuestClaimsHandlerExt(mockGuestClaimsHandlerExt); Dictionary<String, Object> testProp = new Hashtable<>(); testProp.put(TEST_KEY, TEST_VALUE); when(testConfig.getPid()).thenReturn(TEST_PID); when(testConfig.getFactoryPid()).thenReturn(TEST_FACTORY_PID); when(testConfig.getBundleLocation()).thenReturn(TEST_LOCATION); when(testConfig.getProperties()).thenReturn(testProp); Bundle testBundle = mock(Bundle.class); Dictionary bundleHeaders = mock(Dictionary.class); MetaTypeInformation testMTI = mock(MetaTypeInformation.class); ObjectClassDefinition testOCD = mock(ObjectClassDefinition.class); ServiceReference testRef1 = mock(ServiceReference.class); ServiceReference[] testServRefs = { testRef1 }; ArrayList<AttributeDefinition> attDefs = new ArrayList<>(); for (int cardinality : CARDINALITIES) { for (AdminConsoleService.TYPE type : AdminConsoleService.TYPE.values()) { AttributeDefinition testAttDef = mock(AttributeDefinition.class); when(testAttDef.getCardinality()).thenReturn(cardinality); when(testAttDef.getType()).thenReturn(type.getType()); when(testAttDef.getID()).thenReturn(getKey(cardinality, type)); attDefs.add(testAttDef); } } when(testRef1.getProperty(Constants.SERVICE_PID)).thenReturn(TEST_PID); when(testRef1.getBundle()).thenReturn(testBundle); when(testBundle.getLocation()).thenReturn(TEST_LOCATION); when(testBundle.getHeaders(anyString())).thenReturn(bundleHeaders); when(bundleHeaders.get(Constants.BUNDLE_NAME)).thenReturn(TEST_BUNDLE_NAME); when(testOCD.getName()).thenReturn(TEST_OCD); when(testOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)) .thenReturn(attDefs.toArray(new AttributeDefinition[attDefs.size()])); when(testMTI.getBundle()).thenReturn(testBundle); when(testMTI.getFactoryPids()).thenReturn(new String[] { TEST_FACTORY_PID }); when(testMTI.getPids()).thenReturn(new String[] { TEST_PID }); when(testMTI.getObjectClassDefinition(anyString(), anyString())).thenReturn(testOCD); when(testMTS.getMetaTypeInformation(testBundle)).thenReturn(testMTI); when(testBundleContext.getBundles()).thenReturn(new Bundle[] { testBundle }); when(CONFIGURATION_ADMIN.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig }); when(CONFIGURATION_ADMIN.getConfiguration(anyString(), anyString())).thenReturn(testConfig); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs); return configurationAdmin; }
From source file:org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.source.WfsSource.java
private MetacardTypeRegistration createFeatureMetacardTypeRegistration(FeatureTypeType featureTypeType, String ftName, XmlSchema schema) { FeatureMetacardType ftMetacard = new FeatureMetacardType(schema, featureTypeType.getName(), nonQueryableProperties != null ? Arrays.asList(nonQueryableProperties) : new ArrayList<String>(), Wfs20Constants.GML_3_2_NAMESPACE); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(Metacard.CONTENT_TYPE, new String[] { ftName }); LOGGER.debug("WfsSource {}: Registering MetacardType: {}", getId(), ftName); return new MetacardTypeRegistration(ftMetacard, props, featureTypeType.getDefaultCRS()); }
From source file:com.ibm.jaggr.core.impl.transport.AbstractHttpTransport.java
@Override public void initialize(IAggregator aggregator, IAggregatorExtension extension, IExtensionRegistrar reg) { this.aggregator = aggregator; resourcePathId = extension.getAttribute(IHttpTransportExtensionPoint.PATH_ATTRIBUTE); if (resourcePathId == null) { throw new IllegalArgumentException( IHttpTransportExtensionPoint.PATH_ATTRIBUTE + " attribute not specified for extension " + //$NON-NLS-1$ extension.getUniqueId()); }/*from w w w . j av a 2 s . co m*/ String comboUriStr = extension.getAttribute(IHttpTransportExtensionPoint.RESOURCESURI_ATTRIBUTE); if (comboUriStr == null) { throw new IllegalArgumentException(IHttpTransportExtensionPoint.RESOURCESURI_ATTRIBUTE + " attribute not specified for extension " + //$NON-NLS-1$ extension.getUniqueId()); } else { comboUri = URI.create(comboUriStr); } transportId = extension.getUniqueId(); URI featureListResourceUri = getFeatureListResourceUri(); // register a config listener so that we get notified of changes to // the server-side AMD config file. String name = aggregator.getName(); Dictionary<String, String> dict = new Hashtable<String, String>(); dict.put("name", name); //$NON-NLS-1$ serviceRegistrations .add(aggregator.getPlatformServices().registerService(IConfigModifier.class.getName(), this, dict)); dict = new Hashtable<String, String>(); dict.put("name", name); //$NON-NLS-1$ serviceRegistrations.add( aggregator.getPlatformServices().registerService(IShutdownListener.class.getName(), this, dict)); dict = new Hashtable<String, String>(); dict.put("name", aggregator.getName()); //$NON-NLS-1$ serviceRegistrations.add(aggregator.getPlatformServices() .registerService(IDependenciesListener.class.getName(), this, dict)); if (featureListResourceUri != null) { depsInitialized = new CountDownLatch(1); // Get first resource factory extension so we can add to beginning of list Iterable<IAggregatorExtension> resourceFactoryExtensions = aggregator .getExtensions(IResourceFactoryExtensionPoint.ID); IAggregatorExtension first = resourceFactoryExtensions.iterator().next(); // Register the featureMap resource factory Properties props = new Properties(); props.put("scheme", getComboUri().getScheme()); //$NON-NLS-1$ reg.registerExtension(newFeatureListResourceFactory(featureListResourceUri), props, new InitParams(Collections.<InitParam>emptyList()), IResourceFactoryExtensionPoint.ID, getTransportId(), first); } }
From source file:net.solarnetwork.node.settings.ca.CASettingsService.java
@SuppressWarnings("unchecked") @Override//from w w w . jav a 2s.c om public void updateSettings(SettingsCommand command) { // group all updates by provider+instance, to reduce the number of CA updates // when multiple settings are changed if (command.getProviderKey() == null) { Map<String, SettingsCommand> groups = new LinkedHashMap<String, SettingsCommand>(); for (SettingValueBean bean : command.getValues()) { String groupKey = bean.getProviderKey() + (bean.getInstanceKey() == null ? "" : bean.getInstanceKey()); SettingsCommand cmd = groups.get(groupKey); if (cmd == null) { cmd = new SettingsCommand(); cmd.setProviderKey(bean.getProviderKey()); cmd.setInstanceKey(bean.getInstanceKey()); groups.put(groupKey, cmd); } cmd.getValues().add(bean); } for (SettingsCommand cmd : groups.values()) { updateSettings(cmd); } return; } try { Configuration conf = getConfiguration(command.getProviderKey(), command.getInstanceKey()); Dictionary<String, Object> props = conf.getProperties(); if (props == null) { props = new Hashtable<String, Object>(); } for (SettingValueBean bean : command.getValues()) { String settingKey = command.getProviderKey(); String instanceKey = command.getInstanceKey(); if (instanceKey != null) { settingKey = getFactoryInstanceSettingKey(settingKey, instanceKey); } props.put(bean.getKey(), bean.getValue()); if (!bean.isTransient()) { settingDao.storeSetting(settingKey, bean.getKey(), bean.getValue()); } } if (conf != null && props != null) { if (command.getInstanceKey() != null) { props.put(OSGI_PROPERTY_KEY_FACTORY_INSTANCE_KEY, command.getInstanceKey()); } conf.update(props); } } catch (IOException e) { throw new RuntimeException(e); } catch (InvalidSyntaxException e) { throw new RuntimeException(e); } }
From source file:com.ibm.jaggr.core.impl.AbstractAggregatorImpl.java
/** * Registers the layer listener//from ww w . ja v a 2s .co m */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected void registerLayerListener() { Dictionary dict = new Properties(); dict.put("name", getName()); //$NON-NLS-1$ registrations.add(getPlatformServices().registerService(ILayerListener.class.getName(), new AggregatorLayerListener(this), dict)); }
From source file:org.pentaho.marketplace.domain.services.BasePluginService.java
private void removeFeatureFromKarafBoot(String featureName, String configurationPid, String propertyId) { ConfigurationAdmin configurationAdmin = this.getConfigurationAdmin(); Log logger = this.getLogger(); try {/*ww w . j ava 2 s . c o m*/ Configuration configuration = configurationAdmin.getConfiguration(configurationPid); Dictionary<String, Object> properties = configuration.getProperties(); if (properties == null) { logger.debug("Configuration " + configurationPid + " has no properties."); return; } String propertyValue = (String) properties.get(propertyId); if (propertyValue == null) { logger.debug("Property " + propertyId + " not set in configuration " + configurationPid + "."); return; } String newPropertyValue = propertyValue.replaceFirst("," + featureName, ""); if (!propertyValue.equals(newPropertyValue)) { properties.put(propertyId, newPropertyValue); configuration.update(properties); } } catch (IOException e) { logger.debug("Unable to access configuration " + configurationPid + "."); } }