*/
@Test(groups = { TestUtils.UNIT })
public void testAssociations() {
initializeRepositoryAdmin();
// Create two, rather boring, artifacts.
ArtifactObject b1 = createBasicArtifactObject("artifact1");
ArtifactObject b2 = createBasicArtifactObject("artifact2");
// Create three features.
FeatureObject g1 = createBasicFeatureObject("feature1");
FeatureObject g2 = createBasicFeatureObject("feature2");
FeatureObject g3 = createBasicFeatureObject("feature3");
// Create some associations.
Artifact2FeatureAssociation b2g1 = m_artifact2FeatureRepository.create(b1, g2);
assert b2g1 != null;
Artifact2FeatureAssociation b2g2 = m_artifact2FeatureRepository.create(b2, g1);
assert b2g2 != null;
Artifact2FeatureAssociation b2g3 = m_artifact2FeatureRepository.create(b1, g3);
assert b2g3 != null;
Artifact2FeatureAssociation b2g4 = m_artifact2FeatureRepository.create(b2, g3);
assert b2g4 != null;
// Do some basic checks on the repositories.
assert m_artifactRepository.get().size() == 2 : "We should have two artifacts in our repository; we found " + m_artifactRepository.get().size() + ".";
assert m_featureRepository.get().size() == 3 : "We should have three features in our repository; we found " + m_featureRepository.get().size() + ".";
assert m_artifact2FeatureRepository.get().size() == 4 : "We should have four associations in our repository; we found " + m_artifact2FeatureRepository.get().size() + ".";
assert (b2g4.getLeft().size() == 1) && b2g4.getLeft().contains(b2) : "The left side of the fourth association should be artifact 2.";
assert (b2g4.getRight().size() == 1) && b2g4.getRight().contains(g3) : "The right side of the fourth association should be feature 3.";
// Check the wiring: what is wired to what?
List<FeatureObject> b1features = b1.getFeatures();
List<FeatureObject> b2features = b2.getFeatures();
List<ArtifactObject> g1artifacts = g1.getArtifacts();
List<ArtifactObject> g2artifacts = g2.getArtifacts();
List<ArtifactObject> g3artifacts = g3.getArtifacts();
List<DistributionObject> g1distributions = g1.getDistributions();
List<DistributionObject> g2distributions = g2.getDistributions();
List<DistributionObject> g3distributions = g3.getDistributions();
assert g1distributions.size() == 0 : "Feature one should not have any associations to distributions; we found " + g1distributions.size() + ".";
assert g2distributions.size() == 0 : "Feature two should not have any associations to distributions; we found " + g2distributions.size() + ".";
assert g3distributions.size() == 0 : "Feature three should not have any associations to distributions; we found " + g3distributions.size() + ".";
List<FeatureObject> b1expectedFeatures = new ArrayList<FeatureObject>();
b1expectedFeatures.add(g2);
b1expectedFeatures.add(g3);
List<FeatureObject> b2expectedFeatures = new ArrayList<FeatureObject>();
b2expectedFeatures.add(g1);
b2expectedFeatures.add(g3);
List<ArtifactObject> g1expectedArtifacts = new ArrayList<ArtifactObject>();
g1expectedArtifacts.add(b2);
List<ArtifactObject> g2expectedArtifacts = new ArrayList<ArtifactObject>();
g2expectedArtifacts.add(b1);
List<ArtifactObject> g3expectedArtifacts = new ArrayList<ArtifactObject>();
g3expectedArtifacts.add(b1);
g3expectedArtifacts.add(b2);
assert b1features.containsAll(b1expectedFeatures) && b1expectedFeatures.containsAll(b1features) : "b1 should be associated to exactly features 2 and 3.";
assert b2features.containsAll(b2expectedFeatures) && b2expectedFeatures.containsAll(b2features) : "b2 should be associated to exactly features 1 and 3.";
assert g1artifacts.containsAll(g1expectedArtifacts) && g1expectedArtifacts.containsAll(g1artifacts) : "g1 should be associated to exactly artifact 2.";
assert g2artifacts.containsAll(g2expectedArtifacts) && g2expectedArtifacts.containsAll(g2artifacts) : "g2 should be associated to exactly artifact 1.";
assert g3artifacts.containsAll(g3expectedArtifacts) && g3expectedArtifacts.containsAll(g3artifacts) : "g3 should be associated to exactly artifacts 1 and 2.";
m_artifact2FeatureRepository.remove(b2g4);
b1features = b1.getFeatures();
b2features = b2.getFeatures();
g1artifacts = g1.getArtifacts();
g2artifacts = g2.getArtifacts();
g3artifacts = g3.getArtifacts();
b2expectedFeatures.remove(g3);