... and this is why you either want to look at unit testing using mocks, or at integration testing using Selenium. In the half-ground you end up with a lot of complications since the code is designed to run inside a servlet container and you don't have one.
PageTester exists to mock up the servlet container; that's another option. On Wed, Jan 5, 2011 at 8:08 AM, Donny Nadolny <donny.nado...@gmail.com>wrote: > You can contribute just the name of the file you want > ("quartz.properties"), > put it in the classpath, eg in src/main/resources, and then in the place > where you need to use it, load it from the classloader as a resource: > InputStream in = getClass().getResourceAsStream("quartz.properties"); > But instead of "quartz.properties" you can use the symbol that contains > that > filename. > > > On Wed, Jan 5, 2011 at 10:06 AM, abangkis <abang...@gmail.com> wrote: > > > Hi josh, thanks a lot. I follow your advice and tries to include all the > > module that i could think of. This is the modified initRegistry method : > > > > private void initRegistry() { > > RegistryBuilder builder = new RegistryBuilder(); > > builder.add(TapestryModule.class); > > builder.add(AppModule.class); > > builder.add(HibernateCoreModule.class); > > builder.add(ChenilleKitQuartzModule.class); > > registry = builder.build(); > > registry.performRegistryStartup(); > > } > > > > Adding TapestryModule fix the previous error, but i think I'm missing a > > little something here. The ChennileKitQuartzModule throw a null pointer > > exception > > > > Caused by: java.lang.RuntimeException: Error invoking service > contribution > > method > > > > > net.mreunion.cinematorserver.services.AppModule.contributeSchedulerFactory(ApplicationGlobals, > > OrderedConfiguration): java.lang.NullPointerException > > at > > > > > org.apache.tapestry5.ioc.internal.ContributionDefImpl.invokeMethod(ContributionDefImpl.java:139) > > at > > > > > org.apache.tapestry5.ioc.internal.ContributionDefImpl.contribute(ContributionDefImpl.java:82) > > at > > > org.apache.tapestry5.ioc.internal.RegistryImpl$9.run(RegistryImpl.java:651) > > at > > > > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:50) > > at > > > > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:47) > > at > > > > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65) > > ... 98 more > > Caused by: java.lang.NullPointerException > > at > > > > > net.mreunion.cinematorserver.services.AppModule.contributeSchedulerFactory(AppModule.java:116) > > > > That leads to the quartz contribution method in my app module > > > > public static void contributeSchedulerFactory( > > @InjectService("ApplicationGlobals") ApplicationGlobals > > applicationGlobals, > > OrderedConfiguration<URL> configuration) { > > String fileName = applicationGlobals.getServletContext().getRealPath( > > "/WEB-INF/classes/quartz.properties"); > > File file = new File(fileName); > > if (!file.canRead()) > > throw new RuntimeException(String.format("can't read file '%s'", > > file.toURI())); > > > > try { > > configuration.add("configuration", file.toURI().toURL()); > > } catch (MalformedURLException e) { > > throw new RuntimeException(e); > > } > > } > > > > public static void contributeQuartzSchedulerManager( > > OrderedConfiguration<JobSchedulingBundle> configuration, > > CrawlingJobImpl crawlingJob, JakartaCrawler crawler) { > > configuration.add("crawlScheduler", new > CrawlSchedulerBundle(crawlingJob, > > crawler)); > > } > > > > The null pointer is in the > > > > String fileName = applicationGlobals.getServletContext().getRealPath( > > "/WEB-INF/classes/quartz.properties"); > > > > I guess it makes sense, since TestNG is not using Servlet Context to run > > the > > test. Is there anyway to contribute the quartz.properties that will work > > inside and outside of the servlet context ? > > > > > > Cheers, > > Abangkis > > > > On Wed, Jan 5, 2011 at 9:38 PM, Josh Canfield <joshcanfi...@gmail.com > > >wrote: > > > > > It doesn't look like you are including TapestryModule in your registry. > > > Since you're building the registry you're in charge kit adding all the > > > modules. > > > > > > Optionally you could add @SubModule(TapestryModule.class) to your > > AppModule > > > to make the dependency explicit. > > > On Jan 5, 2011 4:25 AM, "abangkis" <abang...@gmail.com> wrote: > > > > Hello, i have a tapestry app that consist of 1-2 pages, and lots of > > > > services. The apps is used to crawl another website. The apps uses > > > hibernate > > > > module, quartz and some other contribution. Because of the nature of > my > > > > apps, i want to test the services class using TestNG. I've created a > > > simple > > > > test that build the tapestry registry for my services and run it. But > i > > > > received an error that the ComponentRequestHandler doesn't exist. > > Here's > > > the > > > > contribution in the appmodule, test file and the stack trace. I > wonder > > > what > > > > I've missed ? > > > > > > > > > > > > Cheers, > > > > Abangkis > > > > > > > > public class AppModule { > > > > .... > > > > > > > > public void > > > > > > > > > > > > > contributeComponentRequestHandler(OrderedConfiguration<ComponentRequestFilter> > > > > configuration) { > > > > configuration.addInstance("PageProtectionFilter", > > > > PageProtectionFilter.class); > > > > } > > > > public void > > contributeRequestHandler(OrderedConfiguration<RequestFilter> > > > > configuration, > > > > PageRenderLinkSource pageRenderLinkSource) { > > > > final HashSet<String> ASSETS_WHITE_LIST = new > > > > HashSet<String>(Arrays.asList("jpg", "jpeg", "png", "gif", "js", > > > > "css", "ico", "html", "json")); > > > > configuration.add("AssetProtectionFilter", new > > > > AssetProtectionFilter(ASSETS_WHITE_LIST, pageRenderLinkSource), > > > > "before:*"); > > > > } > > > > .... > > > > } > > > > > > > > public class MyTest { > > > > private Registry registry; > > > > > > > > @Test > > > > public void f() { > > > > String pageName = "DummyPage"; > > > > MovieManager movieManager = registry.getService(MovieManager.class); > > > > String result = movieManager.getMovieTitle(pageName); > > > > assertEquals("Gullivers Island", result); > > > > } > > > > > > > > @BeforeClass > > > > public void beforeClass() { > > > > // registry = IOCUtilities.buildDefaultRegistry(); > > > > initRegistry(); > > > > } > > > > > > > > private void initRegistry() { > > > > RegistryBuilder builder = new RegistryBuilder(); > > > > builder.add(ChenilleKitQuartzModule.class); > > > > builder.add(AppModule.class); > > > > registry = builder.build(); > > > > registry.performRegistryStartup(); > > > > } > > > > > > > > @AfterClass > > > > public void afterClass() { > > > > registry.shutdown(); > > > > } > > > > > > > > } > > > > > > > > FAILED CONFIGURATION: @BeforeClass beforeClass > > > > java.lang.IllegalArgumentException: Contribution > > > > > > > > > > > > > net.mreunion.cinematorserver.services.AppModule.contributeComponentRequestHandler(OrderedConfiguration) > > > > (at AppModule.java:145) is for service 'ComponentRequestHandler', > which > > > does > > > > not exist. > > > > at > > > > > > > > > > > > > org.apache.tapestry5.ioc.internal.RegistryImpl.validateContributeDefs(RegistryImpl.java:253) > > > > at > > > > > > > > > > > > > org.apache.tapestry5.ioc.internal.RegistryImpl.<init>(RegistryImpl.java:229) > > > > at > > > > org.apache.tapestry5.ioc.RegistryBuilder.build(RegistryBuilder.java:170) > > > > at > > > > net.mreunion.cinematorserver.TestEscapedCharacter.initRegistry(MyTest > > > .java:45) > > > > at > > > > net.mreunion.cinematorserver.TestEscapedCharacter.beforeClass(MyTest > > > .java:33) > > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > > > at java.lang.reflect.Method.invoke(Unknown Source) > > > > at > > > > > > > > > > > > > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74) > > > > at > > > org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525) > > > > at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202) > > > > at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:130) > > > > at > > > > > > > > > > > > > org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:173) > > > > at > org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105) > > > > at org.testng.TestRunner.runWorkers(TestRunner.java:1125) > > > > at org.testng.TestRunner.privateRun(TestRunner.java:749) > > > > at org.testng.TestRunner.run(TestRunner.java:600) > > > > at org.testng.SuiteRunner.runTest(SuiteRunner.java:317) > > > > at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312) > > > > at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274) > > > > at org.testng.SuiteRunner.run(SuiteRunner.java:223) > > > > at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) > > > > at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) > > > > at org.testng.TestNG.runSuitesSequentially(TestNG.java:995) > > > > at org.testng.TestNG.runSuitesLocally(TestNG.java:920) > > > > at org.testng.TestNG.run(TestNG.java:856) > > > > at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110) > > > > at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205) > > > > at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174) > > > > > > > > > > > > -- > > > > http://www.mreunion-labs.net/ > > > > twitter : @mreunionlabs > > > > blog : mreunion.wordpress.com > > > > Follow our android survey at : > > > > http://www.mreunion-labs.net/downloads:dlapk/MySurvey.apk > > > > > > > > > > > -- > > http://www.mreunion-labs.net/ > > twitter : @mreunionlabs > > blog : mreunion.wordpress.com > > Follow our android survey at : > > http://www.mreunion-labs.net/downloads:dlapk/MySurvey.apk > > > -- Howard M. Lewis Ship Creator of Apache Tapestry The source for Tapestry training, mentoring and support. Contact me to learn how I can get you up and productive in Tapestry fast! (971) 678-5210 http://howardlewisship.com