use of org.apache.sling.caconfig.ConfigurationBuilder in project sling by apache.
the class ConfigurationResolverAdaptableTest method testAdaptToConfigurationBuilder.
@Test
public void testAdaptToConfigurationBuilder() {
context.build().resource("/conf/content/site1/sling:configs/sampleName");
// make sure not endless loop occurs
ConfigurationBuilder model = underTest.get(site1Page1).name("sampleName").asAdaptable(ConfigurationBuilder.class);
assertNull(model);
}
use of org.apache.sling.caconfig.ConfigurationBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImpl method getHtmlPageItems.
@Override
@NotNull
public List<HtmlPageItem> getHtmlPageItems() {
if (htmlPageItems == null) {
htmlPageItems = new LinkedList<>();
ConfigurationBuilder configurationBuilder = configurationResolver.get(resource);
HtmlPageItemsConfig config = configurationBuilder.as(HtmlPageItemsConfig.class);
for (HtmlPageItemConfig itemConfig : config.items()) {
HtmlPageItem item = new HtmlPageItemImpl(StringUtils.defaultString(config.prefixPath()), itemConfig);
if (item.getElement() != null) {
htmlPageItems.add(item);
}
}
// Support the former node structure: see com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig
if (htmlPageItems.isEmpty()) {
Resource configResource = configurationResourceResolver.getResource(resource, "sling:configs", HtmlPageItemsConfig.class.getName());
if (configResource != null) {
ValueMap properties = configResource.getValueMap();
for (Resource child : configResource.getChildren()) {
HtmlPageItem item = new HtmlPageItemImpl(properties.get(HtmlPageItemsConfig.PN_PREFIX_PATH, StringUtils.EMPTY), child);
if (item.getElement() != null) {
htmlPageItems.add(item);
}
}
}
}
}
return htmlPageItems;
}
use of org.apache.sling.caconfig.ConfigurationBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class Utils method enableDataLayer.
/**
* Sets the data layer context aware configuration of the AEM test context to enabled/disabled
*
* @param context The AEM test context
* @param enabled {@code true} to enable the data layer, {@code false} to disable it
*/
public static void enableDataLayer(AemContext context, boolean enabled) {
ConfigurationBuilder builder = Mockito.mock(ConfigurationBuilder.class);
DataLayerConfig dataLayerConfig = Mockito.mock(DataLayerConfig.class);
lenient().when(dataLayerConfig.enabled()).thenReturn(enabled);
lenient().when(builder.as(DataLayerConfig.class)).thenReturn(dataLayerConfig);
context.registerAdapter(Resource.class, ConfigurationBuilder.class, builder);
}
use of org.apache.sling.caconfig.ConfigurationBuilder in project sling by apache.
the class ConfigurationBuilderAdapterFactoryTest method testGetAdapter.
@Test
public void testGetAdapter() {
ConfigurationBuilder cfgBuilder = site1Page1.adaptTo(ConfigurationBuilder.class);
SimpleConfig cfg = cfgBuilder.as(SimpleConfig.class);
assertEquals("configValue1", cfg.stringParam());
assertEquals(111, cfg.intParam());
assertEquals(true, cfg.boolParam());
}
Aggregations