Fork me on GitHub


The unit tests have been retro-fitted, JUnit did not exist when the code was first written, so the objectives of the tests are:

  • to illustrate how to use public methods
  • to act as a comprehensive regression test
  • to highlight unused code

JUnit tests

Maven allows tests to be run in a single thread or a new thread per test. Running in a single thread is considerably faster. To enable the tests to run in a single thread it is important to ensure that tests clean up after themselves or different results will be returned when a test is run on its own, in Eclipse for example, to when it is run as part of a suite. To this end all database tests inherit a method to ensure that the number of rows in the database is unchanged.

JUnit tests are incorporated into the build:

  1. Results
  2. Source
  3. Coverage

Provoked SQLExceptions

The test suite uses a separate package (JDBC containing a decorated version of the java.sql API to cover the handling of SQLExceptions thrown by the JDBC connection.

The Driver and any sql object obtained from it can be instructed to throw an exception by use of a static method. This enables coverage of exception handling in a closed API.

Manual tests

The tests below were all we had before JUnit. A default installation should not produce errors for any of them.

ServletTest Simplest possible Hello World test.
ConfigServletTest Test that configuration (reading .properties files) is working.
ConfigServletTestOverride Test overriding upload directory programmatically.
CharsetServletTest Test display of various characters without using a Template Engine.
CharsetTemplateServletTest Test display of various characters using a Template Engine.
EmailTemplateServletTest Test Email sending utility, using a Template Engine.
FlushingServletTest Illustrate the difference between flushing and not flushing your output buffer.
PoemServletTest Test a Melati configuration which accesses a POEM database without using a Template Engine.
TemplateServletTest Test a Melati configuration with a Template Engine.
TemplateServletTestOverride Illustrate org.melati.login.HttpBasicAuthenticationAccessHandler as opposed to org.melati.login.HttpSessionAccessHandler.
WebmacroMelatiServletTest Test Melati in standalone mode (outside the servlet API) by expanding a template to a string and then including it within a template.
WebmacroStandalone This example demonstrates using WebMacro in "standalone" mode. Instead of subclassing from WMServlet you create and maintain your own WebMacro object and you are free to subclass from another servlet. (Copied from WebMacro dsitribution).
SessionAnalysisServlet Shows current sessions and jvm memory usage.