use of org.apache.aries.application.modelling.WrappedReferenceMetadata in project aries by apache.
the class ParserProxyTest method testParseAllServiceElements.
@Test
public void testParseAllServiceElements() throws Exception {
File bpXml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml");
File bp2Xml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp2.xml");
List<WrappedServiceMetadata> services = new ArrayList<WrappedServiceMetadata>();
List<WrappedReferenceMetadata> references = new ArrayList<WrappedReferenceMetadata>();
FileInputStream fis = new FileInputStream(bpXml);
ParsedServiceElements bpelem = _parserProxy.parseAllServiceElements(fis);
services.addAll(bpelem.getServices());
references.addAll(bpelem.getReferences());
fis = new FileInputStream(bp2Xml);
bpelem = _parserProxy.parseAllServiceElements(fis);
services.addAll(bpelem.getServices());
references.addAll(bpelem.getReferences());
// We expect:
// bp.xml: 3 services and 2 references
// bp2.xml: 3 services and a reference list
//
assertTrue("Six services expected, not " + services.size(), services.size() == 6);
assertTrue("Three references expected, not " + references.size(), references.size() == 3);
Set<WrappedServiceMetadata> expectedServices = getTest2ExpectedServices();
// ServiceResultSet will contain some services with autogenerated names starting '.' so we can't
// use a straight Set.equals(). We could add the autogenerated names to the expected results but instead
// let's test that differsOnlyByName() works
int serviceMatchesFound = 0;
for (WrappedServiceMetadata result : services) {
Iterator<WrappedServiceMetadata> it = expectedServices.iterator();
while (it.hasNext()) {
WrappedServiceMetadata next = it.next();
if (result.equals(next) || result.identicalOrDiffersOnlyByName(next)) {
serviceMatchesFound++;
it.remove();
}
}
}
assertEquals("Parsed services are wrong: " + expectedServices + " unmatched ", 6, serviceMatchesFound);
Set<WrappedReferenceMetadata> expectedReferences = getTest2ExpectedReferences();
Set<WrappedReferenceMetadata> results = new HashSet<WrappedReferenceMetadata>(references);
assertTrue("Parsed references are not as we'd expected: " + results.toString() + " != " + expectedReferences, results.equals(expectedReferences));
}
Aggregations