Search in sources :

Example 1 with MetatypeVersion

use of aQute.bnd.metatype.MetatypeVersion 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 2 with MetatypeVersion

use of aQute.bnd.metatype.MetatypeVersion 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 3 with MetatypeVersion

use of aQute.bnd.metatype.MetatypeVersion in project bnd by bndtools.

the class SpecMetatypeTest method testMappingExtensions.

public void testMappingExtensions() 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, MappingConfig.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$MappingConfig.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$MappingConfig", "metatype:MetaData/OCD/@id");
    xt.assertCount(5, "metatype:MetaData/OCD/@*");
    xt.assertExactAttribute("A", "metatype:MetaData/OCD/@foo:first");
    xt.assertExactAttribute("B", "metatype:MetaData/OCD/@foo:second");
    xt.assertCount(6, "metatype:MetaData/OCD/AD[@id='property']/@*");
    xt.assertExactAttribute("one", "metatype:MetaData/OCD/AD[@id='property']/@foo:first");
    xt.assertExactAttribute("two", "metatype:MetaData/OCD/AD[@id='property']/@foo:second");
}
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)

Aggregations

MetatypeVersion (aQute.bnd.metatype.MetatypeVersion)3 Builder (aQute.bnd.osgi.Builder)3 Resource (aQute.bnd.osgi.Resource)3 XmlTester (aQute.bnd.test.XmlTester)3 File (java.io.File)3