use of java.util.Dictionary in project ddf by codice.
the class ConfigurationAdminTest method getConfigAdmin.
private ConfigurationAdmin getConfigAdmin() throws IOException, InvalidSyntaxException {
final BundleContext testBundleContext = mock(BundleContext.class);
final MetaTypeService testMTS = mock(MetaTypeService.class);
ConfigurationAdminExt configurationAdminExt = new ConfigurationAdminExt(CONFIGURATION_ADMIN) {
@Override
BundleContext getBundleContext() {
return testBundleContext;
}
@Override
MetaTypeService getMetaTypeService() {
return testMTS;
}
@Override
public boolean isPermittedToViewService(String servicePid) {
return true;
}
};
ConfigurationAdmin configurationAdmin = new ConfigurationAdmin(CONFIGURATION_ADMIN, configurationAdminExt);
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 (TYPE type : 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;
}
use of java.util.Dictionary in project ddf by codice.
the class ConfigurationAdminTest method testUpdate.
/**
* Tests the {@link ConfigurationAdmin#update(String, Map)} and
* {@link ConfigurationAdmin#updateForLocation(String, String, Map)} methods
*
* @throws Exception
*/
@Test
public void testUpdate() throws Exception {
ConfigurationAdmin configAdmin = getConfigAdmin();
// test every typed cardinality<->cardinality mapping
for (int i = 0; i < CARDINALITIES.length; i++) {
int cardinality = CARDINALITIES[i];
Map<String, Object> testConfigTable = new Hashtable<>();
for (TYPE type : TYPE.values()) {
for (int keyCardinality : CARDINALITIES) {
testConfigTable.put(getKey(keyCardinality, type), getValue(cardinality, type));
}
}
configAdmin.update(TEST_PID, testConfigTable);
verify(testConfig, times(i + 1)).update(any(Dictionary.class));
}
Hashtable<String, Object> values = new Hashtable<>();
String arrayString = getKey(CARDINALITY_ARRAY, TYPE.STRING);
ArgumentCaptor<Dictionary> captor = ArgumentCaptor.forClass(Dictionary.class);
// test string jsonarray parsing
values.put(arrayString, "[\"foo\",\"bar\",\"baz\"]");
String primitiveBoolean = getKey(CARDINALITY_PRIMITIVE, TYPE.BOOLEAN);
// test string valueof parsing
values.put(primitiveBoolean, "true");
String primitiveInteger = getKey(CARDINALITY_PRIMITIVE, TYPE.INTEGER);
// test string valueof parsing for non-strings
values.put(primitiveInteger, (long) TEST_INT);
String arrayInteger = getKey(CARDINALITY_ARRAY, TYPE.INTEGER);
// test empty array substitution
values.put(arrayInteger, "");
configAdmin.update(TEST_PID, values);
verify(testConfig, times(4)).update(captor.capture());
assertThat(((String[]) captor.getValue().get(arrayString)).length, equalTo(3));
assertThat((Boolean) captor.getValue().get(primitiveBoolean), equalTo(true));
assertThat((int) captor.getValue().get(primitiveInteger), equalTo(TEST_INT));
assertThat(((Integer[]) captor.getValue().get(arrayInteger)).length, equalTo(0));
}
use of java.util.Dictionary in project sling by apache.
the class SlingServletResolverTest method setUp.
@Before
public void setUp() throws Exception {
mockResourceResolver = new MockResourceResolver() {
@Override
public void close() {
// nothing to do;
}
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return null;
}
@Override
public ResourceResolver clone(Map<String, Object> authenticationInfo) throws LoginException {
throw new LoginException("MockResourceResolver can't be cloned - excepted for this test!");
}
@Override
public void refresh() {
// nothing to do
}
};
mockResourceResolver.setSearchPath("/");
final ResourceResolverFactory factory = new ResourceResolverFactory() {
@Override
public ResourceResolver getAdministrativeResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
return mockResourceResolver;
}
@Override
public ResourceResolver getResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
return mockResourceResolver;
}
@Override
public ResourceResolver getServiceResourceResolver(Map<String, Object> authenticationInfo) throws LoginException {
return mockResourceResolver;
}
@Override
public ResourceResolver getThreadResourceResolver() {
// TODO Auto-generated method stub
return null;
}
};
servlet = new MockSlingRequestHandlerServlet();
servletResolver = new SlingServletResolver();
Class<?> resolverClass = servletResolver.getClass();
// set resource resolver factory
final Field resolverField = resolverClass.getDeclaredField("resourceResolverFactory");
resolverField.setAccessible(true);
resolverField.set(servletResolver, factory);
MockBundle bundle = new MockBundle(1L);
MockBundleContext bundleContext = new MockBundleContext(bundle) {
@Override
public ServiceRegistration registerService(String s, Object o, Dictionary dictionary) {
return null;
}
@Override
public ServiceRegistration registerService(String[] strings, Object o, Dictionary dictionary) {
return null;
}
};
MockServiceReference serviceReference = new MockServiceReference(bundle);
serviceReference.setProperty(Constants.SERVICE_ID, 1L);
serviceReference.setProperty(ServletResolverConstants.SLING_SERVLET_NAME, SERVLET_NAME);
serviceReference.setProperty(ServletResolverConstants.SLING_SERVLET_PATHS, SERVLET_PATH);
serviceReference.setProperty(ServletResolverConstants.SLING_SERVLET_EXTENSIONS, SERVLET_EXTENSION);
servletResolver.bindServlet(SlingServletResolverTest.this.servlet, serviceReference);
servletResolver.activate(bundleContext, new SlingServletResolver.Config() {
@Override
public Class<? extends Annotation> annotationType() {
return SlingServletResolver.Config.class;
}
@Override
public String servletresolver_servletRoot() {
return "0";
}
@Override
public String[] servletresolver_paths() {
return new String[] { "/" };
}
@Override
public String[] servletresolver_defaultExtensions() {
// TODO Auto-generated method stub
return new String[] { "html" };
}
@Override
public int servletresolver_cacheSize() {
return 200;
}
});
String path = "/" + MockSlingHttpServletRequest.RESOURCE_TYPE + "/" + ResourceUtil.getName(MockSlingHttpServletRequest.RESOURCE_TYPE) + ".servlet";
MockServletResource res = new MockServletResource(mockResourceResolver, servlet, path);
mockResourceResolver.addResource(res);
MockResource parent = new MockResource(mockResourceResolver, ResourceUtil.getParent(res.getPath()), "nt:folder");
mockResourceResolver.addResource(parent);
List<Resource> childRes = new ArrayList<>();
childRes.add(res);
mockResourceResolver.addChildren(parent, childRes);
}
use of java.util.Dictionary in project sling by apache.
the class DefaultXingOauthUserManager method configure.
protected synchronized void configure(final ComponentContext componentContext) {
final Dictionary properties = componentContext.getProperties();
autoCreateUser = PropertiesUtil.toBoolean(properties.get(AUTO_CREATE_USER_PARAMETER), DEFAULT_AUTO_CREATE_USER);
autoUpdateUser = PropertiesUtil.toBoolean(properties.get(AUTO_UPDATE_USER_PARAMETER), DEFAULT_AUTO_UPDATE_USER);
}
use of java.util.Dictionary in project sling by apache.
the class DefaultXingLoginUserManager method configure.
protected synchronized void configure(final ComponentContext componentContext) {
final Dictionary properties = componentContext.getProperties();
secretKey = PropertiesUtil.toString(properties.get(SECRET_KEY_PARAMETER), "").trim();
userDataProperty = PropertiesUtil.toString(properties.get(USER_DATA_PROPERTY_PARAMETER), DEFAULT_USER_DATA_PROPERTY).trim();
userHashProperty = PropertiesUtil.toString(properties.get(USER_HASH_PROPERTY_PARAMETER), DEFAULT_USER_HASH_PROPERTY).trim();
autoCreateUser = PropertiesUtil.toBoolean(properties.get(AUTO_CREATE_USER_PARAMETER), DEFAULT_AUTO_CREATE_USER);
autoUpdateUser = PropertiesUtil.toBoolean(properties.get(AUTO_UPDATE_USER_PARAMETER), DEFAULT_AUTO_UPDATE_USER);
if (StringUtils.isEmpty(secretKey)) {
logger.warn("configured secret key is empty");
}
}
Aggregations