You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Lukas Eder <ma...@adobe.com> on 2013/05/23 14:58:29 UTC

Registering Node Types in a Bundle used by unit tests of that same bundle

Hello,

I'm registering a mixin node type as documented here by this useful post
by Bertrand [1]. This post indicates that the Apache Felix configuration
should be enhanced with something along these lines:

<Sling-Nodetypes>
    SLING-INF/nodetypes/mytype.cnd
                        </Sling-Nodetypes>
                        <Sling-Namespaces>
    mytype=http://www.example.com/mytype
                        </Sling-Namespaces>


This works well, when deployed to Sling.

However, I would like to use that same node type in unit tests that are
run by Maven from within that same bundle. This doesn't seem to work in
the same way. The workaround is simple, of course. Just add the node type
manually through the JackRabbit API from the unit test.

But is there a way to leverage the same mechanism for both bundle
deployment and unit testing?

Cheers
Lukas

[1]: http://stackoverflow.com/a/14375040/521799


Re: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by Lukas Eder <ma...@adobe.com>.

On 5/23/13 4:45 PM, "Bertrand Delacretaz" <bd...@apache.org> wrote:

>On Thu, May 23, 2013 at 4:34 PM, Lukas Eder <ma...@adobe.com> wrote:
>> ...maybe,
>> such a Maven plugin and pre-configured test repository could be
>>leveraged
>> for other purposes, most importantly for mocking Sling as a whole?...
>
>The problem with a Maven plugin is you cannot use it when testing from
>some IDEs.

True, I missed that.

>What we currently have is the RepositoryProvider utility [1] for tests
>which need a JCR repository, it's very easy to use an non-intrusive.
>Enhancing it to detect CND files in (overridable) well-known locations
>should be easy.
>
>There's also been discussions on our dev list about making it easier
>to run OSGi-based tests, when you need Sling services and not just a
>repository. We're using Pax Exam in the installer/it module for
>example, it's not very complicated to setup but might be made even
>easier.

OK, thanks for the insight, Bertrand. I guess things really aren't that
simple. I can live with the manual creating of a repository in my case,
though.


Cheers
Lukas


Re: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Thu, May 23, 2013 at 4:34 PM, Lukas Eder <ma...@adobe.com> wrote:
> ...maybe,
> such a Maven plugin and pre-configured test repository could be leveraged
> for other purposes, most importantly for mocking Sling as a whole?...

The problem with a Maven plugin is you cannot use it when testing from
some IDEs.

What we currently have is the RepositoryProvider utility [1] for tests
which need a JCR repository, it's very easy to use an non-intrusive.
Enhancing it to detect CND files in (overridable) well-known locations
should be easy.

There's also been discussions on our dev list about making it easier
to run OSGi-based tests, when you need Sling services and not just a
repository. We're using Pax Exam in the installer/it module for
example, it's not very complicated to setup but might be made even
easier.

-Bertrand

[1] https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryProvider.java

Re: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by Lukas Eder <ma...@adobe.com>.

On 5/23/13 3:40 PM, "Bertrand Delacretaz" <bd...@apache.org> wrote:

>Hi Lukas,
>
>On Thu, May 23, 2013 at 3:33 PM, Lukas Eder <ma...@adobe.com> wrote:
>> ...Probably, I'm not the first one to have stumbled upon this
>>situation. Did
>> others just explicitly register the node type, as you suggested?...
>
>Yes - if you have good ideas for how to improve this they are welcome,
>but note that the bundle under test will not be built yet when the
>unit tests run.

Yes, I'm aware of this chicken-and-eggs problem. Node types cannot be
tested that way, because the bundle has not yet been built. The bundle
shouldn't be built, because the node types are not yet tested (except if
added manually to a test repo).

Here are a couple of thoughts:

1. /SLING-INF seems to be a standard path on the classpath of the bundle.
So CND files might be auto-discoverable
2. Users leveraging these things are OK with having Sling as a dependency.
So they wouldn't mind adding a Sling Maven Plugin
3. Such a Sling Maven Plugin could maybe "expose" an empty test repository
that would already contain the node type

