svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / test / java / org / gvsig / fmap / dal / feature / impl / rule / RuleExpressionTest.java @ 47723
History | View | Annotate | Download (3.48 KB)
1 |
package org.gvsig.fmap.dal.feature.impl.rule; |
---|---|
2 |
|
3 |
import javax.json.JsonObject; |
4 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
5 |
import static org.gvsig.fmap.dal.feature.FeatureRule.CHECK_WHEN_USER_EDIT_FEATURE; |
6 |
import org.gvsig.fmap.dal.feature.FeatureRuleExpression; |
7 |
import org.gvsig.fmap.dal.feature.FeatureRules; |
8 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureRules; |
9 |
import org.gvsig.json.Json; |
10 |
import org.gvsig.json.SupportJson; |
11 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
12 |
|
13 |
public class RuleExpressionTest extends AbstractLibraryAutoInitTestCase { |
14 |
|
15 |
@Override
|
16 |
protected void doSetUp() throws Exception { |
17 |
|
18 |
} |
19 |
|
20 |
public void testRuleExpressionToJson() { |
21 |
|
22 |
FeatureRules rules = new DefaultFeatureRules();
|
23 |
|
24 |
rules.add("test", null, false, false, ExpressionUtils.createExpression("TRUE")); |
25 |
FeatureRuleExpression rule = (FeatureRuleExpression) rules.get(0);
|
26 |
rule.setCheckWhen(CHECK_WHEN_USER_EDIT_FEATURE); |
27 |
|
28 |
String jsons = ((SupportJson)rules).toJson().toString();
|
29 |
String expected = "\n" + |
30 |
"{\n" +
|
31 |
" \"__classname__\":\"org.gvsig.fmap.dal.feature.impl.DefaultFeatureRules\",\n" +
|
32 |
" \"items\":[\n" +
|
33 |
" {\n" +
|
34 |
" \"__classname__\":\"org.gvsig.expressionevaluator.impl.DefaultFeatureRuleExpression\",\n" +
|
35 |
" \"name\":\"test\",\n" +
|
36 |
" \"description\":null,\n" +
|
37 |
" \"checkWhen\":4,\n" +
|
38 |
" \"checkAtFinishEdition\":false,\n" +
|
39 |
" \"checkAtUpdate\":false,\n" +
|
40 |
" \"expression\":\"TRUE\"\n" +
|
41 |
" }\n" +
|
42 |
" ]\n" +
|
43 |
"}";
|
44 |
assertEquals(expected, jsons); |
45 |
} |
46 |
|
47 |
public void testRuleExpressionFromJson() { |
48 |
|
49 |
FeatureRules rules = new DefaultFeatureRules();
|
50 |
|
51 |
String rules_jsons = "\n" + |
52 |
"{\n" +
|
53 |
" \"__classname__\":\"org.gvsig.fmap.dal.feature.impl.DefaultFeatureRules\",\n" +
|
54 |
" \"items\":[\n" +
|
55 |
" {\n" +
|
56 |
" \"__classname__\":\"org.gvsig.expressionevaluator.impl.DefaultFeatureRuleExpression\",\n" +
|
57 |
" \"name\":\"test\",\n" +
|
58 |
" \"description\":null,\n" +
|
59 |
" \"checkWhen\":4,\n" +
|
60 |
" \"checkAtFinishEdition\":false,\n" +
|
61 |
" \"checkAtUpdate\":false,\n" +
|
62 |
" \"expression\":\"TRUE\"\n" +
|
63 |
" }\n" +
|
64 |
" ]\n" +
|
65 |
"}";
|
66 |
JsonObject rules_json = Json.createObject(rules_jsons); |
67 |
((SupportJson)rules).fromJson(rules_json); |
68 |
|
69 |
// String s = ((SupportJson)rules).toJson().toString();
|
70 |
// assertEquals(rules_jsons, s);
|
71 |
|
72 |
assertEquals(1, rules.size());
|
73 |
|
74 |
FeatureRuleExpression rule = (FeatureRuleExpression) rules.get(0);
|
75 |
assertEquals(false, rule.checkAtFinishEditing());
|
76 |
assertEquals(false, rule.checkAtUpdate());
|
77 |
assertEquals(true, rule.checkWhen(CHECK_WHEN_USER_EDIT_FEATURE));
|
78 |
assertEquals("test", rule.getName());
|
79 |
assertEquals(null, rule.getDescription());
|
80 |
assertEquals("TRUE", rule.getExpression().getPhrase());
|
81 |
} |
82 |
|
83 |
|
84 |
} |