Search in sources :

Example 76 with Resource

use of aQute.bnd.osgi.Resource 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 77 with Resource

use of aQute.bnd.osgi.Resource 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 78 with Resource

use of aQute.bnd.osgi.Resource 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 79 with Resource

use of aQute.bnd.osgi.Resource in project bnd by bndtools.

the class SpecMetatypeTest method testBndAnnoCompatible.

// cf issue 1130
public void testBndAnnoCompatible() throws Exception {
    Builder b = new Builder();
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "test.metatype");
    b.setProperty(Constants.METATYPE_ANNOTATIONS, C.class.getName());
    b.build();
    Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.SpecMetatypeTest$C.xml");
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    assertNull(r);
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) File(java.io.File)

Example 80 with Resource

use of aQute.bnd.osgi.Resource 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)

Aggregations

Resource (aQute.bnd.osgi.Resource)147 Jar (aQute.bnd.osgi.Jar)87 Builder (aQute.bnd.osgi.Builder)83 File (java.io.File)76 XmlTester (aQute.bnd.test.XmlTester)48 JarResource (aQute.bnd.osgi.JarResource)20 Attributes (java.util.jar.Attributes)20 Map (java.util.Map)19 Manifest (java.util.jar.Manifest)19 FileResource (aQute.bnd.osgi.FileResource)17 LogService (org.osgi.service.log.LogService)15 HashMap (java.util.HashMap)14 Document (org.w3c.dom.Document)14 Properties (java.util.Properties)12 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 InputStream (java.io.InputStream)9 Attrs (aQute.bnd.header.Attrs)8 ArrayList (java.util.ArrayList)8 TreeMap (java.util.TreeMap)8