Search in sources :

Example 51 with Resource

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

the class DSAnnotationTest method testVolatileFieldDynamic.

public void testVolatileFieldDynamic() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*VolatileField");
    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$VolatileField.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$VolatileField", "scr:component/implementation/@class");
    xt.assertAttribute("log1", "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("log2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertNoAttribute("scr:component/reference[2]/@policy");
}
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 52 with Resource

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

the class DSAnnotationTest method testReferenceType.

public void testReferenceType() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*RefType");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 0, 0);
    Attributes a = getAttr(jar);
    checkRequires(a, null, Marker.class.getName(), GenericMarker.class.getName(), Object.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$RefType.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");
    Collection<String> indices = new TreeSet<String>();
    for (int i = 1; i < 16; i++) indices.add(Integer.toString(i));
    this.indices.addAll(indices);
    checkMarkerReference(xt, 1, Marker.class);
    checkMarkerReference(xt, 2, Marker.class);
    checkMarkerReference(xt, 3, Marker.class);
    checkMarkerReference(xt, 4, Marker.class);
    checkMarkerReference(xt, 5, GenericMarker.class);
    checkMarkerReference(xt, 6, GenericMarker.class);
    checkMarkerReference(xt, 7, GenericMarker.class);
    checkMarkerReference(xt, 8, GenericMarker.class);
    checkMarkerReference(xt, 9, GenericMarker.class);
    checkMarkerReference(xt, 10, GenericMarker.class);
    checkMarkerReference(xt, 11, GenericMarker.class);
    checkMarkerReference(xt, 12, GenericMarker.class);
    checkMarkerReference(xt, 13, GenericMarker.class);
    checkMarkerReference(xt, 14, Object.class);
    checkMarkerReference(xt, 15, Marker.class);
}
Also used : Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) XmlTester(aQute.bnd.test.XmlTester) TreeSet(java.util.TreeSet) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 53 with Resource

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

the class DSAnnotationTest method testComponentReference.

public void testComponentReference() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*ComponentReference*");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 1, 0);
    {
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ComponentReferenceGood.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        XmlTester xt = new XmlTester(r.openInputStream());
        xt.assertAttribute(LogService.class.getName(), "component/reference[1]/@interface");
    }
    {
        Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ComponentReferenceBad.xml");
        System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
        assertNotNull(r);
        r.write(System.err);
        XmlTester xt = new XmlTester(r.openInputStream());
        xt.assertCount(0, "component/reference");
    }
}
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 54 with Resource

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

the class DSAnnotationTest method testPrefixCollisionExtraAttributesDefaultPrefix.

public void testPrefixCollisionExtraAttributesDefaultPrefix() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$DefaultPrefixCollisionExtraAttributes*");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    String name = DefaultPrefixCollisionExtraAttributes.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", "ns", "org.foo.extensions.v4", "ns1", "org.foo.extensions.v5");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertCount(10, "scr:component/@*");
    xt.assertAttribute("bar", "scr:component/@ns:stringAttr4");
    xt.assertAttribute("A", "scr:component/@ns:fooAttr4");
    xt.assertAttribute("true", "scr:component/@ns:booleanAttr4");
    xt.assertAttribute("bar3", "scr:component/@ns1:stringAttr5");
    xt.assertAttribute("B", "scr:component/@ns1:fooAttr5");
    xt.assertAttribute("true", "scr:component/@ns1:booleanAttr5");
}
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 55 with Resource

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

the class DSAnnotationTest method testExtraAttributes10.

/**
	 * test that an extension attribute will ensure at least a 1.1 namespace, so
	 * the extension namespace is meaningful
	 * 
	 * @throws Exception
	 */
public void testExtraAttributes10() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$ExtraAttributes*");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    String name = ExtraAttributes10.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.1.0", "foo", "org.foo.extensions.v1");
    // This wll check that the spec namespace is 1.1
    xt.assertAttribute(name, "scr:component/implementation/@class");
}
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)

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