testingosgibndtestcontainers-junit5

Howto use testcontainers with bnd


I'm new to bndtools. I'd like to use testcontainers (https://www.testcontainers.org/) to test a osgi bundle which is supposed to connect to a MQTT broker. So I can test connect, connectionlost etc. strategies. I dont't understand how maven and bnd repositories work together, so until I understand, I don't use maven. Then I've tried to "import" testcontainers by adding it to build.bnd :

-plugin.6.junit: \
    aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
        releaseUrl=https://repo.maven.apache.org/maven2/; \
        readOnly=true; \
        name="Maven Central JUNIT";\
        revision="org.osgi:org.osgi.test.junit5:0.10.0,\
        org.osgi:org.osgi.test.junit4:0.10.0", \
        org.testcontainers:testcontainers:1.15.2

But bnd says "Cannot load the plugin org.testcontainers:testcontainers:1.15.2." I'm lost...


Solution

  • The syntax you use is wrong ... The 'revision' parameter is taking a quoted string. That string ends with junit4:0.10.0", \. You add the test containers parameter after the quoted string is closed. So the following should work:

    -plugin.6.junit: \
        aQute.bnd.repository.maven.pom.provider.BndPomRepository; \
            releaseUrl=https://repo.maven.apache.org/maven2/; \
            readOnly=true; \
            name="Maven Central JUNIT";\
            revision="org.osgi:org.osgi.test.junit5:0.10.0,\
                org.osgi:org.osgi.test.junit4:0.10.0, \
                org.testcontainers:testcontainers:1.15.2"
    

    The Maven Bnd Repository is easier to use since it allows you to specify the GAVs in text file, one per line.