|
1 |
| -package com.devonfw.tools.ide.merge; |
| 1 | +package com.devonfw.tools.ide.merge.xml; |
2 | 2 |
|
3 | 3 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
4 | 4 |
|
|
7 | 7 | import java.nio.file.Path;
|
8 | 8 | import java.util.stream.Stream;
|
9 | 9 |
|
| 10 | +import org.junit.jupiter.api.Test; |
10 | 11 | import org.junit.jupiter.api.io.TempDir;
|
11 | 12 | import org.junit.jupiter.params.ParameterizedTest;
|
12 | 13 | import org.junit.jupiter.params.provider.MethodSource;
|
|
15 | 16 | import org.xmlunit.assertj3.XmlAssert;
|
16 | 17 |
|
17 | 18 | import com.devonfw.tools.ide.context.AbstractIdeContextTest;
|
| 19 | +import com.devonfw.tools.ide.context.IdeTestContext; |
18 | 20 | import com.devonfw.tools.ide.context.IdeTestContextMock;
|
19 | 21 | import com.devonfw.tools.ide.environment.EnvironmentVariables;
|
20 | 22 | import com.devonfw.tools.ide.environment.EnvironmentVariablesPropertiesMock;
|
21 | 23 | import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
|
22 |
| -import com.devonfw.tools.ide.merge.xmlmerger.XmlMerger; |
23 | 24 |
|
24 | 25 | /**
|
25 | 26 | * Test of {@link XmlMerger}.
|
@@ -67,4 +68,27 @@ private static Stream<Path> xmlMergerTestCases() throws IOException {
|
67 | 68 |
|
68 | 69 | return Files.list(XML_TEST_RESOURCES).filter(Files::isDirectory);
|
69 | 70 | }
|
| 71 | + |
| 72 | + @Test |
| 73 | + void testFailOnAmbiguousMerge(@TempDir Path tempDir) throws Exception { |
| 74 | + |
| 75 | + // arrange |
| 76 | + IdeTestContext context = new IdeTestContext(); |
| 77 | + EnvironmentVariables variables = context.getVariables(); |
| 78 | + variables.getByType(EnvironmentVariablesType.CONF).set("FAIL_ON_AMBIGOUS_MERGE", "true"); |
| 79 | + XmlMerger merger = new XmlMerger(context); |
| 80 | + Path folder = XML_TEST_RESOURCES.resolve("ambiguous-id"); |
| 81 | + Path sourcePath = folder.resolve(SOURCE_XML); |
| 82 | + Path targetPath = tempDir.resolve(TARGET_XML); |
| 83 | + Files.copy(folder.resolve(TARGET_XML), targetPath, REPLACE_EXISTING); |
| 84 | + // act |
| 85 | + assertThatThrownBy(() -> { |
| 86 | + merger.doMerge(null, sourcePath, variables, targetPath); |
| 87 | + }) |
| 88 | + // assert |
| 89 | + .hasRootCauseInstanceOf(IllegalStateException.class).hasRootCauseMessage( |
| 90 | + "2 matches found for XPath configuration[@default='true' and @type='JUnit'] in workspace XML at /project[@version='4']/component[@name='RunManager' @selected='Application.IDEasy']"); |
| 91 | + ; |
| 92 | + |
| 93 | + } |
70 | 94 | }
|
0 commit comments