You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by vi...@apache.org on 2012/08/25 12:55:06 UTC
svn commit: r1377260 -
/openejb/site/trunk/content/dev/writing-validation-tests.mdtext
Author: vishwanathk
Date: Sat Aug 25 10:55:05 2012
New Revision: 1377260
URL: http://svn.apache.org/viewvc?rev=1377260&view=rev
Log:
CMS commit to openejb by vishwanathk
Modified:
openejb/site/trunk/content/dev/writing-validation-tests.mdtext
Modified: openejb/site/trunk/content/dev/writing-validation-tests.mdtext
URL: http://svn.apache.org/viewvc/openejb/site/trunk/content/dev/writing-validation-tests.mdtext?rev=1377260&r1=1377259&r2=1377260&view=diff
==============================================================================
--- openejb/site/trunk/content/dev/writing-validation-tests.mdtext (original)
+++ openejb/site/trunk/content/dev/writing-validation-tests.mdtext Sat Aug 25 10:55:05 2012
@@ -1,4 +1,5 @@
Title: Writing Validation Tests
+
<a name="WritingValidationTests-Summary"></a>
## Summary
@@ -11,31 +12,36 @@ tests using example snippets.
<a name="WritingValidationTests-TheValidationFramework"></a>
## The Validation Framework
-1. *org.apache.openejb.config.ConfigurationFactory* uses a _chain_ of
-*org.apache.openejb.config.DynamicDeployer* implementations. One of the
-implementations in the _chain_ is
-*org.apache.openejb.config.ValidateModules*. *ValidateModules* is
+1. `org.apache.openejb.config.ConfigurationFactory` uses a chain of
+`org.apache.openejb.config.DynamicDeployer` implementations. One of the
+implementations in the chain is
+`org.apache.openejb.config.ValidateModules`. `ValidateModules` is
conditionally added to the _chain_ if the property
-*openejb.validation.skip=false*. If this property is false, then
-*ValidateModules* is used to kick off the _Validation Framework_.
-{snippet:id=code|url=openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java|lang=java}
-1. Internally ValidateModules uses the *AppValidator.validate()* method.
-{snippet:id=code|url=openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java|lang=java}
+`openejb.validation.skip=false`. If this property is false, then
+`ValidateModules` is used to kick off the Validation Framework
+
+[Configuration Factory](https://github.com/apache/openejb/tree/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java)
+
+1. Internally ValidateModules uses the [*AppValidator.validate()* method](https://github.com/apache/openejb/tree/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/ValidateModules.java)
+
1. This method then performs validation using a number of rules. _A
validation rule/s is represented by a class implementing ValidationRule_.
In fact, all the classes checking the validation rules , extend
ValidationBase, which further implements ValidationRule.
-{gliffy:name=Class Diagram|align=left|size=L|version=2}
+
+ <img src="images/ClassDiagram.png" alt="" align="center">
+
The _list of rules_ being executed can actually be found in the following
-method of AppValidator.
-{snippet:id=code1|url=openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java|lang=java}
+method of [AppValidator](https://github.com/apache/openejb/tree/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java)
1. The above rules are then executed one by one
-{snippet:id=code2|url=openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AppValidator.java|lang=java}
+{snippet:id=code2|url=openejb3/container/openejb-
+core/src/main/java/org/apache/openejb/config/AppValidator.java|lang=java}
+
1. Each module has an attached ValidationContext , which maintains a list of
failures, warnings and errors. As the above rules are being invoked, the
failure/errors/warnings for a module are being added to its
ValidationContext. Every Validation failure has an associated message which
-can be found in *org/apache/openejb/config/rules/messages.properties*. A
+can be found in `org/apache/openejb/config/rules/messages.properties`. A
message has three levels as explained below:
Format for the different levels follows this spirit:
@@ -79,37 +85,38 @@ go and re-attempt deploying the applicat
1. The test framework is specifically written with the following goals in
mind:
-1. # It should be easy to write the test, and the framework should do
+1. It should be easy to write the test, and the framework should do
the boiler-plate work, the test author just needs to provide the relevant
info
-1. # It should report the test coverage i.e. the framework should
+1. It should report the test coverage i.e. the framework should
generate a report regarding which keys in messages.properties have tests
written for them and what is the corresponding Test class/es which test for
the validation rule associated with that key
-1. # It should ensure that if a test is being written for a specific
+1. It should ensure that if a test is being written for a specific
message key, then that key should exist in the messages.properties file
-1. Lets break down the framework by using an example:
-{snippet:id=code|url=openejb3/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInjectionTargetsTest.java|lang=java}
-1. # The first thing to note is that we are running the test using our
+1. Lets break down the framework by using an [example](https://github.com/apache/openejb/tree/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/CheckInjectionTargetsTest.java)
+
+
+ 1. The first thing to note is that we are running the test using our
own custom runner i.e. @RunWith(ValidationRunner.class). This runner
ensures that the keys we are testing, actually exist in the
-messages.properties file. It does a lot more, as we shall see later
-1. # The test method
-1. ## Can be given any name
-1. ## Must be annotated with @Keys and CANNOT be annotated with @Test.
+messages.properties file. It does a lot more, as we shall see later
+ 2. The test method
+ 3. Can be given any name
+ 4. Must be annotated with @Keys and CANNOT be annotated with @Test.
The rest of the JUnit annotations can be used
-1. ## Must return one of EjbJar / EjbModule / AppModule. The returned
+ 5. Must return one of EjbJar / EjbModule / AppModule. The returned
EjbJar/EjbModule/AppModule will be specifically created to cause one or
more validation errors/warnings/failures.
-1. # Following annotations are provided by the framework
-1. ## @Keys : is a collection of zero or more @Key
-1. ## @Key : represents a key for which this test is being written. A @Key
+ 1. Following annotations are provided by the framework
+ 1. @Keys : is a collection of zero or more @Key
+ 1. @Key : represents a key for which this test is being written. A @Key
can be of type FAILURE or WARNING or ERROR. Default value is FAILURE. As
seen in the example above, the test() method is expecting two warnings for
the key injectionTarget.nameContainsSet. If count is not equal to 2 or some
other Validation Failure/Warning/Error was also thrown from the method,
then the test fails.
-{note:title=Be Careful}
+###Be Careful
The test must cause a Validation Failure otherwise the test framework does
not get invoked. For example, in the above code, a Key of type WARNING is
being tested, however the test is purposely being failed by putting an
@@ -126,26 +133,25 @@ generate the report. Simply invoke the f
The above command will create a complete test coverage report and post it
to this location [OPENEJB:Validation Keys Audit Report](openejb:validation-keys-audit-report.html)
-{info:title=Quick facts about ValidationRunner and things to keep in mind
-while writing tests}
+###Quick facts about ValidationRunner and things to keep in mind while writing tests
This class is created specifically to write tests which test OpenEjb
validation code. Specifically, it is used to check the usage of keys
-defined in org.apache.openejb.config.rules.Messages.properties. To use this
+defined in `org.apache.openejb.config.rules.Messages.properties`. To use this
runner, simply annotate your test case with
-@RunWith(ValidationRunner.class). Here are some things to keep in mind when
-writing tests:
-1. A test method needs to be annotated with
-org.apache.openejb.config.rules.Keys instead of the org.junit.Test
-1. Any usage of the @Test annotation will be ignored
-1. If the @Keys and @Test annotation are used together on a test method,
-then the TestCase will error out
-1. Every test method should create a EjbJar or EjbModule or AppModule and
+`@RunWith(ValidationRunner.class`). Here are some things to keep in mind when writing tests:
+ 1. A test method needs to be annotated with
+`org.apache.openejb.config.rules.Keys` instead of the `org.junit.Test`
+ 2. Any usage of the @Test annotation will be ignored
+ 3. If the @Keys and @Test annotation are used together on a test method,
+then the TestCase will error out
+ 4. Every test method should create a EjbJar or EjbModule or AppModule and
return it from the method. It should list the keys being tested in the
@Keys annotation
-1. The runner will invoke the test method and use the Assembler and
+
+1. The runner will invoke the test method and use the Assembler and
ConfigurationFactory to create the application
-1. This will kick off validation and this Runner will catch
+1.This will kick off validation and this Runner will catch
ValidationFailureException and make sure that all the keys specified in the
@Keys annotation show up
in the ValidationFailureException