On Sat, Aug 10, 2013 at 1:47 PM, Bertrand Delacretaz <[email protected] > wrote:
> Hi, > > On Sat, Aug 10, 2013 at 7:02 AM, Dishara Wijewardana > <[email protected]> wrote: > > ...The integration tests > > calls to HTTP REST endpoints. So there should be a place that I should be > > writing something like JAX-RS using sling APIs... > > You don't need JAX-RS, Sling provides RESTful HTTP APIs out of the box. > > > ...Apparently what I should be > > writing is something similar to PlanetsResourceProviderTest.... > > Yeah can be a good starting point - setup a Sling instance with your > resource provider active and create, retrieve, update and delete > resources via Sling's HTTP API. > > You can also probably test your ResourceProvider without a Sling > instance, either with unit tests or pax exam integration tests. If you > can demonstrate there that it works according to the ResourceProvider > semantics, integration tests can be minimal and just verify that your > provider hooks up in the right way when activated. > Hi Bertrand You are quite right. My provider works standalone and wants to make sure whether my provider picked up by the sling engine. Where should I specify my provider when calling the HTTP endpoint. Or if I call to a correct resource path, will it picked it up ? I tried writing something similar to PlanetsResourceProviderTest and did a HTTP GET call to the endpoint " http://localhost:8080/content/cassandra/movies/foo" and when I remotely debug the test, the http client of HTTPTestBase receives a 404 for that GET call.. NOTE: /content/cassandra/movies/foo is an existing resource node in cassandra and my provider capable of returning it in standalone mode. This is the BE error log.. unning org.apache.sling.launchpad.webapp.integrationtest.resourceprovider.CassandraResourceProviderTest Checking if the required Sling services are started (timeout 62 seconds)... (base URLs=http://localhost:8080 and http://localhost:8080; servlet context=) Sling services seem to be started, continuing with integration tests. Listening for transport dt_socket at address: 5006 Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.472 sec <<< FAILURE! testMovieResource(org.apache.sling.launchpad.webapp.integrationtest.resourceprovider.CassandraResourceProviderTest) Time elapsed: 0.437 sec <<< FAILURE! junit.framework.AssertionFailedError: Expected status 200 for http://localhost:8080/content/cassandra/movies/foo (content=<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html> <head> <title>404 No resource found</title> </head> <body> <h1>No resource found (404)</h1> <p>The requested URL /content/cassandra/movies/foo resulted in an error in org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet.</p> <h3>Request Progress:</h3> <pre> 0 (2013-08-11 05:25:39) TIMER_START{Request Processing} 0 (2013-08-11 05:25:39) COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message> 0 (2013-08-11 05:25:39) LOG Method=GET, PathInfo=/content/cassandra/movies/foo 0 (2013-08-11 05:25:39) TIMER_START{ResourceResolution} 2 (2013-08-11 05:25:39) TIMER_END{2,ResourceResolution} URI=/content/cassandra/movies/foo resolves to Resource=NonExistingResource, path=/content/cassandra/movies/foo 3 (2013-08-11 05:25:39) LOG Resource Path Info: SlingRequestPathInfo: path='/content/cassandra/movies/foo', selectorString='null', extension='null', suffix='null' 3 (2013-08-11 05:25:39) TIMER_START{ServletResolution} 3 (2013-08-11 05:25:39) TIMER_START{resolveServlet(NonExistingResource, path=/content/cassandra/movies/foo)} 3 (2013-08-11 05:25:39) TIMER_END{0,resolveServlet(NonExistingResource, path=/content/cassandra/movies/foo)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet 3 (2013-08-11 05:25:39) TIMER_END{0,ServletResolution} URI=/content/cassandra/movies/foo handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet 3 (2013-08-11 05:25:39) LOG Applying Requestfilters 3 (2013-08-11 05:25:39) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter 3 (2013-08-11 05:25:39) TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0} 3 (2013-08-11 05:25:39) TIMER_END{0,org.apache.sling.servlets.get.DefaultGetServlet#0} 3 (2013-08-11 05:25:39) TIMER_START{handleError:status=404} 4 (2013-08-11 05:25:39) TIMER_END{1,handleError:status=404} Using handler org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet 5 (2013-08-11 05:25:39) TIMER_END{5,Request Processing} Dumping SlingRequestProgressTracker Entries </pre> <hr> <address>ApacheSling/2.2 (jetty/6.1.x, OpenJDK 64-Bit Server VM 1.6.0_27, Linux 3.0.0-12-generic amd64)</address> </body> </html> ) expected:<200> but was:<404> at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.failNotEquals(Assert.java:277) at junit.framework.Assert.assertEquals(Assert.java:64) at junit.framework.Assert.assertEquals(Assert.java:195) at org.apache.sling.commons.testing.integration.HttpTestBase.getContent(HttpTestBase.java:380) at org.apache.sling.commons.testing.integration.HttpTestBase.getContent(HttpTestBase.java:355) at org.apache.sling.commons.testing.integration.HttpTestBase.getContent(HttpTestBase.java:347) at org.apache.sling.commons.testing.integration.HttpTestBase.getContent(HttpTestBase.java:342) at org.apache.sling.launchpad.webapp.integrationtest.resourceprovider.CassandraResourceProviderTest.assertStrings(CassandraResourceProviderTest.java:27) at org.apache.sling.launchpad.webapp.integrationtest.resourceprovider.CassandraResourceProviderTest.testMovieResource(CassandraResourceProviderTest.java:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at junit.framework.TestCase.runTest(TestCase.java:168) at junit.framework.TestCase.runBare(TestCase.java:134) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) Results : Failed tests: testMovieResource(org.apache.sling.launchpad.webapp.integrationtest.resourceprovider.CassandraResourceProviderTest): Expected status 200 for http://localhost:8080/content/cassandra/movies/foo(content=<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">(..) Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [ > > -Bertrand > -- Thanks /Dishara
