use of co.cask.cdap.api.plugin.PluginClass in project cdap by caskdata.
the class ArtifactStoreTest method testDelete.
@Test
public void testDelete() throws Exception {
// write an artifact with an app
Id.Artifact parentId = Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.0.0");
ApplicationClass appClass = new ApplicationClass(InspectionApp.class.getName(), "", new ReflectionSchemaGenerator().generate(InspectionApp.AConfig.class));
ArtifactMeta artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addApp(appClass).build());
writeArtifact(parentId, artifactMeta, "parent contents");
// write a child artifact that extends the parent with some plugins
Id.Artifact childId = Id.Artifact.from(Id.Namespace.DEFAULT, "myplugins", "1.0.0");
List<PluginClass> plugins = ImmutableList.of(new PluginClass("atype", "plugin1", "", "c.c.c.plugin1", "cfg", ImmutableMap.<String, PluginPropertyField>of()), new PluginClass("atype", "plugin2", "", "c.c.c.plugin2", "cfg", ImmutableMap.<String, PluginPropertyField>of()));
Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(parentId.getNamespace().getId(), parentId.getName(), new ArtifactVersion("0.1.0"), new ArtifactVersion("2.0.0")));
artifactMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugins(plugins).build(), parents);
writeArtifact(childId, artifactMeta, "child contents");
// check parent has plugins from the child
Assert.assertFalse(artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentId).isEmpty());
// delete the child artifact
artifactStore.delete(childId);
// shouldn't be able to get artifact detail
try {
artifactStore.getArtifact(childId);
Assert.fail();
} catch (ArtifactNotFoundException e) {
// expected
}
// shouldn't see it in the list
List<ArtifactDetail> artifactList = artifactStore.getArtifacts(parentId.getNamespace().toEntityId());
Assert.assertEquals(1, artifactList.size());
Assert.assertEquals(parentId.getName(), artifactList.get(0).getDescriptor().getArtifactId().getName());
// shouldn't see any more plugins for parent
Assert.assertTrue(artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentId).isEmpty());
// delete parent
artifactStore.delete(parentId);
// nothing should be in the list
Assert.assertTrue(artifactStore.getArtifacts(parentId.getNamespace().toEntityId()).isEmpty());
// shouldn't be able to see app class either
Assert.assertTrue(artifactStore.getApplicationClasses(NamespaceId.DEFAULT, appClass.getClassName()).isEmpty());
}
use of co.cask.cdap.api.plugin.PluginClass in project cdap by caskdata.
the class ArtifactStoreTest method testGetArtifacts.
@Test
public void testGetArtifacts() throws Exception {
// add 1 version of another artifact1
Id.Artifact artifact1V1 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact1", "1.0.0");
String contents1V1 = "first contents v1";
PluginClass plugin1V1 = new PluginClass("atype", "plugin1", "", "c.c.c.plugin1", "cfg", ImmutableMap.<String, PluginPropertyField>of());
ArtifactMeta meta1V1 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin1V1).build());
writeArtifact(artifact1V1, meta1V1, contents1V1);
// add 2 versions of an artifact2
Id.Artifact artifact2V1 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.0");
Id.Artifact artifact2V2 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.1");
Id.Artifact artifact2V3 = Id.Artifact.from(Id.Namespace.DEFAULT, "artifact2", "0.1.1-SNAPSHOT");
String contents2V1 = "second contents v1";
String contents2V2 = "second contents v2";
String contents2V3 = "second contents v3";
PluginClass plugin2V1 = new PluginClass("atype", "plugin2", "", "c.c.c.plugin2", "cfg", ImmutableMap.<String, PluginPropertyField>of());
PluginClass plugin2V2 = new PluginClass("atype", "plugin2", "", "c.c.c.plugin2", "cfg", ImmutableMap.<String, PluginPropertyField>of());
PluginClass plugin2V3 = new PluginClass("atype", "plugin2", "", "c.c.c.plugin2", "cfg", ImmutableMap.<String, PluginPropertyField>of());
ArtifactMeta meta2V1 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V1).build());
ArtifactMeta meta2V2 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V2).build());
ArtifactMeta meta2V3 = new ArtifactMeta(ArtifactClasses.builder().addPlugin(plugin2V3).build());
writeArtifact(artifact2V1, meta2V1, contents2V1);
writeArtifact(artifact2V2, meta2V2, contents2V2);
writeArtifact(artifact2V3, meta2V3, contents2V3);
// test we get 1 version of artifact1 and 2 versions of artifact2
List<ArtifactDetail> artifact1Versions = artifactStore.getArtifacts(artifact1V1.getNamespace().toEntityId(), artifact1V1.getName(), Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifact1Versions.size());
assertEqual(artifact1V1, meta1V1, contents1V1, artifact1Versions.get(0));
List<ArtifactDetail> artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(1));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(2));
// test get 2 versions of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 2, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(2, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(1));
// test get sorted version of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 3, ArtifactSortOrder.DESC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(2));
// test get sorted and limited version of artifact 2
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 2, ArtifactSortOrder.DESC);
Assert.assertEquals(2, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
artifact2Versions = artifactStore.getArtifacts(artifact2V1.getNamespace().toEntityId(), artifact2V1.getName(), 3, ArtifactSortOrder.ASC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifact2Versions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifact2Versions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifact2Versions.get(2));
// test we get all 3 in the getArtifactSummaries() call for the namespace
List<ArtifactDetail> artifactVersions = artifactStore.getArtifacts(NamespaceId.DEFAULT);
Assert.assertEquals(4, artifactVersions.size());
assertEqual(artifact1V1, meta1V1, contents1V1, artifactVersions.get(0));
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(2));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(3));
// test get using a range
// this range should get everything
ArtifactRange range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.1.0"), new ArtifactVersion("0.1.2"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(3, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(1));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(2));
// test get one version
artifactVersions = artifactStore.getArtifacts(range, 1, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
// test get sorted versions
artifactVersions = artifactStore.getArtifacts(range, 3, ArtifactSortOrder.DESC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(2));
artifactVersions = artifactStore.getArtifacts(range, 3, ArtifactSortOrder.ASC);
Assert.assertEquals(3, artifact2Versions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(2));
// this range should get just v0.1.1
range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.1.1"), new ArtifactVersion("1.0.0"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, artifactVersions.size());
assertEqual(artifact2V2, meta2V2, contents2V2, artifactVersions.get(0));
// this range should get just v0.1.0 and v0.1.1-SNAPSHOT
range = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "artifact2", new ArtifactVersion("0.0.0"), new ArtifactVersion("0.1.1"));
artifactVersions = artifactStore.getArtifacts(range, Integer.MAX_VALUE, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(2, artifactVersions.size());
assertEqual(artifact2V1, meta2V1, contents2V1, artifactVersions.get(0));
assertEqual(artifact2V3, meta2V3, contents2V3, artifactVersions.get(1));
}
use of co.cask.cdap.api.plugin.PluginClass in project cdap by caskdata.
the class ArtifactStoreTest method testUniversalPlugin.
@Test
public void testUniversalPlugin() throws Exception {
// First, deploy an artifact in the SYSTEM scope that doesn't have any plugin inside.
ArtifactId artifactId = NamespaceId.SYSTEM.artifact("artifact", "1.0.0");
writeArtifact(Id.Artifact.fromEntityId(artifactId), new ArtifactMeta(ArtifactClasses.builder().build()), "test");
// Deploy an artifact that has a plugin in the DEFAULT scope, but without any parent artifact
PluginClass pluginClass1 = new PluginClass("type1", "plugin1", "plugin1", "plugin1", null, Collections.emptyMap());
ArtifactId pluginArtifactId1 = NamespaceId.DEFAULT.artifact("plugin-artifact1", "0.0.1");
writeArtifact(Id.Artifact.fromEntityId(pluginArtifactId1), new ArtifactMeta(ArtifactClasses.builder().addPlugin(pluginClass1).build()), "test");
// Get the available plugins for the artifact, should get the plugin1
SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins = artifactStore.getPluginClasses(NamespaceId.DEFAULT, Id.Artifact.fromEntityId(artifactId));
Assert.assertEquals(1, plugins.size());
List<PluginClass> pluginsClasses = plugins.values().stream().flatMap(Set::stream).collect(Collectors.toList());
Assert.assertEquals(1, pluginsClasses.size());
Assert.assertEquals(pluginClass1, pluginsClasses.get(0));
// Get the available plugins for the plugin artifact itself, should also get the plugin1
plugins = artifactStore.getPluginClasses(NamespaceId.DEFAULT, Id.Artifact.fromEntityId(pluginArtifactId1));
Assert.assertEquals(1, plugins.size());
pluginsClasses = plugins.values().stream().flatMap(Set::stream).collect(Collectors.toList());
Assert.assertEquals(1, pluginsClasses.size());
Assert.assertEquals(pluginClass1, pluginsClasses.get(0));
// Deploy an artifact that has a plugin in the DEFAULT scope with a parent artifact
PluginClass pluginClass2 = new PluginClass("type2", "plugin2", "plugin2", "plugin2", null, Collections.emptyMap());
ArtifactId pluginArtifactId2 = NamespaceId.DEFAULT.artifact("plugin-artifact2", "0.0.1");
ArtifactRange parentArtifactRange = new ArtifactRange(artifactId.getNamespace(), artifactId.getArtifact(), ArtifactVersionRange.parse("[1.0.0,2.0.0)"));
writeArtifact(Id.Artifact.fromEntityId(pluginArtifactId2), new ArtifactMeta(ArtifactClasses.builder().addPlugin(pluginClass2).build(), Collections.singleton(parentArtifactRange)), "test");
// Get the available plugins for the artifact again, should get plugin1 and plugin2
plugins = artifactStore.getPluginClasses(NamespaceId.DEFAULT, Id.Artifact.fromEntityId(artifactId));
Assert.assertEquals(2, plugins.size());
// Get and verify the plugins.
pluginsClasses = plugins.values().stream().flatMap(Set::stream).collect(Collectors.toList());
Assert.assertEquals(2, pluginsClasses.size());
// The plugins are sorted by the ArtifactDescriptor, hence order is guaranteed
Assert.assertEquals(Arrays.asList(pluginClass1, pluginClass2), pluginsClasses);
// Get available plugin by type.
for (PluginClass pluginClass : Arrays.asList(pluginClass1, pluginClass2)) {
plugins = artifactStore.getPluginClasses(NamespaceId.DEFAULT, Id.Artifact.fromEntityId(artifactId), pluginClass.getType());
Assert.assertEquals(1, plugins.size());
pluginsClasses = plugins.values().stream().flatMap(Set::stream).collect(Collectors.toList());
Assert.assertEquals(1, pluginsClasses.size());
Assert.assertEquals(pluginClass, pluginsClasses.get(0));
}
// Get plugins by parent ArtifactRange
for (PluginClass pluginClass : Arrays.asList(pluginClass1, pluginClass2)) {
SortedMap<ArtifactDescriptor, PluginClass> result = artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentArtifactRange, pluginClass.getType(), pluginClass.getName(), null, 10, ArtifactSortOrder.UNORDERED);
Assert.assertEquals(1, result.size());
Assert.assertEquals(pluginClass, result.values().stream().findFirst().get());
}
}
use of co.cask.cdap.api.plugin.PluginClass in project cdap by caskdata.
the class ArtifactSelectorTest method testSelection.
@Test
public void testSelection() {
SortedMap<ArtifactId, PluginClass> plugins = new TreeMap<>();
// doesn't matter what this is, since we only select on artifact id.
PluginClass pluginClass = new PluginClass("type", "name", "desc", "com.company.class", "field", ImmutableMap.<String, PluginPropertyField>of());
// put every combination of abc or def as name, 1.0.0 or 2.0.0 as version, and system or user as scope
plugins.put(new ArtifactId("abc", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), pluginClass);
plugins.put(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), pluginClass);
plugins.put(new ArtifactId("abc", new ArtifactVersion("1.0.0"), ArtifactScope.USER), pluginClass);
plugins.put(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), pluginClass);
plugins.put(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), pluginClass);
plugins.put(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), pluginClass);
plugins.put(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), pluginClass);
plugins.put(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), pluginClass);
// test scope only
ArtifactSelector selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, null);
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, null, null);
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
// test name only
selector = new ArtifactSelector("type", "name", null, "abc", null);
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, "def", null);
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", null, "xyz", null);
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test version only
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("3.0.0"), true, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test range only
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", null, null, new ArtifactVersionRange(new ArtifactVersion("2.0.0"), false, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test name + version
selector = new ArtifactSelector("type", "name", null, "abc", new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, "abc", new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, "def", new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, "def", new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", null, "xyz", new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
try {
selector = new ArtifactSelector("type", "name", null, "abc", new ArtifactVersionRange(new ArtifactVersion("3.0.0"), true, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test name + scope
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "abc", null);
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "def", null);
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "abc", null);
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "def", null);
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "xyz", null);
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test version + scope
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, null, new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("3.0.0"), true, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test name + range
selector = new ArtifactSelector("type", "name", null, "abc", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", null, "abc", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", null, "def", new ArtifactVersionRange(new ArtifactVersion("2.0.0"), false, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test scope + range
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, null, new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, null, new ArtifactVersionRange(new ArtifactVersion("2.0.0"), false, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test name + version + scope
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "def", new ArtifactVersionRange(new ArtifactVersion("2.0.0"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "xyz", new ArtifactVersionRange(new ArtifactVersion("1.0.0"), true, new ArtifactVersion("1.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
// test name + scope + range
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "abc", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "abc", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("abc", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "def", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), false));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("1.0.0"), ArtifactScope.SYSTEM), selector.select(plugins).getKey());
selector = new ArtifactSelector("type", "name", ArtifactScope.USER, "def", new ArtifactVersionRange(new ArtifactVersion("1.0.0-SNAPSHOT"), true, new ArtifactVersion("2.0.0"), true));
Assert.assertEquals(new ArtifactId("def", new ArtifactVersion("2.0.0"), ArtifactScope.USER), selector.select(plugins).getKey());
try {
selector = new ArtifactSelector("type", "name", ArtifactScope.SYSTEM, "abc", new ArtifactVersionRange(new ArtifactVersion("2.0.0"), false, new ArtifactVersion("3.0.0"), true));
selector.select(plugins);
} catch (Exception e) {
// expected
}
}
use of co.cask.cdap.api.plugin.PluginClass in project cdap by caskdata.
the class ArtifactRepository method validatePluginSet.
/**
* Validates the set of plugins for an artifact. Checks that the pair of plugin type and name are unique among
* all plugins in an artifact.
*
* @param plugins the set of plugins to validate
* @throws InvalidArtifactException if there is more than one class with the same type and name
*/
@VisibleForTesting
static void validatePluginSet(Set<PluginClass> plugins) throws InvalidArtifactException {
boolean isInvalid = false;
StringBuilder errMsg = new StringBuilder("Invalid plugins field.");
Set<ImmutablePair<String, String>> existingPlugins = new HashSet<>();
Set<ImmutablePair<String, String>> dupes = new HashSet<>();
for (PluginClass plugin : plugins) {
ImmutablePair<String, String> typeAndName = ImmutablePair.of(plugin.getType(), plugin.getName());
if (!existingPlugins.add(typeAndName) && !dupes.contains(typeAndName)) {
errMsg.append(" Only one plugin with type '");
errMsg.append(typeAndName.getFirst());
errMsg.append("' and name '");
errMsg.append(typeAndName.getSecond());
errMsg.append("' can be present.");
dupes.add(typeAndName);
isInvalid = true;
}
}
// "Invalid plugins. Only one plugin with type 'source' and name 'table' can be present."
if (isInvalid) {
throw new InvalidArtifactException(errMsg.toString());
}
}
Aggregations