Search in sources :

Example 6 with XmlTester

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

the class SpecMetatypeTest method testExtensions.

public void testExtensions() 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, TestExtensions.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$TestExtensions.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$TestExtensions", "metatype:MetaData/OCD/@id");
    xt.assertExactAttribute("simple", "metatype:MetaData/OCD/AD[@id='simple']/@id");
    xt.assertExactAttribute("Simple", "metatype:MetaData/OCD/AD[@id='simple']/@name");
    xt.assertExactAttribute("String", "metatype:MetaData/OCD/AD[@id='simple']/@type");
    xt.assertExactAttribute("false", "metatype:MetaData/OCD/AD[@id='enabled']/@required");
    xt.assertExactAttribute("true", "metatype:MetaData/OCD/AD[@id='enabled']/@default");
    xt.assertExactAttribute(Integer.MAX_VALUE + "", "metatype:MetaData/OCD/AD[@id='notSoSimple']/@cardinality");
    xt.assertCount(8, "metatype:MetaData/OCD/@*");
    xt.assertExactAttribute("ocd", "metatype:MetaData/OCD/@foo:stringAttr");
    xt.assertExactAttribute("A", "metatype:MetaData/OCD/@foo:fooAttr");
    xt.assertExactAttribute("foo bar", "metatype:MetaData/OCD/@foo:stringArrayAttr");
    xt.assertExactAttribute("1 2 3", "metatype:MetaData/OCD/@foo:intArrayAttr");
    xt.assertExactAttribute("true", "metatype:MetaData/OCD/@foo:booleanAttr");
    xt.assertCount(3, "metatype:MetaData/OCD/AD[@id='simple']/@*");
    xt.assertCount(8, "metatype:MetaData/OCD/AD[@id='notSoSimple']/@*");
    xt.assertExactAttribute("ad", "metatype:MetaData/OCD/AD[@id='notSoSimple']/@foo:stringAttr2");
    xt.assertExactAttribute("B", "metatype:MetaData/OCD/AD[@id='notSoSimple']/@foo:fooAttr2");
    xt.assertExactAttribute(String.class.getName(), "metatype:MetaData/OCD/AD[@id='notSoSimple']/@foo:classAttr2");
    xt.assertExactAttribute("true", "metatype:MetaData/OCD/AD[@id='notSoSimple']/@foo:booleanAttr2");
    xt.assertCount(4, "metatype:MetaData/OCD/AD[@id='stringCollection']/@*");
    xt.assertCount(9, "metatype:MetaData/OCD/AD[@id='enabled']/@*");
    xt.assertExactAttribute("ad2", "metatype:MetaData/OCD/AD[@id='enabled']/@foo:stringAttr2");
    xt.assertExactAttribute("A", "metatype:MetaData/OCD/AD[@id='enabled']/@foo:fooAttr2");
    xt.assertExactAttribute(Object.class.getName(), "metatype:MetaData/OCD/AD[@id='enabled']/@foo:classAttr2");
    xt.assertExactAttribute("true", "metatype:MetaData/OCD/AD[@id='enabled']/@foo:booleanAttr2");
}
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 7 with XmlTester

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

the class SpecMetatypeTest method testEscapes.

public void testEscapes() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, Escapes.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$Escapes.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester12(r);
    assertAD(xt, "escapes", "Escapes", null, null, "\\ \\,\\ \\\\,a\\,b,c\\,d,'apostrophe',\"quote\"&", 2147483647, "String", null, null, null);
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 8 with XmlTester

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

the class SpecMetatypeTest method testNaming14.

public void testNaming14() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, Naming14.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$Naming14.xml");
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester14(r);
    assertAD(xt, "test.a-b", "A b", "foo");
    assertAD(xt, "test.xa-b", "a-b", "foo");
    assertAD(xt, "test.naming14", "Value", "foo");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 9 with XmlTester

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

the class SpecMetatypeTest method testADWithInheritance.

public void testADWithInheritance() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, TestADWithInheritanceChild.class.getName().substring(0, TestADWithInheritanceChild.class.getName().length() - "Child".length()) + "*");
    // b.setProperty("-metatypeannotations-inherit", "true");
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$TestADWithInheritanceChild.xml");
    System.err.println(b.getErrors());
    assertEquals(0, b.getErrors().size());
    System.err.println(b.getWarnings());
    assertEquals(0, b.getWarnings().size());
    System.err.println(b.getJar().getResources().keySet());
    assertNotNull(r);
    IO.copy(r.openInputStream(), System.err);
    XmlTester xt = xmlTester12(r);
    assertAD(xt, "fromChild", "From child", null, null, null, 0, "String", null, null, null);
    assertAD(xt, "fromSuperOne", "From super one", null, null, null, 0, "String", null, null, null);
    assertAD(xt, "fromSuperTwo", "From super two", null, null, null, 0, "String", null, null, null);
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 10 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)

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