Search in sources :

Example 41 with XmlTester

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

the class DSAnnotationTest method testExtraAttributes.

public void testExtraAttributes() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$ExtraAttributes*");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    String name = ExtraAttributes.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");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertCount(7, "scr:component/@*");
    xt.assertAttribute("bar", "scr:component/@foo:stringAttr");
    xt.assertAttribute("A", "scr:component/@foo:fooAttr");
    xt.assertAttribute("true", "scr:component/@foo:booleanAttr");
    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 42 with XmlTester

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

the class SpecMetatypeTest method testCollections.

public void testCollections() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, CollectionsTest.class.getName());
    b.build();
    System.out.println(b.getErrors());
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources());
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$CollectionsTest.xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester12(r);
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='collection']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='list']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='set']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='arrayList']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='linkedList']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='linkedHashSet']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='myList']/@cardinality");
    xt.assertExactAttribute("-2147483648", "metatype:MetaData/OCD/AD[@id='stringList']/@cardinality");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 43 with XmlTester

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

the class SpecMetatypeTest method testNaming.

public void testNaming() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, Naming.class.getName());
    b.build();
    System.out.println(b.getErrors());
    assertEquals(0, b.getErrors().size());
    System.out.println(b.getWarnings());
    assertEquals(0, b.getWarnings().size());
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$Naming.xml");
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester12(r);
    assertAD(xt, "secret", "Secret");
    assertAD(xt, ".secret", "Secret");
    assertAD(xt, "_secret", "Secret");
    assertAD(xt, "new", "New");
    assertAD(xt, "$new", "New");
    assertAD(xt, "a.b.c", "A b c");
    assertAD(xt, "a_b_c", "A b c");
    assertAD(xt, ".a_b", "A b");
    assertAD(xt, "$$$$a_b", "A b");
    assertAD(xt, "$$$$a.b", "A b");
    assertAD(xt, "a", "A ");
    assertAD(xt, "a$", "A ");
    assertAD(xt, "b$", "B ");
    assertAD(xt, "a$$", "A ");
    assertAD(xt, "a$.$", "A ");
    assertAD(xt, "a$_$", "A ");
    assertAD(xt, "a..", "A ");
    assertAD(xt, "xsecret", "secret");
    assertAD(xt, "x.secret", ".secret");
    assertAD(xt, "x_secret", "_secret");
    assertAD(xt, "xnew", "new");
    assertAD(xt, "x$new", "$new");
    assertAD(xt, "xa.b.c", "a.b.c");
    assertAD(xt, "xa_b_c", "a_b_c");
    assertAD(xt, "x.a_b", ".a_b");
    assertAD(xt, "x$$$$a_b", "$$$$a_b");
    assertAD(xt, "x$$$$a.b", "$$$$a.b");
    assertAD(xt, "xa", "a");
    assertAD(xt, "xa$", "a$");
    assertAD(xt, "xb$", "a$");
    assertAD(xt, "xa$$", "a$$");
    assertAD(xt, "xa$.$", "a$.$");
    assertAD(xt, "xa$_$", "a$_$");
    assertAD(xt, "xa..", "a..");
    assertAD(xt, "noid", "Noid");
    assertAD(xt, "nullid", "§NULL§");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 44 with XmlTester

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

the class SpecMetatypeTest method assertOCD.

private void assertOCD(Builder b, String cname, String id, String name, String description, String designate, boolean factory, String localization) throws Exception {
    Resource r = b.getJar().getResource("OSGI-INF/metatype/" + id + ".xml");
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester13(r);
    xt.assertExactAttribute(id, "metatype:MetaData/OCD/@id");
    xt.assertExactAttribute(name, "metatype:MetaData/OCD/@name");
    String expected = localization == null ? "OSGI-INF/I10n/" + cname : localization;
    xt.assertExactAttribute(localization == null ? "OSGI-INF/l10n/" + cname : localization, "metatype:MetaData/@localization");
    xt.assertExactAttribute(description == null ? "" : description, "metatype:MetaData/OCD/@description");
    if (designate != null) {
        if (factory)
            xt.assertExactAttribute(designate, "metatype:MetaData/Designate/@factoryPid");
        else
            xt.assertExactAttribute(designate, "metatype:MetaData/Designate/@pid");
    }
    xt.assertExactAttribute(id, "metatype:MetaData/Designate/Object/@ocdref");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 45 with XmlTester

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

the class SpecMetatypeTest method testDesignate.

public void testDesignate() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, "test.metatype.SpecMetatypeTest$Designate*");
    b.setProperty(Constants.DSANNOTATIONS, "test.metatype.SpecMetatypeTest$Designate*");
    b.build();
    {
        Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$DesignateOCD.xml");
        assertEquals(b.getErrors().toString(), 0, b.getErrors().size());
        assertEquals(b.getWarnings().toString(), 0, b.getWarnings().size());
        System.err.println(b.getJar().getResources().keySet());
        assertNotNull(r);
        IO.copy(r.openInputStream(), System.err);
        XmlTester xt = xmlTester13(r);
        xt.assertExactAttribute("Test metatype spec metatype test designate OCD", "metatype:MetaData/OCD/@name");
        xt.assertExactAttribute("test.metatype.SpecMetatypeTest$DesignateOCD", "metatype:MetaData/OCD/@id");
        xt.assertExactAttribute("simplePid", "metatype:MetaData/Designate[1]/@factoryPid");
        xt.assertExactAttribute("test.metatype.SpecMetatypeTest$DesignateOCD", "metatype:MetaData/Designate[1]/Object/@ocdref");
        xt.assertExactAttribute("simplePidName", "metatype:MetaData/Designate[2]/@factoryPid");
        xt.assertExactAttribute("test.metatype.SpecMetatypeTest$DesignateOCD", "metatype:MetaData/Designate[2]/Object/@ocdref");
        xt.assertExactAttribute(DesignateComponent3.class.getName(), "metatype:MetaData/Designate[3]/@factoryPid");
        xt.assertExactAttribute("test.metatype.SpecMetatypeTest$DesignateOCD", "metatype:MetaData/Designate[3]/Object/@ocdref");
        xt.assertExactAttribute(DesignateComponent4.class.getName(), "metatype:MetaData/Designate[4]/@factoryPid");
        xt.assertExactAttribute("test.metatype.SpecMetatypeTest$DesignateOCD", "metatype:MetaData/Designate[4]/Object/@ocdref");
    }
}
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