This is an automated email from the ASF dual-hosted git repository.
simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
The following commit(s) were added to refs/heads/master by this push:
new dfed956 [feature-diff] added FeatureDiffTest and refined related
implementation
dfed956 is described below
commit dfed9569fcfae8d4f71434502de67f4a6faa4a3f
Author: stripodi <[email protected]>
AuthorDate: Wed Apr 3 17:15:40 2019 +0200
[feature-diff] added FeatureDiffTest and refined related implementation
---
.../org/apache/sling/feature/diff/FeatureDiff.java | 24 ++++++++
.../apache/sling/feature/diff/FeatureDiffTest.java | 67 ++++++++++++++++++++++
2 files changed, 91 insertions(+)
diff --git
a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
index 775e679..c2a72fc 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
@@ -21,8 +21,28 @@ import static java.util.Objects.requireNonNull;
import java.util.LinkedList;
import java.util.List;
+import org.apache.sling.feature.Feature;
+
public final class FeatureDiff {
+ public static FeatureDiff compareFeatures(Feature previous, Feature
current) {
+ previous = requireNonNull(previous, "Impossible to compare null
previous feature.");
+ current = requireNonNull(current, "Impossible to compare null current
feature.");
+
+ if (!previous.getId().isSame(current.getId())) {
+ throw new IllegalArgumentException("Feature comparison has to be
related to different versions of the same Feature.");
+ }
+
+ FeatureDiff featureDiff = new FeatureDiff();
+
+ featureDiff.addSection(new
GenericMapComparator("framework-properties").compare(previous.getFrameworkProperties(),
current.getFrameworkProperties()));
+ featureDiff.addSection(new
ArtifactsComparator("bundles").apply(previous.getBundles(),
current.getBundles()));
+ featureDiff.addSection(new
ConfigurationsComparator().apply(previous.getConfigurations(),
current.getConfigurations()));
+ featureDiff.addSection(new
ExtensionsComparator().apply(previous.getExtensions(),
current.getExtensions()));
+
+ return featureDiff;
+ }
+
private final List<DiffSection> diffSections = new LinkedList<>();
private FeatureDiff() {
@@ -36,6 +56,10 @@ public final class FeatureDiff {
}
}
+ public boolean isEmpty() {
+ return diffSections.isEmpty();
+ }
+
public Iterable<DiffSection> getSections() {
return diffSections;
}
diff --git
a/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
b/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
new file mode 100644
index 0000000..0d46c2b
--- /dev/null
+++
b/feature-diff/src/test/java/org/apache/sling/feature/diff/FeatureDiffTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.diff;
+
+import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.junit.Test;
+
+public class FeatureDiffTest {
+
+ @Test(expected = NullPointerException.class)
+ public void doesNotAcceptNullPreviousFeature() {
+ compareFeatures(null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void doesNotAcceptNullCurrentFeature() {
+ compareFeatures(new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0")),
null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void doesNotAcceptDifferentFeatures() {
+ Feature previous = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.apiregions:1.0.0"));
+ Feature current = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0"));
+ compareFeatures(previous, current);
+ }
+
+ @Test
+ public void frameworkPropertiesUpdated() {
+ Feature previous = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:0.9.0"));
+ previous.getFrameworkProperties().put("env", "staging");
+
+ Feature current = new
Feature(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.diff:1.0.0"));
+ current.getFrameworkProperties().put("env", "prod");
+
+ FeatureDiff diff = compareFeatures(previous, current);
+ assertFalse(diff.isEmpty());
+
+ DiffSection fwPropertiesDiff = diff.getSections().iterator().next();
+ assertFalse(fwPropertiesDiff.isEmpty());
+
+ @SuppressWarnings("unchecked") // known type
+ UpdatedItem<String> updated = (UpdatedItem<String>)
fwPropertiesDiff.getUpdatedItems().iterator().next();
+ assertEquals("env", updated.getId());
+ assertEquals("staging", updated.getPrevious());
+ assertEquals("prod", updated.getCurrent());
+ }
+
+}