Search in sources :

Example 26 with XmlTester

use of aQute.bnd.test.XmlTester in project bnd by bndtools.

the class DSAnnotationTest method testFinalDynamicCollectionField.

public void testFinalDynamicCollectionField() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*FinalDynamicCollectionField");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkRequires(a, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$FinalDynamicCollectionField.xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute("test.component.DSAnnotationTest$FinalDynamicCollectionField", "scr:component/implementation/@class");
    xt.assertAttribute("logs1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("dynamic", "scr:component/reference[1]/@policy");
    xt.assertAttribute("update", "scr:component/reference[1]/@field-option");
    xt.assertAttribute("logs2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertNoAttribute("scr:component/reference[2]/@policy");
    xt.assertNoAttribute("scr:component/reference[2]/@field-option");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 27 with XmlTester

use of aQute.bnd.test.XmlTester in project bnd by bndtools.

the class DSAnnotationTest method testIssue347.

public void testIssue347() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*issue347");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a, SERIALIZABLE_RUNNABLE);
    checkRequires(a, null, LogService.class.getName());
    {
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$issue347.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$issue347", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$issue347", "scr:component/@name");
        xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
        xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
    }
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 28 with XmlTester

use of aQute.bnd.test.XmlTester in project bnd by bndtools.

the class DSAnnotationTest method testMethods.

public void testMethods() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Methods");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/methods.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
    // use - to make sure no unbind and updated method is set
    xt.assertAttribute("A", "scr:component/reference[1]/@name");
    xt.assertAttribute("setA", "scr:component/reference[1]/@bind");
    xt.assertAttribute("", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("", "scr:component/reference[1]/@updated");
    // override the names for the methods
    xt.assertAttribute("B", "scr:component/reference[2]/@name");
    xt.assertAttribute("setB", "scr:component/reference[2]/@bind");
    xt.assertAttribute("_B", "scr:component/reference[2]/@unbind");
    xt.assertAttribute("__B", "scr:component/reference[2]/@updated");
    xt.assertAttribute("C", "scr:component/reference[3]/@name");
    xt.assertAttribute("setC", "scr:component/reference[3]/@bind");
    xt.assertAttribute("unsetC", "scr:component/reference[3]/@unbind");
    xt.assertAttribute("updatedC", "scr:component/reference[3]/@updated");
    xt.assertAttribute("D", "scr:component/reference[4]/@name");
    xt.assertAttribute("setD", "scr:component/reference[4]/@bind");
    xt.assertAttribute("", "scr:component/reference[4]/@unbind");
    xt.assertAttribute("", "scr:component/reference[4]/@updated");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 29 with XmlTester

use of aQute.bnd.test.XmlTester in project bnd by bndtools.

the class DSAnnotationTest method checkDS13.

private void checkDS13(Jar jar, String name, String pids, String scope) throws Exception, XPathExpressionException {
    Resource r = jar.getResource("OSGI-INF/" + name + ".xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertAttribute("", "scr:component/@configuration-policy");
    xt.assertAttribute("", "scr:component/@immediate");
    xt.assertAttribute("", "scr:component/@enabled");
    xt.assertAttribute("", "scr:component/@factory");
    xt.assertAttribute(scope, "scr:component/service/@scope");
    xt.assertAttribute(pids, "scr:component/@configuration-pid");
    xt.assertAttribute("activate", "scr:component/@activate");
    xt.assertAttribute("deactivate", "scr:component/@deactivate");
    xt.assertAttribute("modified", "scr:component/@modified");
    xt.assertAttribute("java.io.Serializable", "scr:component/service/provide[1]/@interface");
    xt.assertAttribute("java.lang.Runnable", "scr:component/service/provide[2]/@interface");
    xt.assertAttribute("0", "count(scr:component/properties)");
    xt.assertAttribute("0", "count(scr:component/property)");
    xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("", "scr:component/reference[1]/@target");
    xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
    xt.assertAttribute("", "scr:component/reference[1]/@cardinality");
    xt.assertAttribute("", "scr:component/reference[1]/@policy");
    xt.assertAttribute("", "scr:component/reference[1]/@target");
    xt.assertAttribute("", "scr:component/reference[1]/@policy-option");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 30 with XmlTester

use of aQute.bnd.test.XmlTester in project bnd by bndtools.

the class DSAnnotationTest method testInheritance.

public void testInheritance(String key, String value, String extender) throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Bottom");
    b.setProperty(key, value);
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, extender, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/bottom.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
    xt.assertAttribute("PrivateLogService", "scr:component/reference[2]/@name");
    xt.assertAttribute("setPrivateLogService", "scr:component/reference[2]/@bind");
    xt.assertAttribute("unsetPrivateLogService", "scr:component/reference[2]/@unbind");
    // is private in super class
    xt.assertAttribute("", "scr:component/reference[2]/@updated");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Aggregations

XmlTester (aQute.bnd.test.XmlTester)49 Resource (aQute.bnd.osgi.Resource)48 Builder (aQute.bnd.osgi.Builder)39 File (java.io.File)39 Jar (aQute.bnd.osgi.Jar)24 Attributes (java.util.jar.Attributes)18 LogService (org.osgi.service.log.LogService)15 MetatypeVersion (aQute.bnd.metatype.MetatypeVersion)3 TreeSet (java.util.TreeSet)1