summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/test/java/com/yahoo/container/plugin
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2020-06-24 13:43:21 +0200
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2020-06-24 13:45:19 +0200
commitd401fff24ac80a940ef01f80fabc05711a12fe94 (patch)
tree5538a5a1523f57bae811a4b930271f5362e21876 /bundle-plugin/src/test/java/com/yahoo/container/plugin
parent6821733667528dddeed658205358f6b9dda12090 (diff)
Introduce concept of 'test provided' scoped dependencies
'Test provided' dependencies are treated as 'provided' scoped dependencies when building a test bundle. Other 'test' scoped dependencies are bundled as 'compile'.
Diffstat (limited to 'bundle-plugin/src/test/java/com/yahoo/container/plugin')
-rw-r--r--bundle-plugin/src/test/java/com/yahoo/container/plugin/mojo/TestProvidedArtifactsTest.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/mojo/TestProvidedArtifactsTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/mojo/TestProvidedArtifactsTest.java
new file mode 100644
index 00000000000..0c0bdffed6e
--- /dev/null
+++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/mojo/TestProvidedArtifactsTest.java
@@ -0,0 +1,70 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.plugin.mojo;
+
+
+import org.apache.maven.artifact.Artifact;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author bjorncs
+ */
+public class TestProvidedArtifactsTest {
+
+ private static final String GROUP_ID = "com.test";
+
+ @Test
+ public void findsAllTestProvidedDependencies() {
+ Map<String, Artifact> artifacts = new TreeMap<>();
+ Artifact a = createArtifact(artifacts, "a");
+ Artifact aa = createArtifact(artifacts, "a-a", "a");
+ Artifact ab = createArtifact(artifacts, "a-b", "a");
+ Artifact aaa = createArtifact(artifacts, "a-a-a", "a", "a-a");
+ Artifact b = createArtifact(artifacts, "b");
+ Artifact ba = createArtifact(artifacts, "b-a", "b");
+ Artifact c = createArtifact(artifacts, "c");
+
+ String configString = "com.test:a,com.test:b-a,!com.test:a-b";
+ TestProvidedArtifacts testProvidedArtifacts = TestProvidedArtifacts.from(artifacts, configString);
+
+ assertTrue(testProvidedArtifacts.isTestProvided(a));
+ assertTrue(testProvidedArtifacts.isTestProvided(aa));
+ assertFalse(testProvidedArtifacts.isTestProvided(ab));
+ assertTrue(testProvidedArtifacts.isTestProvided(aaa));
+ assertFalse(testProvidedArtifacts.isTestProvided(b));
+ assertTrue(testProvidedArtifacts.isTestProvided(ba));
+ assertFalse(testProvidedArtifacts.isTestProvided(c));
+ }
+
+ private static Artifact createArtifact(Map<String, Artifact> artifacts, String artifactId, String... dependents) {
+ Artifact artifact = createArtifact(artifactId, dependents);
+ artifacts.put(simpleId(artifactId), artifact);
+ return artifact;
+ }
+
+ private static Artifact createArtifact(String artifactId, String... dependents) {
+ Artifact artifact = Mockito.mock(Artifact.class);
+ when(artifact.getArtifactId()).thenReturn(artifactId);
+ when(artifact.getGroupId()).thenReturn(GROUP_ID);
+ List<String> dependencyTrail = new ArrayList<>();
+ dependencyTrail.add(fullId("bundle-plugin"));
+ Arrays.stream(dependents).forEach(dependent -> dependencyTrail.add(fullId(dependent)));
+ dependencyTrail.add(fullId(artifactId));
+ when(artifact.getDependencyTrail()).thenReturn(dependencyTrail);
+ return artifact;
+ }
+
+ private static String fullId(String artifactId) { return simpleId(artifactId) + ":1.0:compile"; }
+ private static String simpleId(String artifactId) { return GROUP_ID + ":" + artifactId; }
+
+} \ No newline at end of file