This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new c56b99a  SLING-10019 sling-mock: Add Feature Flag Service
c56b99a is described below

commit c56b99aaa17bf0e0a36eb23b378b657e487bfc7e
Author: Stefan Seifert <[email protected]>
AuthorDate: Tue Dec 22 10:04:48 2020 +0100

    SLING-10019 sling-mock: Add Feature Flag Service
---
 core/pom.xml                                       |  6 +++
 .../mock/sling/context/SlingContextImpl.java       |  2 +
 .../mock/sling/context/FeatureFlagsTest.java       | 62 ++++++++++++++++++++++
 3 files changed, 70 insertions(+)

diff --git a/core/pom.xml b/core/pom.xml
index 98e5254..95368c6 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -188,6 +188,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.featureflags</artifactId>
+            <version>1.2.2</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.resourcebuilder</artifactId>
             <version>${resourcebuilder.version}</version>
             <scope>compile</scope>
diff --git 
a/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
 
b/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
index 8211bda..b3b9519 100644
--- 
a/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
+++ 
b/core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
@@ -41,6 +41,7 @@ import org.apache.sling.api.resource.ResourceResolverFactory;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.featureflags.impl.FeatureManager;
 import 
org.apache.sling.jcr.resource.internal.scripting.JcrObjectsBindingsValuesProvider;
 import org.apache.sling.models.impl.ModelAdapterFactory;
 import org.apache.sling.resourcebuilder.api.ResourceBuilder;
@@ -188,6 +189,7 @@ public class SlingContextImpl extends OsgiContextImpl {
                 SERVICE_PROPERTY_MOCK_SLING_BINDINGS_IGNORE, true);
         registerInjectActivateService(new MockResourceBundleProvider());
         registerInjectActivateService(new MockXSSAPIImpl());
+        registerInjectActivateService(new FeatureManager());
         
         // scan for models defined via bundle headers in classpath
         if (registerSlingModelsFromClassPath) {
diff --git 
a/core/src/test/java/org/apache/sling/testing/mock/sling/context/FeatureFlagsTest.java
 
b/core/src/test/java/org/apache/sling/testing/mock/sling/context/FeatureFlagsTest.java
new file mode 100644
index 0000000..9c2e50d
--- /dev/null
+++ 
b/core/src/test/java/org/apache/sling/testing/mock/sling/context/FeatureFlagsTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.sling.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.featureflags.Features;
+import org.apache.sling.featureflags.impl.ConfiguredFeature;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class FeatureFlagsTest {
+
+    @Rule
+    public SlingContext context = new SlingContext();
+
+    @Test
+    public void testFeatureFlag_NotSet() {
+        assertEnabled("feature.1", false);
+    }
+
+    @Test
+    public void testFeatureFlag_Enabled() {
+        context.registerInjectActivateService(new ConfiguredFeature(),
+                "name", "feature.1",
+                "enabled", true);
+        assertEnabled("feature.1", true);
+    }
+
+    @Test
+    public void testFeatureFlag__Disabled() {
+        context.registerInjectActivateService(new ConfiguredFeature(),
+                "name", "feature.1",
+                "enabled", false);
+        assertEnabled("feature.1", false);
+    }
+    
+    private void assertEnabled(String featureFlag, boolean enabled) {
+        Features features = context.getService(Features.class);
+        assertNotNull(features);
+        assertEquals("enabled", enabled, features.isEnabled("feature.1"));
+    }
+
+}

Reply via email to