Search in sources :

Example 16 with XmlTester

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

the class DSAnnotationTest method checkDS13Anno.

private void checkDS13Anno(Jar jar, String name, String pids) 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("", "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("18", "count(scr:component/property)");
    xt.assertAttribute("foo", "scr:component/property[@name='myString']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString']/@type");
    xt.assertTrimmedAttribute("foo\\nbar", "scr:component/property[@name='myStringArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myStringArray']/@type");
    xt.assertTrimmedAttribute("baz", "scr:component/property[@name='mySingleStringArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleStringArray']/@type");
    xt.assertAttribute("1", "scr:component/property[@name='myInt']/@value");
    xt.assertAttribute("Integer", "scr:component/property[@name='myInt']/@type");
    xt.assertTrimmedAttribute("2\\n3", "scr:component/property[@name='myIntArray']");
    xt.assertAttribute("Integer", "scr:component/property[@name='myIntArray']/@type");
    xt.assertTrimmedAttribute("4", "scr:component/property[@name='mySingleIntArray']");
    xt.assertAttribute("Integer", "scr:component/property[@name='mySingleIntArray']/@type");
    xt.assertAttribute("test.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='myClass']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myClass']/@type");
    xt.assertTrimmedAttribute("test.component.DSAnnotationTest$ConfigTypes\\ntest.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='myClassArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myClassArray']/@type");
    xt.assertTrimmedAttribute("test.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='mySingleClassArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleClassArray']/@type");
    xt.assertAttribute("A", "scr:component/property[@name='myEnum']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myEnum']/@type");
    xt.assertTrimmedAttribute("A\\nB", "scr:component/property[@name='myEnumArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myEnumArray']/@type");
    xt.assertTrimmedAttribute("B", "scr:component/property[@name='mySingleEnumArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleEnumArray']/@type");
    xt.assertAttribute("1.0", "scr:component/property[@name='myFloat']/@value");
    xt.assertAttribute("Float", "scr:component/property[@name='myFloat']/@type");
    xt.assertAttribute("97", "scr:component/property[@name='myChar']/@value");
    xt.assertAttribute("Character", "scr:component/property[@name='myChar']/@type");
    xt.assertAttribute("2", "scr:component/property[@name='myByte']/@value");
    xt.assertAttribute("Byte", "scr:component/property[@name='myByte']/@type");
    xt.assertAttribute("298", "scr:component/property[@name='myShort']/@value");
    xt.assertAttribute("Short", "scr:component/property[@name='myShort']/@type");
    xt.assertAttribute("9876543210", "scr:component/property[@name='myLong']/@value");
    xt.assertAttribute("Long", "scr:component/property[@name='myLong']/@type");
    xt.assertAttribute("2.1", "scr:component/property[@name='myDouble']/@value");
    xt.assertAttribute("Double", "scr:component/property[@name='myDouble']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 17 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 18 with XmlTester

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

the class SpecMetatypeTest method testSimpleExtensions.

public void testSimpleExtensions() throws Exception {
    MetatypeVersion version = MetatypeVersion.VERSION_1_2;
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, SimpleConfig.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$SimpleConfig.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals("warnings: " + b.getWarnings(), 0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "metatype", version.getNamespace(), "foo", "org.foo.extensions.v1");
    xt.assertNamespace(version.getNamespace());
    xt.assertExactAttribute("test.metatype.SpecMetatypeTest$SimpleConfig", "metatype:MetaData/OCD/@id");
    xt.assertCount(4, "metatype:MetaData/OCD/@*");
    xt.assertExactAttribute("default", "metatype:MetaData/OCD/@foo:simple");
    xt.assertCount(5, "metatype:MetaData/OCD/AD[@id='property']/@*");
    xt.assertExactAttribute("value", "metatype:MetaData/OCD/AD[@id='property']/@foo:simple");
}
Also used : MetatypeVersion(aQute.bnd.metatype.MetatypeVersion) XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 19 with XmlTester

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

the class SpecMetatypeTest method testSimple.

public void testSimple() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, TestSimple.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$TestSimple.xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester12(r);
    testSimple(b, xt);
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 20 with XmlTester

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

the class SpecMetatypeTest method testSimple13.

public void testSimple13() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, TestSimple.class.getName());
    b.setProperty(Constants.METATYPE_ANNOTATIONS_OPTIONS, "version;minimum=1.3.0");
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$TestSimple.xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester13(r);
    testSimple(b, xt);
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) 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