On Mon, Jan 30, 2012 at 1:35 PM, sam ” <skyn...@gmail.com> wrote:
> Hey Justin,
>
> What do you mean by the following?:
>
> most of the integration
>> tests I write run in Maven and interact with servlets/scripts running
>> inside Sling via HTTP.

Hi sam,
I meant just that - I have regular JUnit tests which interact with
Sling via HTTP and make assertions against the results. Just like the
Sling ITs.

I'll give a recent example. For a project, I had to write a
NodeNameGenerator service. There were ultimately two test classes for
this:

1) Unit tests using mocks. These were in the src/test/java structure
of my bundle.
2) Integration tests. These were in a separate Maven project, also in
the src/test/java structure.

The ITs made HTTP requests (POSTs in this case) to different paths and
with different payloads and then asserted that nodes did (or didn't)
get created with the appropriate names.

This could certainly be done with the in-container test framework. It
just seems more natural to me personally to test components in the
HTTP pipeline via HTTP. I probably should figure out a way to write
tests in curl and grep :)

Justin


>
>
>
> Do you have a separate test OSGi bundle  where you invoke `mvn test` at and
> it'll deploy the test bundle and run tests?
>
>
> Are there actual integration tests written with
> http://sling.apache.org/site/sling-testing-tools.html   (not just simple
> samples) ?
>
>
> I am not sure how to manage ResourceResolver for my Test class.
> class Test {
>    @TestReference private ResourceResolverFactory resolverFactory;
>    ResourceResolver resourceResolver;
> }
>
> Given above, do I call
> resolverFactory.getAdministrativeResourceResolver(null);  @Before  each
> @Test method?
>
> And, call resourceResolver.logout();  @After each @Test?
>
> Ideally, I would login/logout to repository once before and after running a
> bunch of @Test methods.
>
> I tried with @BeforeClass and @AfterClass. But, I don't know how to make
> @TestReference inject to static fields.
>
> Why is junit chosen as integration testing? At least testNG supports test
> dependencies so that I can login to/logout from repository once..
>
> Do you know which projects actually use sling integration tests?
>
> http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests
> This looks like the only integration test for sling. But, these don't use
> ResourceResolverFactory  (@TestReference).
>
>
>
>
>
>
>
> On Fri, Jan 27, 2012 at 9:54 PM, Justin Edelson 
> <jus...@justinedelson.com>wrote:
>
>> Sam-
>> Regardless of whether it is a JSP or Servlet, the correct way to
>> handle this is to create a node with a sling:resourceType property.
>> Your JSP or Servlet should be associated with that resource type. If
>> you need to secure the content, secure the content, but that's an
>> orthogonal concern to the scripts used to render the content. Mounting
>> a servlet at a particular path is sometimes necessary and appropriate,
>> but more often than not it is something you can and should avoid. And,
>> as you note, this puts the onus of security on your servlet, not the
>> repository.
>>
>> To your question about integration tests, most of the integration
>> tests I write run in Maven and interact with servlets/scripts running
>> inside Sling via HTTP.  I try not to write test-specific servlets to
>> the greatest extent possible. We obviously need to create test
>> services for testing the framework itself, but not for applications
>> running inside of the framework. I also try to focus on writing unit
>> tests with good mocks as those tend to be significantly faster than
>> integration tests. YMMV, of course.
>>
>> Justin
>>
>> On Fri, Jan 27, 2012 at 1:33 PM, sam ” <skyn...@gmail.com> wrote:
>> > Hey,
>> >
>> > I have a test script that will make a series of HTTP requests to Sling.
>> > I need to write servlets that will handle the requests.
>> > I can either use jsp (/apps/tests/test1/json.jsp, for example).
>> > Or, I can write a @Service that implements Servlet interface.
>> >
>> > Good thing about writing .jsp to the repository is that I can configure
>> ACL
>> > to block access to /apps/tests.
>> > If I write a @Service that implements Servlet interface (that handles
>> > requests to /bin/tests, for example), anonymous users can make requests.
>> > Maybe there is a way to configure ACL for resources that do not exist in
>> > the repository (such as /bin/tests) ??
>> >
>> > How do you write integration tests?
>> >
>> > Thanks.
>> > Sam.
>>

Reply via email to