Search in sources :

Example 36 with XmlTester

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

the class DSAnnotationTest method checkDS14AnnoConfigNames.

private void checkDS14AnnoConfigNames(Jar jar, String name) 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.4.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("", "scr:component/service/@scope");
    xt.assertAttribute("", "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("2", "count(scr:component/property)");
    xt.assertAttribute("foo", "scr:component/property[@name='test.my-String7']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='test.my-String7']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='test.config.names14']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='test.config.names14']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 37 with XmlTester

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

the class DSAnnotationTest method testFieldInjection.

public void testFieldInjection() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*TestFieldInjection");
    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/" + TestFieldInjection.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("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("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("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("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("tupleField2", "scr:component/reference[6]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[6]/@interface");
    xt.assertAttribute("tupleField2", "scr:component/reference[6]/@field");
    xt.assertAttribute("tupleField3", "scr:component/reference[7]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[7]/@interface");
    xt.assertAttribute("tupleField3", "scr:component/reference[7]/@field");
}
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 38 with XmlTester

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

the class DSAnnotationTest method testPrefixCollisionExtraAttributes.

public void testPrefixCollisionExtraAttributes() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$PrefixCollisionExtraAttributes*");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    String name = PrefixCollisionExtraAttributes.class.getName();
    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", "foo", "org.foo.extensions.v1", "foo1", "org.foo.extensions.v2");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertCount(10, "scr:component/@*");
    xt.assertAttribute("bar", "scr:component/@foo:stringAttr");
    xt.assertAttribute("A", "scr:component/@foo:fooAttr");
    xt.assertAttribute("true", "scr:component/@foo:booleanAttr");
    xt.assertAttribute("bar3", "scr:component/@foo1:stringAttr3");
    xt.assertAttribute("B", "scr:component/@foo1:fooAttr3");
    xt.assertAttribute("false", "scr:component/@foo1:booleanAttr3");
    xt.assertCount(3, "scr:component/reference");
    xt.assertCount(6, "scr:component/reference[1]/@*");
    xt.assertAttribute("bax", "scr:component/reference[1]/@foo:stringAttr2");
    xt.assertAttribute("A", "scr:component/reference[1]/@foo:fooAttr2");
    xt.assertAttribute("true", "scr:component/reference[1]/@foo:booleanAttr2");
    xt.assertCount(3, "scr:component/reference[2]/@*");
    xt.assertCount(6, "scr:component/reference[3]/@*");
    xt.assertAttribute("baz", "scr:component/reference[3]/@foo:stringAttr2");
    xt.assertAttribute("B", "scr:component/reference[3]/@foo:fooAttr2");
    xt.assertAttribute("false", "scr:component/reference[3]/@foo:booleanAttr2");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 39 with XmlTester

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

the class DSAnnotationTest method checkDSFelix12.

private void checkDSFelix12(Jar jar, String name) 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", FELIX_1_2);
    // 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("", "scr:component/service/@servicefactory");
    xt.assertAttribute("", "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 40 with XmlTester

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

the class DSAnnotationTest method testConfigPolicySetsNamespace.

public void testConfigPolicySetsNamespace() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*TestConfigPolicy");
    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);
    Resource r = jar.getResource("OSGI-INF/testConfigPolicy.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");
}
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