Skip to content
Permalink
Browse files
Re-adding tests and restoring behavior where if a property is not fou…
…nd in the ancestor the custom and product must equal or it will be a conflict
  • Loading branch information
klcodanr committed Mar 10, 2022
1 parent 05509c9 commit 8a44639667c6c954253e23af8a3c8f94fd4b52e4
Showing 4 changed files with 12 additions and 45 deletions.
@@ -148,8 +148,6 @@ private static String mergeProperty(String path, String property, JsonObject anc
return cp;
} else if (Objects.equals(ap, cp)) {
return pp;
} else if (ap == null) {
return cp; // if property doesn't exist in the ancestor, prefer customization over the product value
} else {
conflicts.add("Could not merge value; path=" + path + " property=" + property + "; ancestor=" + ap + "; custom=" + cp
+ "; product=" + pp);
@@ -26,7 +26,6 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Optional;

import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.oak.commons.json.JsonObject;
@@ -41,9 +40,9 @@
* Test merging index definitions.
*/
@RunWith(Parameterized.class)
public class IndexDefMergerScenariosTest {
public class IndexDefMergerScenariosTest extends ParameterizedMergingTestBase {

private static final Logger log = LoggerFactory.getLogger(IndexDefMergerScenariosTest.class);
private static final Logger log = LoggerFactory.getLogger(IndexDefMergerConflictsTest.class);

@Parameters(name = "{0}")
public static Collection<Object[]> data() {
@@ -60,53 +59,17 @@ public static Collection<Object[]> data() {
});
}

public static Object[] testCase(String name, String testCaseFile) {
return new Object[] {
name,
testCaseFile
};
}

private final String testCaseFile;
private final String testCaseName;
private final JsonObject buildIndexes;
private final JsonObject runIndexes;
private final JsonObject expectedIndexes;

public IndexDefMergerScenariosTest(String name, String testCaseFile)
throws IOException {
this.testCaseName = name;
this.testCaseFile = testCaseFile;
JsonObject testCase = readTestCaseFile(testCaseFile);
this.buildIndexes = getChild(testCase, "build");
this.runIndexes = getChild(testCase, "run");
this.expectedIndexes = getChild(testCase, "expected");
}

private JsonObject readTestCaseFile(String testCaseFileName) {
return Optional.ofNullable(IndexDefMergerScenariosTest.class.getResourceAsStream(testCaseFileName))
.map(in -> {
try {
return IOUtils.toString(in, StandardCharsets.UTF_8.toString());
} catch (IOException e) {
throw new IllegalArgumentException(
"Unexpected IOException reading test case file: " + testCaseFileName, e);
}
})
.map(s -> JsonObject.fromJson(s, true))
.orElseThrow(() -> new IllegalArgumentException("Unable to read test case file: " + testCaseFileName));
}

private JsonObject getChild(JsonObject testCase, String fieldName) {
return Optional.ofNullable(testCase.getChildren().get(fieldName))
.orElseThrow(() -> new IllegalArgumentException(
"Unable to run test: " + testCaseName + ", Expected field " + fieldName + " not set"));
super(name, testCaseFile);
this.expectedIndexes = super.getTestCaseChild("expected");
}

@Test
public void testMerge() {
public void verifyExpectedMergeResult() {
IndexDefMergerUtils.merge(buildIndexes, runIndexes);

File output = new File("target" + File.separator + "surefire-output" + File.separator
+ getClass().getCanonicalName().replace(".", "-") + File.separator + testCaseFile);
try {
@@ -1,7 +1,7 @@
{
"run": {
"/oak:index/lucene": { "a": 1, "b": 10, "x": 1, "z": 2 },
"/oak:index/lucene-custom-1": { "a": 2, "b": 10, "c": 1, "x": 1 }
"/oak:index/lucene-custom-1": { "a": 2, "b": 10, "c": 1, "x": 1 }
},
"build": {
"/oak:index/lucene-2": { "a": 1, "b": 11, "d": 100, "z": 2 }
@@ -13,6 +13,12 @@
"product": {"o": {"a": 1, "p": 20}},
"expected": {"merges": ["/oak:index/test-2", "/oak:index/test-1-custom-1"], "o": {"a": 2, "c": 10, "p": 20 }}
},
{
"ancestor": {"o": {"a": 1}},
"custom": {},
"product": {"o": {"a": 2}},
"expected": {"merges": ["/oak:index/test-2", "/oak:index/test-1-custom-1"],"o": {"a": 2}}
},
{
"ancestor": {"a": 1},
"custom": {"a": 2},

0 comments on commit 8a44639

Please sign in to comment.