01: package simpleorm.properties;
02:
03: /** Unit tests the property subsystem. */
04:
05: public class SPropertyTest {
06:
07: final static SProperty NAME = new SProperty("Name");
08: final static SProperty DBFIELD = new SProperty("DBField");
09: final static SProperty PROMPT = new SProperty("Prompt") {
10: protected Object defaultValue(SPropertyMap map) {
11: SPropertyMap form = (SPropertyMap) map.getProperty(DBFIELD);
12: return form.getProperty(PROMPT);
13: }
14: };
15: final static SProperty PRIMARY_KEY = new SProperty("PKey");
16: final static SPropertyValue SDF_PRIMARY_KEY = new SPropertyValue(
17: PRIMARY_KEY);
18:
19: public static SPropertyMap newField(SPropertyValue[] pvals) {
20: SPropertyMap fld = new SPropertyMap();
21: fld.setPropertyValues(pvals);
22: return fld;
23: }
24:
25: public static void main(String[] argv) throws Exception {
26: SPropertyMap dbField = newField(new SPropertyValue[] {
27: NAME.pvalue("CustNr"), SDF_PRIMARY_KEY }); // Or PRIMARY_KEY.ptrue()
28: dbField.putProperty(PROMPT, "Customer Number");
29:
30: //SPropertyMap dbField2 = newField(dbField0.cloneMap());
31:
32: SPropertyMap uiField = new SPropertyMap();
33: uiField.putProperty(DBFIELD, dbField);
34:
35: if (!uiField.getProperty(PROMPT).equals("Customer Number"))
36: throw new RuntimeException("bad Prompt");
37: if (!dbField.getBoolean(PRIMARY_KEY))
38: throw new RuntimeException("bad PKey");
39: }
40:
41: }
|