use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testAppWithConfigurationString.
@Test
public void testAppWithConfigurationString() throws Exception {
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ConfigApp");
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "appWithConfig", "1.0.0-SNAPSHOT");
HttpResponse response = addAppArtifact(artifactId, ConfigTestApp.class);
Assert.assertEquals(200, response.getResponseCode());
ConfigTestApp.ConfigClass configuration = new ConfigTestApp.ConfigClass("abc", "def");
String configurationString = GSON.toJson(configuration);
response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), null, null, null, null, configurationString));
Assert.assertEquals(200, response.getResponseCode());
JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), "ConfigApp");
Assert.assertEquals(GSON.toJson(configuration), appDetails.get("configuration").getAsString());
deleteApp(appId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testAppWithConfig.
@Test
public void testAppWithConfig() throws Exception {
Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ConfigApp");
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "appWithConfig", "1.0.0-SNAPSHOT");
HttpResponse response = addAppArtifact(artifactId, ConfigTestApp.class);
Assert.assertEquals(200, response.getResponseCode());
ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), config));
Assert.assertEquals(200, response.getResponseCode());
JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), "ConfigApp");
Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
deleteApp(appId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandlerInternalTest method testListArtifacts.
@Test
public void testListArtifacts() throws Exception {
List<ArtifactInfo> artifactInfoList = null;
ArtifactInfo artifactInfo = null;
// Add a system artifact
String systemArtfiactName = "sysApp";
String systemArtifactVeresion = "1.0.0";
ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, systemArtifactVeresion);
addAppAsSystemArtifacts(systemArtifactId);
// Listing all artifacts in default namespace, should include system artifacts
artifactInfoList = listArtifactsInternal(NamespaceId.DEFAULT.getNamespace());
Assert.assertEquals(1, artifactInfoList.size());
artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.SYSTEM)).findAny().orElse(null);
Assert.assertNotNull(artifactInfo);
Assert.assertEquals(ArtifactScope.SYSTEM, artifactInfo.getScope());
Assert.assertEquals(systemArtfiactName, artifactInfo.getName());
Assert.assertEquals(systemArtifactVeresion, artifactInfo.getVersion());
Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
// Add a user artifact, in addition to the above system artifact
String userArtifactName = "userApp";
String userArtifactVersion = "2.0.0";
ArtifactId userArtifactId = NamespaceId.DEFAULT.artifact(userArtifactName, userArtifactVersion);
addAppAsUserArtifacts(userArtifactId);
// Listing all artifacts in default namespace, should include both user and system artifacts
artifactInfoList = listArtifactsInternal(NamespaceId.DEFAULT.getNamespace());
Assert.assertEquals(2, artifactInfoList.size());
artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.USER)).findAny().orElse(null);
Assert.assertNotNull(artifactInfo);
Assert.assertEquals(ArtifactScope.USER, artifactInfo.getScope());
Assert.assertEquals(userArtifactName, artifactInfo.getName());
Assert.assertEquals(userArtifactVersion, artifactInfo.getVersion());
Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
artifactInfo = artifactInfoList.stream().filter(info -> info.getScope().equals(ArtifactScope.SYSTEM)).findAny().orElse(null);
Assert.assertNotNull(artifactInfo);
Assert.assertEquals(ArtifactScope.SYSTEM, artifactInfo.getScope());
Assert.assertEquals(systemArtfiactName, artifactInfo.getName());
Assert.assertEquals(systemArtifactVeresion, artifactInfo.getVersion());
Assert.assertTrue(artifactInfo.getClasses().getApps().size() > 0);
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandlerInternalTest method testRemoteArtifactRepositoryReaderGetArtifact.
/**
* Test {@link RemoteArtifactRepositoryReader#getArtifact}
*/
@Test
public void testRemoteArtifactRepositoryReaderGetArtifact() throws Exception {
// Add a system artifact
String systemArtfiactName = "sysApp";
String systemArtifactVeresion = "1.0.0";
ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, systemArtifactVeresion);
addAppAsSystemArtifacts(systemArtifactId);
// Fetch ArtifactDetail using RemoteArtifactRepositoryReader and verify
ArtifactRepositoryReader remoteReader = getInjector().getInstance(RemoteArtifactRepositoryReader.class);
ArtifactDetail detail = remoteReader.getArtifact(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertNotNull(detail);
ArtifactDetail expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(detail.equals(expectedDetail));
wipeData();
}
use of io.cdap.cdap.proto.id.ArtifactId in project cdap by caskdata.
the class ArtifactHttpHandlerInternalTest method testRemoteArtifactRepositoryReaderGetArtifactDetails.
/**
* Test {@link RemoteArtifactRepositoryReader#getArtifactDetails}
*/
@Test
public void testRemoteArtifactRepositoryReaderGetArtifactDetails() throws Exception {
// Add an artifact with a number of versions
String systemArtfiactName = "sysApp3";
final int numVersions = 10;
List<ArtifactId> artifactIds = new ArrayList<>();
for (int i = 1; i <= numVersions; i++) {
String version = String.format("%d.0.0", i);
ArtifactId systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, version);
addAppAsSystemArtifacts(systemArtifactId);
artifactIds.add(systemArtifactId);
}
ArtifactRepositoryReader remoteReader = getInjector().getInstance(RemoteArtifactRepositoryReader.class);
ArtifactRange range = null;
List<ArtifactDetail> details = null;
ArtifactId systemArtifactId = null;
ArtifactDetail expectedDetail = null;
int numLimits = 0;
range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion("1.0.0"), new ArtifactVersion(String.format("%d.0.0", numVersions)));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in desc order
numLimits = 1;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(numLimits, details.size());
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(numLimits - 1).equals(expectedDetail));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 3 in desc order
numLimits = 3;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(numLimits, details.size());
for (int i = 0; i < numLimits; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", numVersions - i));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 1 in asec order
details = remoteReader.getArtifactDetails(range, 1, ArtifactSortOrder.ASC);
Assert.assertEquals(1, details.size());
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, "1.0.0");
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(0).equals(expectedDetail));
// Fetch artifacts with the version in range [1.0.0, numVersions.0.0], but limit == 5 in asec order
numLimits = 5;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.ASC);
Assert.assertEquals(numLimits, details.size());
for (int i = 0; i < numLimits; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", i + 1));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
int versionLow = 1;
int versionHigh = numVersions / 2;
range = new ArtifactRange(NamespaceId.SYSTEM.getNamespace(), systemArtfiactName, new ArtifactVersion(String.format("%d.0.0", versionLow)), new ArtifactVersion(String.format("%d.0.0", versionHigh)));
// Fetch artifacts with the version in range [1.0.0, <numVersions/2>.0.0], but limit == numVersions in desc order
numLimits = numVersions;
details = remoteReader.getArtifactDetails(range, numLimits, ArtifactSortOrder.DESC);
Assert.assertEquals(versionHigh - versionLow + 1, details.size());
for (int i = 0; i < versionHigh - versionLow + 1; i++) {
systemArtifactId = NamespaceId.SYSTEM.artifact(systemArtfiactName, String.format("%d.0.0", versionHigh - i));
expectedDetail = getArtifactDetailFromRepository(Id.Artifact.fromEntityId(systemArtifactId));
Assert.assertTrue(details.get(i).equals(expectedDetail));
}
}
Aggregations