final Map<String, String> attr = new HashMap<String, String>();
attr.put(TargetObject.KEY_ID, targetId);
final Map<String, String> tags = new HashMap<String, String>();
final StatefulTargetObject sgo = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
public StatefulTargetObject call() throws Exception {
return m_statefulTargetRepository.preregister(attr, tags);
}
}, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
assertTrue("Without any deployment versions, and no information in the shop, we should not need to approve.", !sgo.needsApprove());
assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
assertEquals("We expect the registration state to be New;", StoreState.New, sgo.getStoreState());
assertEquals(UNKNOWN_VERSION, sgo.getCurrentVersion());
final ArtifactObject b11 = createBasicBundleObject("bundle1", "1", null);
FeatureObject g1 = createBasicFeatureObject("feature1");
FeatureObject g2 = createBasicFeatureObject("feature2"); // note that this feature is not associated to a bundle.
createDynamicBundle2FeatureAssociation(b11, g1);
final DistributionObject l1 = createBasicDistributionObject("distribution1");
m_feature2distributionRepository.create(g1, l1);
m_feature2distributionRepository.create(g2, l1);
runAndWaitForEvent(new Callable<Distribution2TargetAssociation>() {
public Distribution2TargetAssociation call() throws Exception {
return m_distribution2targetRepository.create(l1, sgo.getTargetObject());
}
}, false, Distribution2TargetAssociation.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
assertTrue("We added information that influences our target, so we should need to approve it.", sgo.needsApprove());
assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
assertEquals("We expect the registration state to be Unapproved;", StoreState.Unapproved, sgo.getStoreState());
assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
assertEquals("According to the deployment, this target needs 0 bundles", 0, sgo.getArtifactsFromDeployment().length);
assertEquals(UNKNOWN_VERSION, sgo.getCurrentVersion());
runAndWaitForEvent(new Callable<Object>() {
public Object call() throws Exception {
createBasicDeploymentVersionObject(targetId, "1", b11);
return null;
}
}, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
assertFalse("We manually created a deployment version that reflects the shop, so no approval should be necessary.", sgo.needsApprove());
assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
assertEquals("We expect the registration state to be Approved;", StoreState.Approved, sgo.getStoreState());
assertEquals("According to the shop, this target needs 1 bundle;", 1, sgo.getArtifactsFromShop().length);
assertEquals("According to the deployment, this target needs 1 bundle;", 1, sgo.getArtifactsFromDeployment().length);
runAndWaitForEvent(new Callable<ArtifactObject>() {
public ArtifactObject call() throws Exception {
return createBasicBundleObject("bundle1", "2", null);
}
}, false, ArtifactObject.TOPIC_ADDED, Artifact2FeatureAssociation.TOPIC_CHANGED, TOPIC_STATUS_CHANGED);
assertTrue("We added a new version of a bundle that is used by the target, so approval should be necessary.", sgo.needsApprove());
assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
assertEquals("We expect the registration state to be Unapproved;", StoreState.Unapproved, sgo.getStoreState());
assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
assertEquals("The shop should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromShop()[0].getURL());
assertEquals("According to the deployment, this target needs 1 bundle", 1, sgo.getArtifactsFromDeployment().length);
assertEquals("The deployment should tell use we need bundle URL 'bundle1-1';", "http://bundle1-1", sgo.getArtifactsFromDeployment()[0].getUrl());
assertEquals("1", sgo.getCurrentVersion());
final String newVersion = runAndWaitForEvent(new Callable<String>() {
public String call() throws Exception {
return sgo.approve();
}
}, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
assertFalse("Immediately after approval, no approval is necessary.", sgo.needsApprove());
assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
assertEquals("We expect the registration state to be Approved;", StoreState.Approved, sgo.getStoreState());
assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
assertEquals("The shop should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromShop()[0].getURL());
assertEquals("According to the deployment, this target needs 1 bundle", 1, sgo.getArtifactsFromDeployment().length);
assertEquals("The deployment should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromDeployment()[0].getUrl());
assertEquals( "We expect two deployment versions;", 2, m_deploymentVersionRepository.get().size());
assertEquals(newVersion, sgo.getCurrentVersion());
// clean up this object ourselves; we cannot rely on cleanUp() in this case.
runAndWaitForEvent(new Callable<Object>() {
public Object call() throws Exception {
m_statefulTargetRepository.unregister(targetId);
return null;
}
}, false, TargetObject.TOPIC_REMOVED, TOPIC_REMOVED);
StatefulTargetObject target = findStatefulTarget(targetId);
assertNull("Target should be removed?!", target);
cleanUp();
}