Property Expressions
Property expressions are very common in Java these days. They are used by JSP 2.0 EL, by Struts and by Spring Framework. Basically they are the same everywhere, so we will not go into all the detail. We just give some examples on how they work when you try to set data using them.
| Property Expression |
Java Equivalent |
| foo |
yourTestCase.setFoo(someValue) |
| foo.bar |
yourTestCase.getFoo().setBar(someValue) |
Notice how it is always assumed that the bean to start looking for properties in is always the current test case.
See also the Spring Ref Manual
on the topic.
Where Data Comes From
ddsteps-defaults.properties
In this properties file, to be placed in the default package ("the "root" of the classpath), contains defaults. The key is a property expression. The defaults are applied first, so if the same property expression exists in the Excel file (see below) the value from the "ddsteps-defaults.properties" is applied first and then overwritten by the value from the Excel file.
If the property expression does not match a bean, i.e. if there is no getFoo() in your test case, or there is not setBaz() on the bean returned from getBar() then the value is ignored, as these are only defaults. The test case will not fail because of this, but a warning will be logged (using Commons Logging).
Excel
An Excel file with the same name as you TestCase is loaded, from the same package as your TestCase. The headers is used as a property expression.

If a header / property expression does not match a bean, i.e. if there is no getFoo() in your test case, or there is not setBaz() on the bean returned from getBar(), then an exception is thrown, and the test case will fail. This helps you keep your Excel headers in synch with your test case and test step properties.
Data Types and Conversion
When data is pulled from your Excel file and from the properties file "ddsteps-defaults.properties", the data may not be in the right format. Your properties may be any Java class or native type (e.g. int, float), so some conversion will take place. If you are used to Spring Framework, most of this will seem familiar, but when dealing with Excel, there are some special cases to consider.
Remember: in most cases, if you have problems getting data into a property from Excel, try writing it as a text cell, instead of a number cell (or what not). You can easily force a cell to be a text cell, by writing "'my text", i.e. start the text with a single quote character.
Common conversions
These apply for both the "ddsteps-defaults.properties" file and for Excel. There may be more conversions that work (since we are Spring based) but these are the most common ones:
| Input |
Target Property type |
Info |
| Text* |
String |
No conversion. |
| Text* |
byte, short, int, long, float, double |
Uses standard Java parsing, i.e. write decimal numbers as "42.1" |
| Text* |
Byte, Short, Integer, Long, Float, Double |
Uses the constructor of each class that takes a String, i.e. write decimal numbers as "42.1" |
| Text* |
boolean or Boolean Uses Spring's Property Editor. |
See Spring Ref Manual . |
| Text* |
byte[], class, File, InputStream, Locale, Properties, String[], URL |
Uses the Spring's Property Editor that are registered by default (as stated in Spring's documentation. See Spring Ref Manual. |
| Text* |
Spring Resource |
See Spring Ref Manual . |
* = text means either the value from a properties file (which is text) or the value from a text cell in Excel.
Excel conversions
Since Excel has several, built-in datatypes, we handle some more specific conversions for Excel. This is where DDSteps typically add to the default Property Editors from Spring, with some specific data conversions.
In case you were wondering; number cells in Excel are Doubles internally.
| Input |
Target Property type |
Works? |
Info |
| Number Cell |
String |
Yes |
Double.toString() is used, NOT the formatted cell value as you see it in Excel. If you want to control the exact String, use a text cell. |
| Number Cell |
byte, short, int, long, Byte, Short, Integer, Long |
Yes |
The value is truncated using the methods in java.lang.Number, e.g. intValue(). |
| Number Cell |
double, Double |
Yes |
No conversion. |
| Number Cell |
float, Float |
Yes |
The value is truncated using the method in java.lang.Number, i.e. floatValue(). |
| Number Cell |
Anything else |
Not known |
You could try, but you probably want to use a text cell instead... |
| Boolean Cell |
boolean or Boolean |
Yes |
No conversion. |
| Boolean Cell |
String |
Yes |
Boolean.toString() is used, NOT the formatted cell value as you see it in Excel. If you want to control the exact String, use a text cell. |
| Boolean Cell |
Anything else |
Not known |
You could try, but you probably want to use a text cell instead... |
| Date Cell |
String |
Yes, but... |
Date.toString() is used, NOT the formatted cell value as you see it in Excel. If you want to control the exact String, use a text cell. |
| Date Cell |
java.util.Date |
Yes |
Works nicely, you can use Excel to write any date you want, and then get it as a java.util.Date. |
| Date Cell |
Anything else |
No |
Don't try this at home... |