use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.
the class TestFrameworkTestRun method testAppVersionsCreation.
@Test
public void testAppVersionsCreation() throws Exception {
ArtifactId artifactId = new ArtifactId(NamespaceId.DEFAULT.getNamespace(), "cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version1");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS1", "tD1", "tV1"));
ApplicationManager appManager = deployApplication(appId, createRequest);
ServiceManager serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
URL serviceURL = serviceManager.getServiceURL();
Gson gson = new Gson();
Assert.assertEquals("tV1", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
appId = new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "AppV1", "version2");
createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("tS2", "tD2", "tV2"));
appManager = deployApplication(appId, createRequest);
serviceManager = appManager.getServiceManager(ConfigTestApp.SERVICE_NAME);
serviceManager.start();
serviceURL = serviceManager.getServiceURL();
Assert.assertEquals("tV2", gson.fromJson(callServiceGet(serviceURL, "ping"), String.class));
serviceManager.stop();
}
use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.
the class TestFrameworkTestRun method testInvalidAppWithDuplicateDatasets.
@Test
public void testInvalidAppWithDuplicateDatasets() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("invalid-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, AppWithDuplicateData.class);
ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("test-plugin", "1.0.0-SNAPSHOT");
addPluginArtifact(pluginArtifactId, artifactId, ToStringPlugin.class);
ApplicationId appId = NamespaceId.DEFAULT.app("InvalidApp");
for (int choice = 4; choice > 0; choice /= 2) {
try {
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass((choice == 4), (choice == 2), (choice == 1)));
deployApplication(appId, createRequest);
// fail if we succeed with application deployment
Assert.fail();
} catch (Exception e) {
// expected
}
}
AppRequest<AppWithDuplicateData.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new AppWithDuplicateData.ConfigClass(false, false, false));
deployApplication(appId, createRequest);
}
use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.
the class UnitTestManager method deployApplication.
@Override
public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) {
Preconditions.checkNotNull(applicationClz, "Application class cannot be null.");
Type configType = Artifacts.getConfigType(applicationClz);
try {
ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT");
addAppArtifact(artifactId, applicationClz);
if (configObject == null) {
configObject = (Config) TypeToken.of(configType).getRawType().newInstance();
}
Application app = applicationClz.newInstance();
MockAppConfigurer configurer = new MockAppConfigurer(app);
app.configure(configurer, new DefaultApplicationContext<>(configObject));
ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName());
ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion());
appFabricClient.deployApplication(applicationId.toId(), new AppRequest(artifactSummary, configObject));
return appManagerFactory.create(applicationId);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations