Hello Bertrand,

Thank you very much for this email. It helped me a lot. My problem is that
didn't work with OSGi good enough and there is a big gap for me. But I also
agree that I tackle this I'll be well equipped to write a large range of
Sling tests.
I have created a test bundle using ./installer/it/pom.xml with required
Sling-Initial-Content header in manifest file. Bundle installs fine, I can
get it's id, and get it back by this id. However I don't see any imported
content in a repository.

I did everything same as it described on Content Loading webpage[1], but it
still doesn't work.
My bundle[2] contains META-INF/MANIFEST.MF file with Sling-Initial-Content
header and SLING-INF/content/home.xml file as well. However in JCR root
node I see only jcr:system and rep:policy nodes. You can watch my last
changes in my GitHub repo[3] or I have also created a Gist on GitHub[4].

[1]
https://sling.apache.org/documentation/bundles/content-loading-jcr-contentloader.html
[2]
https://github.com/PetrShypila/sling-builder/blob/trunk/bundles/jcr/contentloader/src/test/resources/org.apache.sling.installer.it-3.6.7-SNAPSHOT-testbundle-1.0.jar
[3]
https://github.com/PetrShypila/sling-builder/tree/trunk/bundles/jcr/contentloader
[4] https://gist.github.com/PetrShypila/3a81b26be7d2bd5f995e

Could me someone probably say, what I'm doing wrong?

Thank you so much,
Petr

2015-06-23 18:30 GMT+03:00 Bertrand Delacretaz <bdelacre...@apache.org>:

> 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