// Empty tag map to be reused througout test
final Map<String, String> tags = new HashMap<String, String>();
// First, create a bundle and two artifacts, but do not provide a processor for the artifacts.
ArtifactObject b1 = createBasicBundleObject("bundle1");
Map<String, String> attr = new HashMap<String, String>();
attr.put(ArtifactObject.KEY_URL, "http://myobject");
attr.put(ArtifactObject.KEY_PROCESSOR_PID, "my.processor.pid");
attr.put(ArtifactHelper.KEY_MIMETYPE, "mymime");
ArtifactObject a1 = m_artifactRepository.create(attr, tags);
attr = new HashMap<String, String>();
attr.put(ArtifactObject.KEY_URL, "http://myotherobject");
attr.put(ArtifactObject.KEY_PROCESSOR_PID, "my.processor.pid");
attr.put(ArtifactObject.KEY_RESOURCE_ID, "mymime");
attr.put(ArtifactHelper.KEY_MIMETYPE, "mymime");
ArtifactObject a2 = m_artifactRepository.create(attr, tags);
FeatureObject g = createBasicFeatureObject("feature");
DistributionObject l = createBasicDistributionObject("distribution");
attr = new HashMap<String, String>();
attr.put(TargetObject.KEY_ID, "myTarget");
StatefulTargetObject sgo = m_statefulTargetRepository.preregister(attr, tags);
m_artifact2featureRepository.create(b1, g);
m_artifact2featureRepository.create(a1, g);
m_artifact2featureRepository.create(a2, g);
m_feature2distributionRepository.create(g, l);
m_distribution2targetRepository.create(l, sgo.getTargetObject());
sgo.approve();
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_repositoryAdmin.commit();
return null;
}
}, false, TOPIC_STATUS_CHANGED);
assertEquals("Store state for target should still be new, because the resource processor is missing.", StoreState.New, sgo.getStoreState());
// Now, add a processor for the artifact.
attr = new HashMap<String, String>();
attr.put(ArtifactObject.KEY_URL, "http://myprocessor");
attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
attr.put(BundleHelper.KEY_VERSION, "1.0.0");
attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);
ArtifactObject b2 = m_artifactRepository.create(attr, tags);
sgo.approve();
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_repositoryAdmin.commit();
return null;
}
}, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
DeploymentVersionObject dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());
DeploymentArtifact[] toDeploy = dep.getDeploymentArtifacts();
assertEquals("We expect to find four artifacts to deploy;", 4, toDeploy.length);
DeploymentArtifact bundle1 = toDeploy[0];
assertEquals(b1.getURL(), bundle1.getUrl());
DeploymentArtifact bundle2 = toDeploy[1];
assertEquals(b2.getURL(), bundle2.getUrl());
assertEquals("true", bundle2.getDirective(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER));
DeploymentArtifact artifact1 = toDeploy[2];
assertEquals(a1.getURL(), artifact1.getUrl());
assertEquals("my.processor.pid", artifact1.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
DeploymentArtifact artifact2 = toDeploy[3];
assertEquals(a2.getURL(), artifact2.getUrl());
assertEquals("my.processor.pid", artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
assertEquals(a2.getResourceId(), artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_RESOURCE_ID));
// Now, add a new version of the processor (ACE-373)
assertFalse("There should be no changes.", sgo.needsApprove());
attr = new HashMap<String, String>();
attr.put(ArtifactObject.KEY_URL, "http://myprocessor/v2");
attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
attr.put(BundleHelper.KEY_VERSION, "2.0.0");
attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);
ArtifactObject b3 = m_artifactRepository.create(attr, tags);
assertTrue("By adding a resource processor, we should have triggered a change that needs to be approved.", sgo.needsApprove());
sgo.approve();
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_repositoryAdmin.commit();
return null;
}
}, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());
toDeploy = dep.getDeploymentArtifacts();
assertEquals("We expect to find four artifacts to deploy;", 4, toDeploy.length);
boolean foundBundle = false;
boolean foundProcessor = false;
boolean foundArtifact1 = false;
boolean foundArtifact2 = false;
for (DeploymentArtifact a : toDeploy) {
String url = a.getUrl();
if (url.equals(b1.getURL())) {
foundBundle = true;
}
else if (url.equals(b3.getURL())) {
assertEquals("true", a.getDirective(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER));
foundProcessor = true;
}
else if (url.equals(a1.getURL())) {
assertEquals("my.processor.pid", a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));