import org.osgi.service.useradmin.User;
public class RepositoryAdminTest extends BaseRepositoryAdminTest {
public void testAssociationsWithMovingEndpoints() throws Exception {
final ArtifactObject b1 = createBasicBundleObject("thebundle", "1", null);
final FeatureObject g1 = createBasicFeatureObject("thefeature");
final Artifact2FeatureAssociation bg = runAndWaitForEvent(new Callable<Artifact2FeatureAssociation>() {
public Artifact2FeatureAssociation call() throws Exception {
Map<String, String> properties = new HashMap<String, String>();
properties.put(BundleHelper.KEY_ASSOCIATION_VERSIONSTATEMENT, "[1,3)");
return m_artifact2featureRepository.create(b1, properties, g1, null);
}
}, false, Artifact2FeatureAssociation.TOPIC_ADDED);
assertTrue("The left side of the association should now be b1; we find "
+ bg.getLeft().size() + " bundles on the left side of the association.", (bg.getLeft().size() == 1) && bg.getLeft().contains(b1));
assertTrue("The right side of the association should now be g1.", (bg.getRight().size() == 1) && bg.getRight().contains(g1));
assertEquals("b1 should be assocated with g1", g1, b1.getFeatures().get(0));
assertEquals("g1 should be assocated with b1", b1, g1.getArtifacts().get(0));
final ArtifactObject b2 = runAndWaitForEvent(new Callable<ArtifactObject>() {
public ArtifactObject call() throws Exception {
return createBasicBundleObject("thebundle", "2", null);
}
}, false, Artifact2FeatureAssociation.TOPIC_CHANGED);
assertTrue("The left side of the association should no longer be b1; we find "
+ bg.getLeft().size() + " bundles.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b1));
assertTrue("The left side of the association should now be b2.", (bg.getLeft().size() == 1) && bg.getLeft().contains(b2));
assertTrue("The right side of the association should now be g1.", (bg.getRight().size() == 1) && bg.getRight().contains(g1));
assertEquals("b1 should not be associated with any feature.", 0, b1.getFeatures().size());
assertEquals("b2 should now be assocation with g1", g1, b2.getFeatures().get(0));
assertEquals("g1 should be assocation with b2", b2, g1.getArtifacts().get(0));
assertEquals("g1 should be associated with one bundle", 1, g1.getArtifacts().size());
ArtifactObject b3 = createBasicBundleObject("thebundle", "3", null);
assertTrue("The left side of the association should no longer be b1.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b1));
assertTrue("The left side of the association should now be b2.", (bg.getLeft().size() == 1) && bg.getLeft().contains(b2));
assertTrue("The left side of the association should not be b3.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b3));
assertTrue("The right side of the association should now be g1.", (bg.getRight().size() == 1) && bg.getRight().contains(g1));
assertEquals("b1 should not be associated with any feature.", 0, b1.getFeatures().size());
assertEquals("b2 should now be assocation with g1", g1, b2.getFeatures().get(0));
assertEquals("b3 should not be associated with any feature.", 0, b3.getFeatures().size());
assertEquals("g1 should be assocation with b2", b2, g1.getArtifacts().get(0));
assertEquals("g1 should be associated with one bundle", 1, g1.getArtifacts().size());
ArtifactObject b15 = createBasicBundleObject("thebundle", "1.5", null);
assertTrue("The left side of the association should no longer be b1.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b1));
assertTrue("The left side of the association should not be b15.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b15));
assertTrue("The left side of the association should now be b2.", (bg.getLeft().size() == 1) && bg.getLeft().contains(b2));
assertTrue("The left side of the association should not be b3.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b3));
assertTrue("The right side of the association should now be g1.", (bg.getRight().size() == 1) && bg.getRight().contains(g1));
assertEquals("b1 should not be associated with any feature.", 0, b1.getFeatures().size());
assertEquals("b15 should not be associated with any feature.", 0, b15.getFeatures().size());
assertEquals("b2 should now be assocation with g1", g1, b2.getFeatures().get(0));
assertEquals("b3 should not be associated with any feature.", 0, b3.getFeatures().size());
assertEquals("g1 should be assocation with b2", b2, g1.getArtifacts().get(0));
assertEquals("g1 should be associated with one bundle", 1, g1.getArtifacts().size());
runAndWaitForEvent(new Callable<Object>() {
public Object call() throws Exception {
m_artifactRepository.remove(b2);
return null;
}
}, false, Artifact2FeatureAssociation.TOPIC_CHANGED);
// note that we cannot test anything for b2: this has been removed, and now has no
// defined state.
assertTrue("The left side of the association should no longer be b1.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b1));
assertTrue("The left side of the association should now be b15.", (bg.getLeft().size() == 1) && bg.getLeft().contains(b15));
assertTrue("The left side of the association should not be b3.", (bg.getLeft().size() == 1) && !bg.getLeft().contains(b3));
assertTrue("The right side of the association should now be g1.", (bg.getRight().size() == 1) && bg.getRight().contains(g1));
assertEquals("b1 should not be associated with any feature.", 0, b1.getFeatures().size());
assertEquals("b15 should now be assocation with g1", g1, b15.getFeatures().get(0));
assertEquals("b3 should not be associated with any feature.", 0, b3.getFeatures().size());
assertEquals("g1 should be assocation with b15", b15, g1.getArtifacts().get(0));
assertEquals("g1 should be associated with one bundle", 1, g1.getArtifacts().size());
cleanUp();