You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:16:46 UTC
[sling-org-apache-sling-testing-caconfig-mock-plugin] 01/13:
SLING-6360 Context-Aware Config: Sling Mock Context Plugin
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.testing.caconfig-mock-plugin-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-caconfig-mock-plugin.git
commit 38ec93112258e6fd196f050486c915175d49e291
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Sat Dec 3 16:17:53 2016 +0000
SLING-6360 Context-Aware Config: Sling Mock Context Plugin
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin@1772476 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 91 ++++++++++++++++
.../testing/mock/caconfig/ContextPlugins.java | 120 +++++++++++++++++++++
.../sling/testing/mock/caconfig/package-info.java | 23 ++++
.../testing/mock/caconfig/ContextPluginsTest.java | 68 ++++++++++++
4 files changed, 302 insertions(+)
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..e061212
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>29</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.testing.caconfig-mock-plugin</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache Sling Context-Aware Configuration Mock Plugin</name>
+ <description>Mock Context Plugin for Apache Sling Context-Aware Configuration</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.caconfig.api</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.caconfig.spi</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.caconfig.impl</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.9.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+ <version>2.1.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.sling-mock</artifactId>
+ <version>1.8.1-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java b/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
new file mode 100644
index 0000000..a9a74b3
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.caconfig;
+
+import org.apache.sling.caconfig.impl.ConfigurationBuilderAdapterFactory;
+import org.apache.sling.caconfig.impl.ConfigurationInheritanceStrategyMultiplexer;
+import org.apache.sling.caconfig.impl.ConfigurationResolverImpl;
+import org.apache.sling.caconfig.impl.def.DefaultConfigurationInheritanceStrategy;
+import org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy;
+import org.apache.sling.caconfig.impl.metadata.ConfigurationMetadataProviderMultiplexer;
+import org.apache.sling.caconfig.impl.override.ConfigurationOverrideManager;
+import org.apache.sling.caconfig.management.impl.ConfigurationManagerImpl;
+import org.apache.sling.caconfig.management.impl.ConfigurationPersistenceStrategyMultiplexer;
+import org.apache.sling.caconfig.management.impl.ContextPathStrategyMultiplexerImpl;
+import org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolverImpl;
+import org.apache.sling.caconfig.resource.impl.ConfigurationResourceResolvingStrategyMultiplexer;
+import org.apache.sling.caconfig.resource.impl.def.DefaultConfigurationResourceResolvingStrategy;
+import org.apache.sling.caconfig.resource.impl.def.DefaultContextPathStrategy;
+import org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin;
+import org.apache.sling.testing.mock.osgi.context.ContextPlugin;
+import org.apache.sling.testing.mock.sling.context.SlingContextImpl;
+
+/**
+ * Mock context plugins.
+ */
+public final class ContextPlugins {
+
+ private ContextPlugins() {
+ // constants only
+ }
+
+ /**
+ * Context plugin for Sling Context-Aware Configuration.
+ */
+ public static final ContextPlugin<? extends SlingContextImpl> CACONFIG = new AbstractContextPlugin<SlingContextImpl>() {
+ @Override
+ public void afterSetUp(SlingContextImpl context) throws Exception {
+ registerConfigurationResourceResolver(context);
+ registerConfigurationResolver(context);
+ registerConfigurationManagement(context);
+ registerConfigurationResourceResolverDefaultImpl(context);
+ registerConfigurationResolverDefaultImpl(context);
+ }
+ };
+
+ /**
+ * Context plugin for Sling Context-Aware Configuration (without the default implentations).
+ */
+ public static final ContextPlugin<? extends SlingContextImpl> CACONFIG_NODEF = new AbstractContextPlugin<SlingContextImpl>() {
+ @Override
+ public void afterSetUp(SlingContextImpl context) throws Exception {
+ registerConfigurationResourceResolver(context);
+ registerConfigurationResolver(context);
+ registerConfigurationManagement(context);
+ }
+ };
+
+ /**
+ * Register all services for ConfigurationResourceResolver (without the default implementations).
+ * @param context Sling context
+ */
+ private static void registerConfigurationResourceResolver(SlingContextImpl context) {
+ context.registerInjectActivateService(new ContextPathStrategyMultiplexerImpl());
+ context.registerInjectActivateService(new ConfigurationResourceResolvingStrategyMultiplexer());
+ context.registerInjectActivateService(new ConfigurationResourceResolverImpl());
+ }
+
+ /**
+ * Register default implementations for for ConfigurationResourceResolver.
+ * @param context Sling context
+ */
+ private static void registerConfigurationResourceResolverDefaultImpl(SlingContextImpl context) {
+ context.registerInjectActivateService(new DefaultContextPathStrategy());
+ context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy());
+ }
+
+
+ /**
+ * Register all services for ConfigurationResolver (without the default implementations).
+ * @param context Sling context
+ */
+ private static void registerConfigurationResolver(SlingContextImpl context) {
+ context.registerInjectActivateService(new ConfigurationPersistenceStrategyMultiplexer());
+ context.registerInjectActivateService(new ConfigurationInheritanceStrategyMultiplexer());
+ context.registerInjectActivateService(new ConfigurationOverrideManager());
+ context.registerInjectActivateService(new ConfigurationResolverImpl());
+ context.registerInjectActivateService(new ConfigurationBuilderAdapterFactory());
+ }
+
+ /**
+ * Register default implementations for for ConfigurationResolver.
+ * @param context Sling context
+ */
+ private static void registerConfigurationResolverDefaultImpl(SlingContextImpl context) {
+ context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
+ context.registerInjectActivateService(new DefaultConfigurationInheritanceStrategy());
+ }
+
+ private static void registerConfigurationManagement(SlingContextImpl context) {
+ context.registerInjectActivateService(new ConfigurationMetadataProviderMultiplexer());
+ context.registerInjectActivateService(new ConfigurationManagerImpl());
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/testing/mock/caconfig/package-info.java b/src/main/java/org/apache/sling/testing/mock/caconfig/package-info.java
new file mode 100644
index 0000000..de6d18e
--- /dev/null
+++ b/src/main/java/org/apache/sling/testing/mock/caconfig/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/**
+ * Apache Sling Context-Aware Configuration Mock Plugin
+ */
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.testing.mock.caconfig;
diff --git a/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java b/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java
new file mode 100644
index 0000000..f172a85
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.testing.mock.caconfig;
+
+import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.caconfig.ConfigurationBuilder;
+import org.apache.sling.caconfig.management.ConfigurationManager;
+import org.apache.sling.caconfig.spi.ConfigurationPersistData;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class ContextPluginsTest {
+
+ private static final String CONFIG_NAME = "testConfig";
+
+ @Rule
+ public SlingContext context = new SlingContextBuilder().plugin(CACONFIG).build();
+
+ private Resource contextResource;
+
+ @Before
+ public void setUp() {
+ context.create().resource("/content/site1", "sling:configRef", "/conf/site1");
+ contextResource = context.create().resource("/content/site1/page1");
+ }
+
+ @Test
+ public void testPlugin() {
+
+ // write config
+ ConfigurationManager configManager = context.getService(ConfigurationManager.class);
+ configManager.persistConfiguration(contextResource, CONFIG_NAME,
+ new ConfigurationPersistData(ImmutableMap.<String, Object>of(
+ "prop1", "value1",
+ "prop2", 123)));
+
+ // read config
+ ValueMap props = contextResource.adaptTo(ConfigurationBuilder.class).name(CONFIG_NAME).asValueMap();
+ assertEquals("value1", props.get("prop1", String.class));
+ assertEquals((Integer)123, props.get("prop2", Integer.class));
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.