Search in sources :

Example 21 with XmlTester

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

the class DSAnnotationTest method testBridgeMethod.

/*
	 * See https://github.com/bndtools/bnd/issues/1546. If a component class has
	 * an annotated method for which the compiler generates a bridge method,
	 * javac will copy the annotations onto the bridge method. Bnd must ignore
	 * bridge methods.
	 */
public void testBridgeMethod() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*ActivatableComponent");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b, 0, 0);
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ActivatableComponent.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    xt.assertAttribute("activator", "scr:component/@activate");
}
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 22 with XmlTester

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

the class DSAnnotationTest method testFieldCardinality.

public void testFieldCardinality() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*FieldCardinality");
    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$FieldCardinality.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$FieldCardinality", "scr:component/implementation/@class");
    xt.assertAttribute("log1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[1]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[1]/@policy");
    xt.assertNoAttribute("scr:component/reference[1]/@field-option");
    xt.assertAttribute("log2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[2]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[2]/@policy");
    xt.assertNoAttribute("scr:component/reference[2]/@field-option");
    xt.assertAttribute("log3", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertNoAttribute("scr:component/reference[3]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[3]/@policy");
    xt.assertNoAttribute("scr:component/reference[3]/@field-option");
    xt.assertAttribute("log4", "scr:component/reference[4]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[4]/@interface");
    xt.assertNoAttribute("scr:component/reference[4]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[4]/@policy");
    xt.assertNoAttribute("scr:component/reference[4]/@field-option");
    xt.assertAttribute("log5", "scr:component/reference[5]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[5]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[5]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[5]/@policy");
    xt.assertAttribute("update", "scr:component/reference[5]/@field-option");
}
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 23 with XmlTester

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

the class DSAnnotationTest method testPrototypes.

public void testPrototypes() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Prototypes");
    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);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/prototypes.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
    xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
}
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 24 with XmlTester

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

the class DSAnnotationTest method checkDS13AnnoConfigNames.

private void checkDS13AnnoConfigNames(Jar jar, String name) throws Exception, XPathExpressionException {
    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");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertAttribute("", "scr:component/@configuration-policy");
    xt.assertAttribute("", "scr:component/@immediate");
    xt.assertAttribute("", "scr:component/@enabled");
    xt.assertAttribute("", "scr:component/@factory");
    xt.assertAttribute("", "scr:component/service/@scope");
    xt.assertAttribute("", "scr:component/@configuration-pid");
    xt.assertAttribute("activate", "scr:component/@activate");
    xt.assertAttribute("deactivate", "scr:component/@deactivate");
    xt.assertAttribute("modified", "scr:component/@modified");
    xt.assertAttribute("java.io.Serializable", "scr:component/service/provide[1]/@interface");
    xt.assertAttribute("java.lang.Runnable", "scr:component/service/provide[2]/@interface");
    xt.assertAttribute("6", "count(scr:component/property)");
    xt.assertAttribute("foo", "scr:component/property[@name='myString1']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString1']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='myString2']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString2']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my$String3']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my$String3']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my.String4']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my.String4']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my_String5']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my_String5']/@type");
    xt.assertAttribute("foo", "scr:component/property[@name='my$_String6']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='my$_String6']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

Example 25 with XmlTester

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

the class DSAnnotationTest method checkDS13Anno.

private void checkDS13Anno(Jar jar, String name, String pids) throws Exception, XPathExpressionException {
    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");
    // Test the defaults
    xt.assertAttribute(name, "scr:component/implementation/@class");
    // Default must be the implementation class
    xt.assertAttribute(name, "scr:component/@name");
    xt.assertAttribute("", "scr:component/@configuration-policy");
    xt.assertAttribute("", "scr:component/@immediate");
    xt.assertAttribute("", "scr:component/@enabled");
    xt.assertAttribute("", "scr:component/@factory");
    xt.assertAttribute("", "scr:component/service/@scope");
    xt.assertAttribute(pids, "scr:component/@configuration-pid");
    xt.assertAttribute("activate", "scr:component/@activate");
    xt.assertAttribute("deactivate", "scr:component/@deactivate");
    xt.assertAttribute("modified", "scr:component/@modified");
    xt.assertAttribute("java.io.Serializable", "scr:component/service/provide[1]/@interface");
    xt.assertAttribute("java.lang.Runnable", "scr:component/service/provide[2]/@interface");
    xt.assertAttribute("0", "count(scr:component/properties)");
    xt.assertAttribute("18", "count(scr:component/property)");
    xt.assertAttribute("foo", "scr:component/property[@name='myString']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myString']/@type");
    xt.assertTrimmedAttribute("foo\\nbar", "scr:component/property[@name='myStringArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myStringArray']/@type");
    xt.assertTrimmedAttribute("baz", "scr:component/property[@name='mySingleStringArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleStringArray']/@type");
    xt.assertAttribute("1", "scr:component/property[@name='myInt']/@value");
    xt.assertAttribute("Integer", "scr:component/property[@name='myInt']/@type");
    xt.assertTrimmedAttribute("2\\n3", "scr:component/property[@name='myIntArray']");
    xt.assertAttribute("Integer", "scr:component/property[@name='myIntArray']/@type");
    xt.assertTrimmedAttribute("4", "scr:component/property[@name='mySingleIntArray']");
    xt.assertAttribute("Integer", "scr:component/property[@name='mySingleIntArray']/@type");
    xt.assertAttribute("test.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='myClass']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myClass']/@type");
    xt.assertTrimmedAttribute("test.component.DSAnnotationTest$ConfigTypes\\ntest.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='myClassArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myClassArray']/@type");
    xt.assertTrimmedAttribute("test.component.DSAnnotationTest$ConfigTypes", "scr:component/property[@name='mySingleClassArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleClassArray']/@type");
    xt.assertAttribute("A", "scr:component/property[@name='myEnum']/@value");
    xt.assertAttribute("String", "scr:component/property[@name='myEnum']/@type");
    xt.assertTrimmedAttribute("A\\nB", "scr:component/property[@name='myEnumArray']");
    xt.assertAttribute("String", "scr:component/property[@name='myEnumArray']/@type");
    xt.assertTrimmedAttribute("B", "scr:component/property[@name='mySingleEnumArray']");
    xt.assertAttribute("String", "scr:component/property[@name='mySingleEnumArray']/@type");
    xt.assertAttribute("1.0", "scr:component/property[@name='myFloat']/@value");
    xt.assertAttribute("Float", "scr:component/property[@name='myFloat']/@type");
    xt.assertAttribute("97", "scr:component/property[@name='myChar']/@value");
    xt.assertAttribute("Character", "scr:component/property[@name='myChar']/@type");
    xt.assertAttribute("2", "scr:component/property[@name='myByte']/@value");
    xt.assertAttribute("Byte", "scr:component/property[@name='myByte']/@type");
    xt.assertAttribute("298", "scr:component/property[@name='myShort']/@value");
    xt.assertAttribute("Short", "scr:component/property[@name='myShort']/@type");
    xt.assertAttribute("9876543210", "scr:component/property[@name='myLong']/@value");
    xt.assertAttribute("Long", "scr:component/property[@name='myLong']/@type");
    xt.assertAttribute("2.1", "scr:component/property[@name='myDouble']/@value");
    xt.assertAttribute("Double", "scr:component/property[@name='myDouble']/@type");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Resource(aQute.bnd.osgi.Resource)

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