Search in sources :

Example 31 with XmlTester

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

the class DSAnnotationTest method testFieldCollectionType.

public void testFieldCollectionType() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*TestFieldCollectionType");
    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/" + TestFieldCollectionType.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");
    xt.assertNamespace("http://www.osgi.org/xmlns/scr/v1.3.0");
    xt.assertAttribute("propsField", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("propsField", "scr:component/reference[1]/@field");
    xt.assertAttribute("properties", "scr:component/reference[1]/@field-collection-type");
    xt.assertAttribute("serviceField", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("serviceField", "scr:component/reference[2]/@field");
    xt.assertAttribute("service", "scr:component/reference[2]/@field-collection-type");
    xt.assertAttribute("soField", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertAttribute("soField", "scr:component/reference[3]/@field");
    xt.assertAttribute("serviceobjects", "scr:component/reference[3]/@field-collection-type");
    xt.assertAttribute("srField", "scr:component/reference[4]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[4]/@interface");
    xt.assertAttribute("srField", "scr:component/reference[4]/@field");
    xt.assertAttribute("reference", "scr:component/reference[4]/@field-collection-type");
    xt.assertAttribute("tupleField", "scr:component/reference[5]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[5]/@interface");
    xt.assertAttribute("tupleField", "scr:component/reference[5]/@field");
    xt.assertAttribute("tuple", "scr:component/reference[5]/@field-collection-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) LogService(org.osgi.service.log.LogService)

Example 32 with XmlTester

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

the class DSAnnotationTest method checkConfigurationPolicy.

void checkConfigurationPolicy(Jar jar, Class<?> clazz, String option) throws Exception, XPathExpressionException {
    Resource r = jar.getResource("OSGI-INF/" + clazz.getName() + ".xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
    xt.assertNamespace("http://www.osgi.org/xmlns/scr/v1.1.0");
    xt.assertAttribute(option, "scr:component/@configuration-policy");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 33 with XmlTester

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

the class DSAnnotationTest method verifyDS11VeryBasic.

private void verifyDS11VeryBasic(Jar jar, Class<?> clazz) throws Exception, XPathExpressionException {
    String className = clazz.getName();
    Resource r = jar.getResource("OSGI-INF/" + className + ".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(className, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(className, "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("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("", "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 34 with XmlTester

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

the class DSAnnotationTest method testMismatchedUnbind.

public void testMismatchedUnbind() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*MismatchedUnbind");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 0, 8);
    Attributes a = getAttr(jar);
    checkRequires(a, null, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$MismatchedUnbind.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");
    xt.assertAttribute("LogService10", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("setLogService10", "scr:component/reference[1]/@bind");
    xt.assertNoAttribute("scr:component/reference[1]/@unbind");
    xt.assertNoAttribute("scr:component/reference[1]/@updated");
    xt.assertAttribute("LogService11", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("setLogService11", "scr:component/reference[2]/@bind");
    xt.assertNoAttribute("scr:component/reference[2]/@unbind");
    xt.assertAttribute("LogService13", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertAttribute("setLogService13", "scr:component/reference[3]/@bind");
    xt.assertNoAttribute("scr:component/reference[3]/@unbind");
}
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 35 with XmlTester

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

the class DSAnnotationTest method testBinds.

public void testBinds(String extender) throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*CheckBinds");
    if (extender != null)
        b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "extender");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS + ".min", "version;minimum=1.2.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, extender, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/prototypes.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("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("bindLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unbindLogService", "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)

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