This seems like a lot of work if its' just about node types. But maybe,
such a Maven plugin and pre-configured test repository could be leveraged
for other purposes, most importantly for mocking Sling as a whole?

Cheers
Lukas


Re: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Lukas,

On Thu, May 23, 2013 at 3:33 PM, Lukas Eder <ma...@adobe.com> wrote:
> ...Probably, I'm not the first one to have stumbled upon this situation. Did
> others just explicitly register the node type, as you suggested?...

Yes - if you have good ideas for how to improve this they are welcome,
but note that the bundle under test will not be built yet when the
unit tests run.

-Bertrand

Re: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by Lukas Eder <ma...@adobe.com>.
Yes, as I said...

> The workaround is simple, of course. Just add the node type manually
>through the JackRabbit API from the unit test.

But I'd like to know if there's a way to reuse the same mechanism for node
type publishing for both

- Bundle deployment
- Unit testing

Probably, I'm not the first one to have stumbled upon this situation. Did
others just explicitly register the node type, as you suggested?

Cheers
Lukas

On 5/23/13 3:17 PM, "Amit.. Gupta." <am...@adobe.com> wrote:

>RepositoryUtil.registerNodeType(adminSession,
>getClass().getResourceAsStream("/CQ-INF/nodetypes/dam.cnd"));
>
>-Amit
>
>-----Original Message-----
>From: Lukas Eder [mailto:mar09086@adobe.com]
>Sent: 23 May 2013 18:28
>To: users@sling.apache.org
>Subject: Registering Node Types in a Bundle used by unit tests of that
>same bundle
>
>Hello,
>
>I'm registering a mixin node type as documented here by this useful post
>by Bertrand [1]. This post indicates that the Apache Felix configuration
>should be enhanced with something along these lines:
>
><Sling-Nodetypes>
>    SLING-INF/nodetypes/mytype.cnd
>                        </Sling-Nodetypes>
>                        <Sling-Namespaces>
>    mytype=http://www.example.com/mytype
>                        </Sling-Namespaces>
>
>
>This works well, when deployed to Sling.
>
>However, I would like to use that same node type in unit tests that are
>run by Maven from within that same bundle. This doesn't seem to work in
>the same way. The workaround is simple, of course. Just add the node type
>manually through the JackRabbit API from the unit test.
>
>But is there a way to leverage the same mechanism for both bundle
>deployment and unit testing?
>
>Cheers
>Lukas
>
>[1]: http://stackoverflow.com/a/14375040/521799
>


RE: Registering Node Types in a Bundle used by unit tests of that same bundle

Posted by "Amit.. Gupta." <am...@adobe.com>.
RepositoryUtil.registerNodeType(adminSession, getClass().getResourceAsStream("/CQ-INF/nodetypes/dam.cnd"));

-Amit

-----Original Message-----
From: Lukas Eder [mailto:mar09086@adobe.com] 
Sent: 23 May 2013 18:28
To: users@sling.apache.org
Subject: Registering Node Types in a Bundle used by unit tests of that same bundle

Hello,

I'm registering a mixin node type as documented here by this useful post by Bertrand [1]. This post indicates that the Apache Felix configuration should be enhanced with something along these lines:

<Sling-Nodetypes>
    SLING-INF/nodetypes/mytype.cnd
                        </Sling-Nodetypes>
                        <Sling-Namespaces>
    mytype=http://www.example.com/mytype
                        </Sling-Namespaces>


This works well, when deployed to Sling.

However, I would like to use that same node type in unit tests that are run by Maven from within that same bundle. This doesn't seem to work in the same way. The workaround is simple, of course. Just add the node type manually through the JackRabbit API from the unit test.

But is there a way to leverage the same mechanism for both bundle deployment and unit testing?

Cheers
Lukas

[1]: http://stackoverflow.com/a/14375040/521799