/** * Improper Manifest file should throw an exception. */ @Test(expected = ExecutionException.class) public void testImproperOrNoManifestFile() throws Exception { // Create an JAR without the MainClass set. File deployFile = TMP_FOLDER.newFile(); try (JarOutputStream output = new JarOutputStream(new FileOutputStream(deployFile), new Manifest())) { output.putNextEntry(new JarEntry("dummy")); } Location jarLoc = Locations.toLocation(deployFile); ArtifactId artifactId = new ArtifactId("dummy", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, jarLoc); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, "some.class.name", null, null, null); AppFabricTestHelper.getLocalManager().deploy(info).get(); }
@Test(expected = ExecutionException.class) public void testInvalidConfigPipeline() throws Exception { Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class); ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "BadApp", null, GSON.toJson("invalid")); AppFabricTestHelper.getLocalManager().deploy(info).get(); } }
public static ApplicationWithPrograms deployApplicationWithManager(Id.Namespace namespace, Class<?> appClass, Supplier<File> folderSupplier, Config config) throws Exception { ensureNamespaceExists(namespace.toEntityId()); Location deployedJar = createAppJar(appClass, folderSupplier); ArtifactVersion artifactVersion = new ArtifactVersion(String.format("1.0.%d", System.currentTimeMillis())); ArtifactId artifactId = new ArtifactId(appClass.getSimpleName(), artifactVersion, ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar); ArtifactRepository artifactRepository = getInjector().getInstance(ArtifactRepository.class); artifactRepository.addArtifact(Id.Artifact.fromEntityId(Artifacts.toArtifactId(namespace.toEntityId(), artifactId)), new File(deployedJar.toURI())); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, namespace.toEntityId(), appClass.getName(), null, null, config == null ? null : new Gson().toJson(config)); return getLocalManager().deploy(info).get(); }
@Test public void testValidConfigPipeline() throws Exception { Location deployedJar = AppJarHelper.createDeploymentJar(lf, ConfigTestApp.class); ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myTable"); ArtifactId artifactId = new ArtifactId("configtest", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, ConfigTestApp.class.getName(), "MyApp", null, GSON.toJson(config)); AppFabricTestHelper.getLocalManager().deploy(info).get(); }
/** * Good pipeline with good tests. */ @Test public void testGoodPipeline() throws Exception { Location deployedJar = AppJarHelper.createDeploymentJar(lf, AllProgramsApp.class); ArtifactId artifactId = new ArtifactId("app", new ArtifactVersion("1.0.0-SNAPSHOT"), ArtifactScope.USER); ArtifactDescriptor artifactDescriptor = new ArtifactDescriptor(artifactId, deployedJar); AppDeploymentInfo info = new AppDeploymentInfo(artifactDescriptor, NamespaceId.DEFAULT, AllProgramsApp.class.getName(), null, null, null); ApplicationWithPrograms input = AppFabricTestHelper.getLocalManager().deploy(info).get(); ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp()); // Validate that all programs are being captured by the deployment pipeline Map<ProgramType, Set<String>> programByTypes = new HashMap<>(); for (ProgramDescriptor desc : input.getPrograms()) { ProgramId programId = desc.getProgramId(); programByTypes.computeIfAbsent(programId.getType(), k -> new HashSet<>()).add(programId.getProgram()); } for (co.cask.cdap.api.app.ProgramType programType : co.cask.cdap.api.app.ProgramType.values()) { Assert.assertEquals(appSpec.getProgramsByType(programType), programByTypes.getOrDefault(ProgramType.valueOf(programType.name()), Collections.emptySet())); } }