public static void testConfigurableForNonPrimitives() { Map<String, String> p = new HashMap<String, String>(); C config = Configurable.createConfigurable(C.class, p); assertNull(config.port()); p.put("port", "10"); config = Configurable.createConfigurable(C.class, p); assertEquals(Integer.valueOf(10), config.port()); // property port is // not set }
@Activate @Modified protected void activate(Map<String, Object> properties) { _siteNavigationBreadcrumbWebTemplateConfiguration = Configurable.createConfigurable( SiteNavigationBreadcrumbWebTemplateConfiguration.class, properties); }
@Activate protected void activate(Map<String, Object> properties) { CMISRepositoryConfiguration cmisRepositoryConfiguration = Configurable.createConfigurable(CMISRepositoryConfiguration.class, properties); super.setCMISRepositoryConfiguration(cmisRepositoryConfiguration); }
@Before public void setUp() throws Exception { VelocityEngineConfiguration _velocityEngineConfiguration = Configurable.createConfigurable(VelocityEngineConfiguration.class, Collections.emptyMap()); _templateContextHelper = new MockTemplateContextHelper(); _velocityEngine = new VelocityEngine(); boolean cacheEnabled = false; ExtendedProperties extendedProperties = new FastExtendedProperties(); extendedProperties.setProperty( VelocityEngine.DIRECTIVE_IF_TOSTRING_NULLCHECK, String.valueOf(_velocityEngineConfiguration.directiveIfToStringNullCheck())); extendedProperties.setProperty( VelocityEngine.EVENTHANDLER_METHODEXCEPTION, LiferayMethodExceptionEventHandler.class.getName()); extendedProperties.setProperty( RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES, StringUtil.merge(_velocityEngineConfiguration.restrictedClasses())); extendedProperties.setProperty( RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES, StringUtil.merge(_velocityEngineConfiguration.restrictedPackages())); extendedProperties.setProperty(VelocityEngine.RESOURCE_LOADER, "liferay"); extendedProperties.setProperty( "liferay." + VelocityEngine.RESOURCE_LOADER + ".cache", String.valueOf(cacheEnabled)); extendedProperties.setProperty( "liferay." + VelocityEngine.RESOURCE_LOADER + ".resourceModificationCheckInterval", _velocityEngineConfiguration.resourceModificationCheckInterval() + ""); extendedProperties.setProperty( "liferay." + VelocityEngine.RESOURCE_LOADER + ".class", LiferayResourceLoader.class.getName()); extendedProperties.setProperty( VelocityEngine.RESOURCE_MANAGER_CLASS, LiferayResourceManager.class.getName()); extendedProperties.setProperty( "liferay." + VelocityEngine.RESOURCE_MANAGER_CLASS + ".resourceModificationCheckInterval", _velocityEngineConfiguration.resourceModificationCheckInterval() + ""); extendedProperties.setProperty( VelocityTemplateResourceLoader.class.getName(), _templateResourceLoader); extendedProperties.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, _velocityEngineConfiguration.logger()); extendedProperties.setProperty( VelocityEngine.RUNTIME_LOG_LOGSYSTEM + ".log4j.category", _velocityEngineConfiguration.loggerCategory()); extendedProperties.setProperty( RuntimeConstants.UBERSPECT_CLASSNAME, SecureUberspector.class.getName()); extendedProperties.setProperty( VelocityEngine.VM_LIBRARY, StringUtil.merge(_velocityEngineConfiguration.velocimacroLibrary())); extendedProperties.setProperty( VelocityEngine.VM_LIBRARY_AUTORELOAD, String.valueOf(!cacheEnabled)); extendedProperties.setProperty( VelocityEngine.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, String.valueOf(!cacheEnabled)); _velocityEngine.setExtendedProperties(extendedProperties); _velocityEngine.init(); }
public static void testEnum() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml"); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); Properties p = new Properties(); p.setProperty("r", "requireConfiguration"); p.setProperty("i", "ignoreConfiguration"); p.setProperty("o", "optionalConfiguration"); Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p); assertEquals(Enums.X.requireConfiguration, enums.r()); assertEquals(Enums.X.ignoreConfiguration, enums.i()); assertEquals(Enums.X.optionalConfiguration, enums.o()); }
public static void testConfigurable() { Map<String, Object> ht = new Hashtable<String, Object>(); DefaultBoolean db = Configurable.createConfigurable(DefaultBoolean.class, ht); assertTrue(db.istrue()); assertFalse(db.isfalse()); assertFalse(db.isAlsoFalse()); }
static <T> T set(Class<T> interf, Object value) { Properties p = new Properties(); Method ms[] = interf.getMethods(); for (Method m : ms) { p.put(m.getName(), value); } return Configurable.createConfigurable(interf, (Map<Object, Object>) p); }
@Activate public void activate(BundleContext context, Map<String, Object> properties) { config = Configurable.createConfigurable(Config.class, properties); writer = new ElasticSearchWriter( fpContext, config.writeDelay(), config.elasticSearchIndexName(), config.elasticSearchServerURL()); }
@Activate @Modified protected void activate(Map<String, Object> properties) { IndexWriterHelperConfiguration indexWriterHelperConfiguration = Configurable.createConfigurable(IndexWriterHelperConfiguration.class, properties); _commitImmediately = indexWriterHelperConfiguration.indexCommitImmediately(); _indexReadOnly = indexWriterHelperConfiguration.indexReadOnly(); }
@Override public synchronized void unregisterConfiguration(Configuration configuration) { Dictionary<String, Object> properties = configuration.getProperties(); T configurable = Configurable.createConfigurable(getMetatype(), properties); long companyId = configurable.companyId(); _configurations.remove(companyId); }
public static void testSpecialConversions() throws URISyntaxException { Properties p = new Properties(); p.put("enumv", "A"); p.put("pattern", ".*"); p.put("clazz", "java.lang.Object"); p.put("constructor", "http://www.aQute.biz"); SpecialConversions trt = Configurable.createConfigurable(SpecialConversions.class, (Map<Object, Object>) p); assertEquals(SpecialConversions.X.A, trt.enumv()); assertEquals(".*", trt.pattern().pattern()); assertEquals(Object.class, trt.clazz()); assertEquals(new URI("http://www.aQute.biz"), trt.constructor()); }
@Activate @Modified protected void activate(Map<String, Object> properties) { _velocityEngineConfiguration = Configurable.createConfigurable(VelocityEngineConfiguration.class, properties); _defaultTemplateResourceLoader = new DefaultTemplateResourceLoader( TemplateConstants.LANG_TYPE_VM, _velocityEngineConfiguration.resourceParsers(), _velocityEngineConfiguration.resourceModificationCheckInterval(), _multiVMPool, _singleVMPool); }
@Activate protected void activate(Map<String, Object> properties) { _fileSystemStoreConfiguration = Configurable.createConfigurable(FileSystemStoreConfiguration.class, properties); if (Validator.isBlank(_fileSystemStoreConfiguration.rootDir())) { throw new IllegalArgumentException( "File system root directory is not set", new FileSystemStoreRootDirException()); } validate(); initializeRootDir(); }
@Activate @Modified protected void activate(ComponentContext componentContext) { _freemarkerEngineConfiguration = Configurable.createConfigurable( FreeMarkerEngineConfiguration.class, componentContext.getProperties()); BundleContext bundleContext = componentContext.getBundleContext(); _bundle = bundleContext.getBundle(); BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class); _classLoader = bundleWiring.getClassLoader(); }
@Activate @Modified protected void activate(Map<String, Object> properties) { _ntlmConfiguration = Configurable.createConfigurable(NtlmConfiguration.class, properties); for (Map.Entry<String, Object> entry : properties.entrySet()) { String key = entry.getKey(); if (key.contains("jcifs.")) { String value = (String) entry.getValue(); Config.setProperty(key, value); } } }
@Activate @Modified protected void activate(Map<String, Object> properties) { PluginRepositoriesConfiguration pluginRepositoriesConfiguration = Configurable.createConfigurable(PluginRepositoriesConfiguration.class, properties); if (!pluginRepositoriesConfiguration.enabled()) { return; } schedulerEntryImpl.setTrigger( TriggerFactoryUtil.createTrigger( getEventListenerClass(), getEventListenerClass(), pluginRepositoriesConfiguration.interval(), pluginRepositoriesConfiguration.timeUnit())); _schedulerEngineHelper.register(this, schedulerEntryImpl, DestinationNames.SCHEDULER_DISPATCH); }
public static void testNaming() throws Exception { Map<String, Object> map = Create.map(); map.put("_secret", "_secret"); map.put("_secret", "_secret"); map.put(".secret", ".secret"); map.put("$new", "$new"); map.put("new", "new"); map.put("secret", "secret"); map.put("a_b_c", "a_b_c"); map.put("a.b.c", "a.b.c"); map.put(".a_b", ".a_b"); map.put("$$$$a_b", "$$$$a_b"); map.put("$$$$a.b", "$$$$a.b"); map.put("a", "a"); map.put("a$", "a$"); map.put("a$$", "a$$"); map.put("a$.$", "a$.$"); map.put("a$_$", "a$_$"); map.put("a..", "a.."); map.put("noid", "noid"); map.put("nullid", "nullid"); Naming trt = Configurable.createConfigurable(Naming.class, map); // By name assertEquals("secret", trt.secret()); assertEquals("_secret", trt.__secret()); assertEquals(".secret", trt._secret()); assertEquals("new", trt.$new()); assertEquals("$new", trt.$$new()); assertEquals("a.b.c", trt.a_b_c()); assertEquals("a_b_c", trt.a__b__c()); assertEquals(".a_b", trt._a__b()); assertEquals("$$$$a.b", trt.$$$$$$$$a_b()); assertEquals("$$$$a_b", trt.$$$$$$$$a__b()); assertEquals("a", trt.a$()); assertEquals("a$", trt.a$$()); assertEquals("a$", trt.a$$$()); assertEquals("a$.$", trt.a$$_$$()); assertEquals("a$_$", trt.a$$__$$()); assertEquals("a..", trt.a_$_()); assertEquals("noid", trt.noid()); assertEquals("nullid", trt.nullid()); // By AD assertEquals("secret", trt.xsecret()); assertEquals("_secret", trt.x__secret()); assertEquals(".secret", trt.x_secret()); assertEquals("new", trt.x$new()); assertEquals("$new", trt.x$$new()); assertEquals("a.b.c", trt.xa_b_c()); assertEquals("a_b_c", trt.xa__b__c()); assertEquals(".a_b", trt.x_a__b()); assertEquals("$$$$a.b", trt.x$$$$$$$$a_b()); assertEquals("$$$$a_b", trt.x$$$$$$$$a__b()); assertEquals("a", trt.xa$()); assertEquals("a$", trt.xa$$()); assertEquals("a$", trt.xa$$$()); assertEquals("a$.$", trt.xa$$_$$()); Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Naming.xml"); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream(), "UTF-8"); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); }
@Activate @Modified protected void activate(Map<String, Object> properties) { elasticsearchConfiguration = Configurable.createConfigurable(ElasticsearchConfiguration.class, properties); }