You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/11/07 11:37:26 UTC
[sling-org-apache-sling-feature-extension-apiregions] 02/13:
SLING-7779 API Region support for the Sling Feature Model
This is an automated email from the ASF dual-hosted git repository.
davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git
commit 97aca3cc663f178cd84e0db615fcfafa09d3d4b3
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Oct 31 16:58:46 2018 +0000
SLING-7779 API Region support for the Sling Feature Model
Unit tests for the BundleMappingHandler
---
pom.xml | 8 ++
.../extensions/BundleMappingHandler.java | 1 -
.../apiregions/BundleMappingHandlerTest.java | 86 +++++++++++++++++++++
src/test/resources/b1/MANIFEST.MF | 3 +
src/test/resources/b1/b1.jar | Bin 0 -> 371 bytes
src/test/resources/b2/MANIFEST.MF | 3 +
src/test/resources/b2/b2.jar | Bin 0 -> 374 bytes
src/test/resources/b3/MANIFEST.MF | 2 +
src/test/resources/b3/b3.jar | Bin 0 -> 358 bytes
9 files changed, 102 insertions(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 0fb4d4b..857060f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
<configuration>
<excludes>
<exclude>src/main/resources/META-INF/services/**</exclude>
+ <exclude>src/test/resources/**</exclude>
</excludes>
</configuration>
</plugin>
@@ -57,5 +58,12 @@
<artifactId>osgi.core</artifactId>
<scope>provided</scope>
</dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
index 1338e88..bf68d02 100644
--- a/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
+++ b/src/main/java/org/apache/sling/feature/whitelisting/extensions/BundleMappingHandler.java
@@ -34,7 +34,6 @@ public class BundleMappingHandler extends AbstractHandler implements PostProcess
if (!"api-regions".equals(extension.getName()))
return;
-
try {
File idBSNFile = getDataFile("idbsnver.properties");
Properties map = loadProperties(idBSNFile);
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
new file mode 100644
index 0000000..1b24f9f
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/BundleMappingHandlerTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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.feature.extension.apiregions;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.builder.ArtifactProvider;
+import org.apache.sling.feature.whitelisting.extensions.BundleMappingHandler;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+
+public class BundleMappingHandlerTest {
+ @Test
+ public void testHandler() throws IOException {
+ ArtifactProvider ap = new ArtifactProvider() {
+ @Override
+ public File provide(ArtifactId id) {
+ switch(id.toMvnId()) {
+ case "g:b1:1":
+ return getResourceFile("b1/b1.jar");
+ case "g:b2:1.2.3":
+ return getResourceFile("b2/b2.jar");
+ case "g:b3:0":
+ return getResourceFile("b3/b3.jar");
+ default: return null;
+ }
+ }
+ };
+
+ BundleMappingHandler bmh = new BundleMappingHandler();
+
+ Extension ex = new Extension(ExtensionType.JSON, "api-regions", false);
+ Feature f = new Feature(ArtifactId.fromMvnId("foo:bar:123"));
+ Artifact b1 = new Artifact(ArtifactId.fromMvnId("g:b1:1"));
+ f.getBundles().add(b1);
+ Artifact b2 = new Artifact(ArtifactId.fromMvnId("g:b2:1.2.3"));
+ f.getBundles().add(b2);
+ Artifact b3 = new Artifact(ArtifactId.fromMvnId("g:b3:0"));
+ f.getBundles().add(b3);
+ bmh.postProcess(() -> ap, f, ex);
+
+ String p = System.getProperty("whitelisting.idbsnver.properties");
+ Properties actual = new Properties();
+ actual.load(new FileReader(p));
+
+ Properties expected = new Properties();
+ expected.put("g:b1:1", "b1~1.0.0");
+ expected.put("g:b2:1.2.3", "b2~1.2.3");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testUnrelatedExtension() {
+ BundleMappingHandler bmh = new BundleMappingHandler();
+ Extension ex = new Extension(ExtensionType.JSON, "foobar", false);
+ bmh.postProcess(null, null, ex);
+ // Should not do anything and definitely not throw an exception
+ }
+
+ private File getResourceFile(String filename) {
+ return new File(getClass().getClassLoader().getResource(filename).getFile());
+ }
+}
diff --git a/src/test/resources/b1/MANIFEST.MF b/src/test/resources/b1/MANIFEST.MF
new file mode 100644
index 0000000..28bba7a
--- /dev/null
+++ b/src/test/resources/b1/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: b1
+Bundle-Version: 1.0.0
+
diff --git a/src/test/resources/b1/b1.jar b/src/test/resources/b1/b1.jar
new file mode 100644
index 0000000..6798c5e
Binary files /dev/null and b/src/test/resources/b1/b1.jar differ
diff --git a/src/test/resources/b2/MANIFEST.MF b/src/test/resources/b2/MANIFEST.MF
new file mode 100644
index 0000000..653d2b0
--- /dev/null
+++ b/src/test/resources/b2/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: b2
+Bundle-Version: 1.2.3
+
diff --git a/src/test/resources/b2/b2.jar b/src/test/resources/b2/b2.jar
new file mode 100644
index 0000000..c9cfb6b
Binary files /dev/null and b/src/test/resources/b2/b2.jar differ
diff --git a/src/test/resources/b3/MANIFEST.MF b/src/test/resources/b3/MANIFEST.MF
new file mode 100644
index 0000000..bf91437
--- /dev/null
+++ b/src/test/resources/b3/MANIFEST.MF
@@ -0,0 +1,2 @@
+NotABundle: me
+
diff --git a/src/test/resources/b3/b3.jar b/src/test/resources/b3/b3.jar
new file mode 100644
index 0000000..bca1724
Binary files /dev/null and b/src/test/resources/b3/b3.jar differ