Search in sources :

Example 1 with WrappedReferenceMetadata

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));
}
Also used : WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ArrayList(java.util.ArrayList) WrappedReferenceMetadata(org.apache.aries.application.modelling.WrappedReferenceMetadata) FileInputStream(java.io.FileInputStream) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ParsedServiceElements (org.apache.aries.application.modelling.ParsedServiceElements)1 WrappedReferenceMetadata (org.apache.aries.application.modelling.WrappedReferenceMetadata)1 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)1 Test (org.junit.Test)1