Author: cziegeler
Date: Fri Jul 28 16:02:04 2017
New Revision: 1803289
URL: http://svn.apache.org/viewvc?rev=1803289&view=rev
Log:
Add simple test for bundles merging
Added:
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
(with props)
Added:
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java?rev=1803289&view=auto
==============================================================================
---
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
(added)
+++
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
Fri Jul 28 16:02:04 2017
@@ -0,0 +1,133 @@
+/*
+ * 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.process;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Bundles;
+import org.apache.sling.feature.process.BuilderUtil.ArtifactMerge;
+import org.junit.Test;
+
+public class BuilderUtilTest {
+
+ private List<Map.Entry<Integer, Artifact>> getBundles(final Bundles f) {
+ final List<Map.Entry<Integer, Artifact>> result = new ArrayList<>();
+ for(final Map.Entry<Integer, Artifact> entry : f) {
+ result.add(entry);
+ }
+ return result;
+ }
+
+ private void assertContains(final List<Map.Entry<Integer, Artifact>>
bundles,
+ final int level, final ArtifactId id) {
+ for(final Map.Entry<Integer, Artifact> entry : bundles) {
+ if ( entry.getKey().intValue() == level
+ && entry.getValue().getId().equals(id) ) {
+ return;
+ }
+ }
+ fail(id.toMvnId());
+ }
+
+ @Test public void testMergeBundlesWithAlgHighest() {
+ final Bundles target = new Bundles();
+
+ target.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.0")));
+ target.add(2, new Artifact(ArtifactId.fromMvnId("g/b/2.0")));
+ target.add(3, new Artifact(ArtifactId.fromMvnId("g/c/2.5")));
+
+ final Bundles source = new Bundles();
+ source.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.1")));
+ source.add(2, new Artifact(ArtifactId.fromMvnId("g/b/1.9")));
+ source.add(3, new Artifact(ArtifactId.fromMvnId("g/c/2.5")));
+
+ BuilderUtil.mergeBundles(target, source, ArtifactMerge.HIGHEST);
+
+ final List<Map.Entry<Integer, Artifact>> result = getBundles(target);
+ assertEquals(3, result.size());
+ assertContains(result, 1, ArtifactId.fromMvnId("g/a/1.1"));
+ assertContains(result, 2, ArtifactId.fromMvnId("g/b/2.0"));
+ assertContains(result, 3, ArtifactId.fromMvnId("g/c/2.5"));
+ }
+
+ @Test public void testMergeBundlesWithAlgLatest() {
+ final Bundles target = new Bundles();
+
+ target.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.0")));
+ target.add(2, new Artifact(ArtifactId.fromMvnId("g/b/2.0")));
+ target.add(3, new Artifact(ArtifactId.fromMvnId("g/c/2.5")));
+
+ final Bundles source = new Bundles();
+ source.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.1")));
+ source.add(2, new Artifact(ArtifactId.fromMvnId("g/b/1.9")));
+ source.add(3, new Artifact(ArtifactId.fromMvnId("g/c/2.5")));
+
+ BuilderUtil.mergeBundles(target, source, ArtifactMerge.LATEST);
+
+ final List<Map.Entry<Integer, Artifact>> result = getBundles(target);
+ assertEquals(3, result.size());
+ assertContains(result, 1, ArtifactId.fromMvnId("g/a/1.1"));
+ assertContains(result, 2, ArtifactId.fromMvnId("g/b/1.9"));
+ assertContains(result, 3, ArtifactId.fromMvnId("g/c/2.5"));
+ }
+
+ @Test public void testMergeBundlesDifferentStartlevel() {
+ final Bundles target = new Bundles();
+
+ target.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.0")));
+
+ final Bundles source = new Bundles();
+ source.add(2, new Artifact(ArtifactId.fromMvnId("g/a/1.1")));
+
+ BuilderUtil.mergeBundles(target, source, ArtifactMerge.LATEST);
+
+ final List<Map.Entry<Integer, Artifact>> result = getBundles(target);
+ assertEquals(1, result.size());
+ assertContains(result, 2, ArtifactId.fromMvnId("g/a/1.1"));
+ }
+
+ @Test public void testMergeBundles() {
+ final Bundles target = new Bundles();
+
+ target.add(1, new Artifact(ArtifactId.fromMvnId("g/a/1.0")));
+ target.add(2, new Artifact(ArtifactId.fromMvnId("g/b/2.0")));
+ target.add(3, new Artifact(ArtifactId.fromMvnId("g/c/2.5")));
+
+ final Bundles source = new Bundles();
+ source.add(1, new Artifact(ArtifactId.fromMvnId("g/d/1.1")));
+ source.add(2, new Artifact(ArtifactId.fromMvnId("g/e/1.9")));
+ source.add(3, new Artifact(ArtifactId.fromMvnId("g/f/2.5")));
+
+ BuilderUtil.mergeBundles(target, source, ArtifactMerge.LATEST);
+
+ final List<Map.Entry<Integer, Artifact>> result = getBundles(target);
+ assertEquals(6, result.size());
+ assertContains(result, 1, ArtifactId.fromMvnId("g/a/1.0"));
+ assertContains(result, 2, ArtifactId.fromMvnId("g/b/2.0"));
+ assertContains(result, 3, ArtifactId.fromMvnId("g/c/2.5"));
+ assertContains(result, 1, ArtifactId.fromMvnId("g/d/1.1"));
+ assertContains(result, 2, ArtifactId.fromMvnId("g/e/1.9"));
+ assertContains(result, 3, ArtifactId.fromMvnId("g/f/2.5"));
+ }
+}
Propchange:
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/cziegeler/feature/src/test/java/org/apache/sling/feature/process/BuilderUtilTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url