Hi Borut,
It looks like the T5 page class also contain the tests.
You need to have separate classes for the page and for the tests. To test
components I create pages that I call "demo" pages (because they
demonstrate the component).
Also I would advise putting the test class in a different package (I know
it's in a different source tree - but the java package is the same) as
that will stop T5 thinking the test class is part of the T5
pages/components/mixins classes. T5 uses a special classloader for those
classes in order to implement its live reloading functionality - so best
to keep other things away from that magic.
So, my project layout would look like the following (notice that some of
this is a very personal choice, but I'll present everything and you can
choose what you like):
+---src
+---main
¦ +---java
¦ ¦ +---si
¦ ¦ +---najdi
¦ ¦ +---tapestry
¦ ¦ +---library
¦ ¦ +---components
¦ ¦ ¦ DayMonthYearDateInput.java
¦ ¦ ¦ day-month-year-date-input-error.png
¦ ¦ ¦ day-month-year-date-input.png
¦ ¦ ¦ DayMonthYearDateInput.properties
¦ ¦ ¦ DayMonthYearDateInput.tml
¦ ¦ ¦ DayMonthYearDateInput.xdoc
¦ ¦ ¦
DayMonthYearDateInput_sl_SI.properties
¦ ¦ ¦
¦ ¦ +---mixins
¦ ¦ ¦ ZoneUpdater.java
¦ ¦ ¦ ZoneUpdater.js
¦ ¦ ¦
¦ ¦ +---services
¦ ¦ ¦ LibraryModule.java
¦ ¦ ¦ TestInfrastructureModule.java
¦ ¦ ¦
¦ ¦ +---util
¦ ¦ IntegerOptionModel.java
¦ ¦ IntegerSelectModel.java
¦ ¦ IntegerValueEncoder.java
¦ ¦ Month.java
¦ ¦
¦ +---resources
¦ log4j.properties
|
+---site
¦ ¦ site.xml
¦ ¦
¦ +---xdoc
¦ index.xml
¦
+---test
+---conf
¦ testng.xml
|
+---java
+---test
+---si
+---najdi
+---tapestry
+---library
+---base
¦
AbstractT5ComponentsLibraryTest.java
¦
+---demo
¦ ¦ DemoModule.java
¦ +---components
¦ DayMonthYearDateInputDemo.tml
¦ DayMonthYearDateInputDemo.java
+---components
DayMonthYearDateInputTest.java
Things to note:
a) I've put all the component's resources alongside the java class (in
src/main/java/si/najdi/tapestry/library/components). Personally, I find it
much easier to work with resources that are associated with a class if I
do this.
To make Maven allow this you need to add the following to your pom (you
may need to tweak the 'includes' and 'excludes' rules depending on what
you have in your source folders):
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<filtering>false</filtering>
</testResource>
</testResources>
b) I put all the tests in a parallel package hierarchy prefixed with
"test". So the tests for components in:
si.najdi.tapestry.library.components
will be found in the package:
test.si.najdi.tapestry.library.components
This makes it easy to find the tests but also keeps them separate from a
Java runtime point-of-view.
FYI, the Eclipse plugin MoreUnit (http://moreunit.sourceforge.net/) makes
it easy to jump between classes and tests and understands this convention.
c) For components, I create "demo" pages in a parallel hierarchy near the
test package. So the demo pages for:
si.najdi.tapestry.library.components
will be found in the package:
test.si.najdi.tapestry.library.demo.components
This choice makes the demo pages and the tests fairly near each other in a
package explorer view in your IDE. You can't put them in the same package
because of T5's special classloading for pages/components/mixins.
When running the tests, I create the IOC container with an additional
module (give this class as a parameter when you create your
TapestryTester):
package test.si.najdi.tapestry.library.demo;
public class DemoModule {
public static void contributeComponentClassResolver(
Configuration<LibraryMapping> configuration) {
configuration.add(new LibraryMapping("demo",
DemoModule.class.getPackage().getName()));
}
}
And I would render the page like this:
private Document renderPage() {
return tester.renderPage("demo/DayMonthYearDateInputDemo");
}
Hope you find that useful.
- Paul
---
This e-mail may contain confidential and/or privileged information. If you are
not the intended recipient (or have received this e-mail in error) please
notify the sender immediately and delete this e-mail. Any unauthorized copying,
disclosure or distribution of the material in this e-mail is strictly forbidden.
Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional
EU corporate and regulatory disclosures.