Search in sources :

Example 1 with XmlTester

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

the class DSAnnotationTest method testBinds13.

public void testBinds13() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*CheckBinds13");
    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, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/" + CheckBinds13.class.getName() + ".xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    for (int i = 1; i <= 8; i++) {
        xt.assertAttribute(LogService.class.getName(), "scr:component/reference[" + i + "]/@interface");
    }
}
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 2 with XmlTester

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

the class DSAnnotationTest method testEnums.

public void testEnums() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Enums");
    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/enums.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
    xt.assertAttribute("A", "scr:component/reference[1]/@name");
    xt.assertAttribute("", "scr:component/reference[1]/@cardinality");
    xt.assertAttribute("", "scr:component/reference[1]/@policy");
    xt.assertAttribute("", "scr:component/reference[1]/@policy-option");
    xt.assertAttribute("B", "scr:component/reference[2]/@name");
    xt.assertAttribute("1..n", "scr:component/reference[2]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[2]/@policy");
    xt.assertAttribute("greedy", "scr:component/reference[2]/@policy-option");
    xt.assertAttribute("C", "scr:component/reference[3]/@name");
    xt.assertAttribute("1..1", "scr:component/reference[3]/@cardinality");
    xt.assertAttribute("static", "scr:component/reference[3]/@policy");
    xt.assertAttribute("reluctant", "scr:component/reference[3]/@policy-option");
    xt.assertAttribute("D", "scr:component/reference[4]/@name");
    xt.assertAttribute("0..n", "scr:component/reference[4]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[4]/@policy");
    xt.assertAttribute("greedy", "scr:component/reference[4]/@policy-option");
    xt.assertAttribute("E", "scr:component/reference[5]/@name");
    xt.assertAttribute("0..1", "scr:component/reference[5]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[5]/@policy");
    xt.assertAttribute("reluctant", "scr:component/reference[5]/@policy-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 3 with XmlTester

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

the class DSAnnotationTest method testBasic.

public void testBasic() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*_basic");
    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);
    {
        //
        // Test all the DS 1.0 defaults
        //
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$DS10_basic.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        XmlTester xt = new XmlTester(r.openInputStream());
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$DS10_basic", "component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$DS10_basic", "component/@name");
        xt.assertAttribute("", "component/@configuration-policy");
        xt.assertAttribute("", "component/@immediate");
        xt.assertAttribute("", "component/@enabled");
        xt.assertAttribute("", "component/@factory");
        xt.assertAttribute("", "component/service/@servicefactory");
        xt.assertAttribute("", "component/@configuration-pid");
        xt.assertAttribute("", "component/@activate");
        xt.assertAttribute("", "component/@deactivate");
        xt.assertAttribute("", "component/@modified");
        xt.assertAttribute("java.io.Serializable", "component/service/provide[1]/@interface");
        xt.assertAttribute("java.lang.Runnable", "component/service/provide[2]/@interface");
        xt.assertAttribute("0", "count(component/properties)");
        xt.assertAttribute("0", "count(component/property)");
        xt.assertAttribute("xsetLogService", "component/reference[1]/@name");
        xt.assertAttribute("", "component/reference[1]/@target");
        xt.assertAttribute("xsetLogService", "component/reference[1]/@bind");
        xt.assertAttribute("unxsetLogService", "component/reference[1]/@unbind");
        xt.assertAttribute("", "component/reference[1]/@cardinality");
        xt.assertAttribute("", "component/reference[1]/@policy");
        xt.assertAttribute("", "component/reference[1]/@target");
        xt.assertAttribute("", "component/reference[1]/@policy-option");
    }
    {
        //
        // Test package methods >> DS 1.1
        //
        verifyDS11VeryBasic(jar, DS11_1_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_2_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_3_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_4_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_5_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_6_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_7_very_basic.class);
        verifyDS11VeryBasic(jar, DS11_8_very_basic.class);
    }
    {
        //
        // Test the DS 1.1 defaults
        //
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$DS11_basic.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        // #136
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
        // was
        // http://www.osgi.org/xmlns/scr/1.1.0
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_basic", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_basic", "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("", "scr:component/service/@servicefactory");
        xt.assertAttribute("", "scr:component/@configuration-pid");
        xt.assertAttribute("activate", "scr:component/@activate");
        xt.assertAttribute("deactivate", "scr:component/@deactivate");
        xt.assertAttribute("", "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("xsetLogService", "scr:component/reference[1]/@name");
        xt.assertAttribute("", "scr:component/reference[1]/@target");
        xt.assertAttribute("xsetLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unxsetLogService", "scr:component/reference[1]/@unbind");
        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");
    }
    {
        //
        // Test a DS 1.1 bind method results in the DS 1.1 namespace
        //
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$DS11_ref1_basic.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        // #136
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
        // was
        // http://www.osgi.org/xmlns/scr/1.1.0
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_ref1_basic", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_ref1_basic", "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("", "scr:component/service/@servicefactory");
        xt.assertAttribute("", "scr:component/@configuration-pid");
        xt.assertAttribute("activate", "scr:component/@activate");
        xt.assertAttribute("deactivate", "scr:component/@deactivate");
        xt.assertAttribute("", "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("xsetLogService", "scr:component/reference[1]/@name");
        xt.assertAttribute("", "scr:component/reference[1]/@target");
        xt.assertAttribute("xsetLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unxsetLogService", "scr:component/reference[1]/@unbind");
        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");
    }
    {
        //
        // Test a DS 1.1 unbind method results in the DS 1.1 namespace
        //
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$DS11_ref2_basic.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        // #136
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
        // was
        // http://www.osgi.org/xmlns/scr/1.1.0
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_ref2_basic", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$DS11_ref2_basic", "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("", "scr:component/service/@servicefactory");
        xt.assertAttribute("", "scr:component/@configuration-pid");
        xt.assertAttribute("activate", "scr:component/@activate");
        xt.assertAttribute("deactivate", "scr:component/@deactivate");
        xt.assertAttribute("", "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("xsetLogService", "scr:component/reference[1]/@name");
        xt.assertAttribute("", "scr:component/reference[1]/@target");
        xt.assertAttribute("xsetLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unxsetLogService", "scr:component/reference[1]/@unbind");
        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");
    }
    {
        //
        // Test all the defaults
        //
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$Defaults_basic.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        // #136
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
        // was
        // http://www.osgi.org/xmlns/scr/1.1.0
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$Defaults_basic", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("test.component.DSAnnotationTest$Defaults_basic", "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("", "scr:component/service/@servicefactory");
        xt.assertAttribute("", "scr:component/@configuration-pid");
        xt.assertAttribute("open", "scr:component/@activate");
        xt.assertAttribute("close", "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("xsetLogService", "scr:component/reference[1]/@name");
        xt.assertAttribute("", "scr:component/reference[1]/@target");
        xt.assertAttribute("xsetLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unxsetLogService", "scr:component/reference[1]/@unbind");
        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");
    }
    {
        //
        // Test explicit
        //
        Resource r = jar.getResource("OSGI-INF/name.xml");
        assertNotNull(r);
        r.write(System.err);
        XmlTester xt = new XmlTester(r.openInputStream(), "scr", "xmlns");
        // Test the defaults
        xt.assertAttribute("test.component.DSAnnotationTest$Explicit_basic", "scr:component/implementation/@class");
        // Default must be the implementation class
        xt.assertAttribute("name", "scr:component/@name");
        xt.assertAttribute("ignore", "scr:component/@configuration-policy");
        xt.assertAttribute("configuration-pid", "scr:component/@configuration-pid");
        xt.assertAttribute("false", "scr:component/@immediate");
        xt.assertAttribute("false", "scr:component/@enabled");
        xt.assertAttribute("factory", "scr:component/@factory");
        xt.assertAttribute("false", "scr:component/service/@servicefactory");
        xt.assertAttribute("open", "scr:component/@activate");
        xt.assertAttribute("close", "scr:component/@deactivate");
        xt.assertAttribute("changed", "scr:component/@modified");
        xt.assertAttribute("java.lang.Object", "scr:component/service/provide[1]/@interface");
        xt.assertAttribute("1", "count(scr:component/service/provide)");
        xt.assertAttribute("1", "count(scr:component/properties)");
        xt.assertAttribute("2", "count(scr:component/property)");
        xt.assertAttribute("(objectclass=*)", "scr:component/reference[1]/@target");
        xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
        xt.assertAttribute("unset", "scr:component/reference[1]/@unbind");
        xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
        xt.assertAttribute("1..n", "scr:component/reference[1]/@cardinality");
        xt.assertAttribute("dynamic", "scr:component/reference[1]/@policy");
        xt.assertAttribute("(objectclass=*)", "scr:component/reference[1]/@target");
        xt.assertAttribute("2", "count(scr:component/property)");
        xt.assertAttribute("1", "count(scr:component/properties)");
        xt.assertAttribute("resource.props", "scr:component/properties[1]/@entry");
        xt.assertAttribute("greedy", "scr:component/reference[1]/@policy-option");
    }
    Attributes a = getAttr(jar);
    checkProvides(a, SERIALIZABLE_RUNNABLE, OBJECT);
    // n.b. we should merge the 2 logService requires, so when we fix that
    // we'll need to update this test.
    // one is plain, other has cardinality multiple.
    checkRequires(a, "1.3.0", LogService.class.getName(), LogService.class.getName());
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Attributes(java.util.jar.Attributes) XmlTester(aQute.bnd.test.XmlTester) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 4 with XmlTester

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

the class DSAnnotationTest method testReferenceInComponent.

public void testReferenceInComponent() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*ref_on_comp");
    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, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ref_on_comp.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$ref_on_comp", "scr:component/implementation/@class");
    xt.assertAttribute("log", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("1..n", "scr:component/reference[1]/@cardinality");
    xt.assertAttribute("logField", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("1..n", "scr:component/reference[2]/@cardinality");
    xt.assertAttribute("replace", "scr:component/reference[2]/@field-option");
    // TODO field-component-type
    xt.assertAttribute("logMethod", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertAttribute("1..1", "scr:component/reference[3]/@cardinality");
    xt.assertAttribute("setLogMethod", "scr:component/reference[3]/@bind");
    xt.assertAttribute("unsetLogMethod", "scr:component/reference[3]/@unbind");
    xt.assertAttribute("updatedLogMethod", "scr:component/reference[3]/@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 5 with XmlTester

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

the class DSAnnotationTest method testProperties.

public void testProperties() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*x");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    if (!b.check("Cannot convert data blabla to type Integer", "Cannot convert data 3.0 to type Integer"))
        fail();
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null);
    //
    // Test all the defaults
    //
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$PropertiesTestx.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.1.0");
    xt.assertAttribute("1", "scr:component/property[@name='b']/@value");
    xt.assertAttribute("", "scr:component/property[@name='a']/@value");
    xt.assertAttribute("Byte", "scr:component/property[@name='byte']/@type");
    xt.assertAttribute("Boolean", "scr:component/property[@name='boolean']/@type");
    xt.assertAttribute("Character", "scr:component/property[@name='char']/@type");
    xt.assertAttribute("Short", "scr:component/property[@name='short']/@type");
    xt.assertAttribute("Integer", "scr:component/property[@name='integer']/@type");
    xt.assertAttribute("Long", "scr:component/property[@name='long']/@type");
    xt.assertAttribute("Float", "scr:component/property[@name='float']/@type");
    xt.assertAttribute("Double", "scr:component/property[@name='double']/@type");
    xt.assertAttribute("Integer", "scr:component/property[@name='̓̈́͆ͅ']/@type");
}
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)

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