sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seifert <sseif...@pro-vision.de>
Subject RE: [CaConfig][OSGI Mocks] Provide custom configuration for the CaConfig components...
Date Tue, 28 Jan 2020 21:19:18 GMT
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

Mime
View raw message