Search in sources :

Example 21 with InvalidArtifactException

use of co.cask.cdap.common.InvalidArtifactException in project cdap by caskdata.

the class ArtifactRepositoryTest method testGreatGrandparentsAreInvalid.

@Test
public void testGreatGrandparentsAreInvalid() throws Exception {
    // create child artifact
    co.cask.cdap.proto.id.ArtifactId childId = NamespaceId.DEFAULT.artifact("child", "1.0.0");
    Manifest manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin1.class.getPackage().getName());
    File jarFile = createPluginJar(Plugin1.class, new File(tmpDir, "child-1.0.0.jar"), manifest);
    // add the artifact
    Set<ArtifactRange> parents = ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace().getId(), APP_ARTIFACT_ID.getName(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
    artifactRepository.addArtifact(Id.Artifact.fromEntityId(childId), jarFile, parents, null);
    // create grandchild
    co.cask.cdap.proto.id.ArtifactId grandchildId = NamespaceId.DEFAULT.artifact("grandchild", "1.0.0");
    manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin2.class.getPackage().getName());
    jarFile = createPluginJar(Plugin2.class, new File(tmpDir, "grandchild-1.0.0.jar"), manifest);
    parents = ImmutableSet.of(new ArtifactRange(childId.getNamespace(), childId.getArtifact(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
    artifactRepository.addArtifact(Id.Artifact.fromEntityId(grandchildId), jarFile, parents, null);
    // try and create great grandchild, should fail
    co.cask.cdap.proto.id.ArtifactId greatGrandchildId = NamespaceId.DEFAULT.artifact("greatgrandchild", "1.0.0");
    manifest = createManifest(ManifestFields.EXPORT_PACKAGE, Plugin2.class.getPackage().getName());
    jarFile = createPluginJar(Plugin2.class, new File(tmpDir, "greatgrandchild-1.0.0.jar"), manifest);
    parents = ImmutableSet.of(new ArtifactRange(grandchildId.getNamespace(), grandchildId.getArtifact(), new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0")));
    try {
        artifactRepository.addArtifact(Id.Artifact.fromEntityId(greatGrandchildId), jarFile, parents, null);
        Assert.fail("Artifact repository is not supposed to allow great grandparents.");
    } catch (InvalidArtifactException e) {
    // expected
    }
}
Also used : TestPlugin2(co.cask.cdap.internal.app.plugins.test.TestPlugin2) Plugin2(co.cask.cdap.internal.app.runtime.artifact.plugin.Plugin2) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) Manifest(java.util.jar.Manifest) File(java.io.File) InvalidArtifactException(co.cask.cdap.common.InvalidArtifactException) Test(org.junit.Test)

Aggregations

InvalidArtifactException (co.cask.cdap.common.InvalidArtifactException)21 IOException (java.io.IOException)9 File (java.io.File)8 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)7 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)6 ArtifactAlreadyExistsException (co.cask.cdap.common.ArtifactAlreadyExistsException)6 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)6 NotFoundException (co.cask.cdap.common.NotFoundException)6 HashSet (java.util.HashSet)6 ExecutionException (java.util.concurrent.ExecutionException)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)5 BadRequestException (co.cask.cdap.common.BadRequestException)4 ConflictException (co.cask.cdap.common.ConflictException)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)4 WriteConflictException (co.cask.cdap.internal.app.runtime.artifact.WriteConflictException)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Location (org.apache.twill.filesystem.Location)4 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)3 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)3