Search in sources :

Example 1 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class FlowVerificationTest method testFlowWithMoreOutputThanWhatInputCanHandle.

@Test
public void testFlowWithMoreOutputThanWhatInputCanHandle() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowSpec = new FlowVerification();
    for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
        VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
        // that is not connected to any input to flowlet CountByField.
        if (entry.getValue().getName().equals("WordCountFlow")) {
            Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
        } else {
            Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
        }
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class FlowVerificationTest method testFlowMissingConnection.

/**
   * This test that verification of flow connections
   */
@Test
public void testFlowMissingConnection() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new NoConsumerApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowVerifier = new FlowVerification();
    for (FlowSpecification flowSpec : appSpec.getFlows().values()) {
        VerifyResult result = flowVerifier.verify(new ApplicationId("test", newSpec.getName()), flowSpec);
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class ApplicationVerificationTest method testGoodApplication.

/**
   * Good test
   */
@Test
public void testGoodApplication() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    ApplicationVerification app = new ApplicationVerification();
    VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
    Assert.assertTrue(result.getMessage(), result.getStatus() == VerifyResult.Status.SUCCESS);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 4 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class ProgramGenerationStageTest method testProgramGenerationForToyApp.

@Test
public void testProgramGenerationForToyApp() throws Exception {
    cConf.set(Constants.AppFabric.OUTPUT_DIR, "programs");
    LocationFactory lf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    // have to do this since we are not going through the route of create namespace -> deploy application
    // in real scenarios, the namespace directory would already be created
    Location namespaceLocation = lf.create(DefaultId.APPLICATION.getNamespace());
    Locations.mkdirsIfNotExists(namespaceLocation);
    LocationFactory jarLf = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    Location appArchive = AppJarHelper.createDeploymentJar(jarLf, ToyApp.class);
    ApplicationSpecification appSpec = Specifications.from(new ToyApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    ProgramGenerationStage pgmStage = new ProgramGenerationStage(new NoOpAuthorizer(), new AuthenticationTestContext());
    // Can do better here - fixed right now to run the test.
    pgmStage.process(new StageContext(Object.class));
    pgmStage.process(new ApplicationDeployable(NamespaceId.DEFAULT.artifact("ToyApp", "1.0"), appArchive, DefaultId.APPLICATION, newSpec, null, ApplicationDeployScope.USER));
    Assert.assertTrue(true);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ToyApp(co.cask.cdap.ToyApp) AuthenticationTestContext(co.cask.cdap.security.auth.context.AuthenticationTestContext) NoOpAuthorizer(co.cask.cdap.security.spi.authorization.NoOpAuthorizer) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) StageContext(co.cask.cdap.internal.pipeline.StageContext) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 5 with ApplicationSpecificationAdapter

use of co.cask.cdap.internal.app.ApplicationSpecificationAdapter in project cdap by caskdata.

the class FlowVerificationTest method testValidFlow.

@Test
public void testValidFlow() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    FlowVerification flowSpec = new FlowVerification();
    for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
        VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
        Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) WebCrawlApp(co.cask.cdap.WebCrawlApp) FlowSpecification(co.cask.cdap.api.flow.FlowSpecification) ApplicationSpecificationAdapter(co.cask.cdap.internal.app.ApplicationSpecificationAdapter) ReflectionSchemaGenerator(co.cask.cdap.internal.io.ReflectionSchemaGenerator) VerifyResult(co.cask.cdap.app.verification.VerifyResult) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)10 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)10 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)10 Test (org.junit.Test)10 VerifyResult (co.cask.cdap.app.verification.VerifyResult)4 ApplicationId (co.cask.cdap.proto.id.ApplicationId)4 WebCrawlApp (co.cask.cdap.WebCrawlApp)3 FlowSpecification (co.cask.cdap.api.flow.FlowSpecification)3 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)3 Location (org.apache.twill.filesystem.Location)3 LocationFactory (org.apache.twill.filesystem.LocationFactory)3 ToyApp (co.cask.cdap.ToyApp)2 WordCountApp (co.cask.cdap.WordCountApp)2 CloseableClassLoader (co.cask.cdap.api.artifact.CloseableClassLoader)2 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)2 Configurator (co.cask.cdap.app.deploy.Configurator)2 QueueSpecificationGenerator (co.cask.cdap.app.queue.QueueSpecificationGenerator)2 DummyProgramRunnerFactory (co.cask.cdap.app.runtime.DummyProgramRunnerFactory)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)2