You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Daniel Platon <dp...@gmail.com> on 2020/01/28 14:31:24 UTC
[CaConfig][OSGI Mocks] Provide custom configuration for the CaConfig components...
Hi everyone,
I'm trying to use the "Apache Sling Context-Aware Configuration Mock
Plugin" in my unit tests and I stumbled into an issue: I want to
provide a custom configuration for
org.apache.sling.caconfig.impl.ConfigurationResolverImpl and it
doesn't work.
I followed the docs at [0] to provide my own setting for
configBucketNames but it's not taken into account. I'm pretty sure I
do something wrong but I cannot figure out what.
Relevant code at [1].
Thank you and have a nice day,
___________________________
Daniel Platon
[0] https://sling.apache.org/documentation/development/osgi-mock.html#provide-your-own-configuration-via-configadmin
[1] https://github.com/adobe/aem-core-cif-components/blob/e0261af7964877b75143b922e09c54e8b33a584c/bundles/core/src/test/java/com/adobe/cq/commerce/core/components/client/MagentoGraphqlClientTest.java#L72
RE: [CaConfig][OSGI Mocks] Provide custom configuration for the
CaConfig components...
Posted by Daniel Platon <dp...@gmail.com>.
Hi Stefan,
Thanks a lot for your input, in fixed the problem. I guessed that it
had something to do with the configurations not being refreshed, so I
was really looking for a "beforeSetup" hook.
Thank you again,
Daniel
--
Sent from: http://apache-sling.73963.n3.nabble.com/Sling-Dev-f73966.html
RE: [CaConfig][OSGI Mocks] Provide custom configuration for the
CaConfig components...
Posted by Stefan Seifert <ss...@pro-vision.de>.
the problem is that the reconfiguration is done too late, and the service is already instantiated and the configuration not updated.
sling mocks/osgi mocks currently only supports providing configuration before the service is registered.
if you put your configuration code in a beforeSetup block of the context initialization instead of the setUp() method it should work - example:
@Rule
public final AemContext context = new AemContextBuilder(ResourceResolverType.JCR_MOCK)
.plugin(ContextPlugins.CACONFIG)
.beforeSetUp(context -> {
ConfigurationAdmin configurationAdmin = context.getService(ConfigurationAdmin.class);
Configuration serviceConfiguration = configurationAdmin.getConfiguration(DefaultContextPathStrategy.class.getName());
Dictionary<String, Object> props = new Hashtable<>();
props.put("configRefResourceNames", new String[] { ".", "jcr:content" });
props.put("configRefPropertyNames", "cq:conf");
serviceConfiguration.update(props);
})
.build();
stefan
>-----Original Message-----
>From: Daniel Platon [mailto:dplaton@gmail.com]
>Sent: Tuesday, January 28, 2020 3:31 PM
>To: dev@sling.apache.org
>Subject: [CaConfig][OSGI Mocks] Provide custom configuration for the
>CaConfig components...
>
>Hi everyone,
>
>I'm trying to use the "Apache Sling Context-Aware Configuration Mock
>Plugin" in my unit tests and I stumbled into an issue: I want to
>provide a custom configuration for
>org.apache.sling.caconfig.impl.ConfigurationResolverImpl and it
>doesn't work.
>
>I followed the docs at [0] to provide my own setting for
>configBucketNames but it's not taken into account. I'm pretty sure I
>do something wrong but I cannot figure out what.
>
>Relevant code at [1].
>
>Thank you and have a nice day,
>___________________________
>Daniel Platon
>
>[0] https://sling.apache.org/documentation/development/osgi-
>mock.html#provide-your-own-configuration-via-configadmin
>[1] https://github.com/adobe/aem-core-cif-
>components/blob/e0261af7964877b75143b922e09c54e8b33a584c/bundles/core/src/t
>est/java/com/adobe/cq/commerce/core/components/client/MagentoGraphqlClientT
>est.java#L72