Hi Petr,

On Mon, Jun 22, 2015 at 7:41 PM, Petr Shypila <ikrump...@gmail.com> wrote:
> ...So the only service which injects fine is
> o.a.s.jcr.contentloader.ContentReader...

That's correct.

If you look at the details of the org.apache.sling.jcr.contentloader
bundle at http://localhost:8080/system/console/bundles on a standard
Sling instance (for example java -jar
target/org.apache.sling.launchpad-8-SNAPSHOT.jar ad launchpad/builder)
you see that this bundle only supplies ContentReader services along
with a ContentReaderWhiteboard service that's an internal class, not
exported AFAICS. If you look the the details of the ContentReader
services you can see that they all have an "extensions" property which
allows the bundle's internal code to select them. This would be
visible from the source code of course but it's easier to find out in
that way initially.

You could call those ContentReader services directly for testing them
but IMO it's more useful to just install new bundles that supply
initial content and verify that the content is correctly installed as
per 
https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html
. And maybe also update and remove those bundles to verify that the
initial content is correctly handled. You'll probably need the
RetryRule of the bundles/commons/testing module in your tests as the
content won't appear immediately after a test bundle is installed.

To create such test bundles you might be able to use
https://ops4j1.jira.com/wiki/display/ops4j/Tinybundles but I'm not
sure how to include json or other files in such bundles created on the
fly - it looks like you just pull stuff from your current classpath so
that might work. Otherwise you can use the technique of
./installer/it/pom.xml to generate a few test bundles at build time
(look for "Create several simple test bundles" in there).

This contentloader bundle is a bit unusual as it uses the so-called
"extender pattern" to listen for new bundles that appear with a bundle
header that's interesting in terms of content loading. The bundle's
main role is not to provided services, it's to process such bundles,
so IMO it's best to test that use case directly.

Those tests are a bit tricky to setup though, so feel free to ask if
you have more questions! Once you tackle this you'll be well equipped
to write a large range of Sling tests.

-Bertrand

Reply via email to