1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.common.ui.server.mvc.dto; |
17 |
|
|
18 |
|
import static org.junit.Assert.assertEquals; |
19 |
|
import static org.junit.Assert.assertTrue; |
20 |
|
|
21 |
|
import java.util.HashMap; |
22 |
|
import java.util.List; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Test; |
27 |
|
import org.kuali.student.common.ui.client.mvc.DataModel; |
28 |
|
import org.kuali.student.common.ui.client.mvc.DataModelDefinition; |
29 |
|
import org.kuali.student.common.ui.client.validator.DataModelValidator; |
30 |
|
import org.kuali.student.core.assembly.data.ConstraintMetadata; |
31 |
|
import org.kuali.student.core.assembly.data.Data; |
32 |
|
import org.kuali.student.core.assembly.data.Metadata; |
33 |
|
import org.kuali.student.core.assembly.data.QueryPath; |
34 |
|
import org.kuali.student.core.assembly.data.Data.DataType; |
35 |
|
import org.kuali.student.core.assembly.data.Data.IntegerKey; |
36 |
|
import org.kuali.student.core.validation.dto.ValidationResultInfo; |
37 |
|
|
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (70) |
Complexity: 3 |
Complexity Density: 0.04 |
|
39 |
|
public class TestDataModel { |
40 |
|
|
41 |
|
DataModelDefinition rootModelDefinition; |
42 |
|
DataModelDefinition formatModelDefinition; |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 1 |
Complexity Density: 0.03 |
|
44 |
2
|
@Before... |
45 |
|
public void setup(){ |
46 |
|
|
47 |
|
|
48 |
2
|
Metadata metaId = new Metadata(); |
49 |
2
|
metaId.setDataType(DataType.STRING); |
50 |
2
|
ConstraintMetadata constraint = new ConstraintMetadata(); |
51 |
2
|
constraint.setMinLength(10); |
52 |
2
|
constraint.setMaxLength(10); |
53 |
2
|
metaId.getConstraints().add(constraint); |
54 |
|
|
55 |
|
|
56 |
2
|
Metadata metaTitle = new Metadata(); |
57 |
2
|
metaTitle.setDataType(DataType.STRING); |
58 |
2
|
metaTitle.getConstraints().add(constraint); |
59 |
2
|
Metadata metaType = new Metadata(); |
60 |
2
|
metaType.setDataType(DataType.STRING); |
61 |
|
|
62 |
|
|
63 |
2
|
Map<String, Metadata> formatProperties; |
64 |
2
|
formatProperties = new HashMap<String, Metadata>(); |
65 |
2
|
formatProperties.put("title", metaTitle); |
66 |
2
|
formatProperties.put("type", metaType); |
67 |
|
|
68 |
|
|
69 |
2
|
Metadata metaFormat = new Metadata(); |
70 |
2
|
metaFormat.setProperties(formatProperties); |
71 |
2
|
metaFormat.setDataType(DataType.DATA); |
72 |
|
|
73 |
|
|
74 |
2
|
Metadata metaFormats = new Metadata(); |
75 |
2
|
Map<String, Metadata> formatListProperties = new HashMap<String, Metadata>(); |
76 |
2
|
formatListProperties.put("*", metaFormat); |
77 |
2
|
metaFormats.setDataType(DataType.LIST); |
78 |
2
|
metaFormats.setProperties(formatListProperties); |
79 |
|
|
80 |
|
|
81 |
2
|
Metadata metadataRoot = new Metadata(); |
82 |
2
|
Map<String, Metadata> rootProperties = new HashMap<String, Metadata>(); |
83 |
2
|
rootProperties.put("formats", metaFormats); |
84 |
2
|
rootProperties.put("id", metaId); |
85 |
2
|
metadataRoot.setProperties(rootProperties); |
86 |
2
|
metadataRoot.setDataType(DataType.DATA); |
87 |
|
|
88 |
2
|
rootModelDefinition = new DataModelDefinition(); |
89 |
2
|
rootModelDefinition.setMetadata(metadataRoot); |
90 |
|
|
91 |
2
|
formatModelDefinition = new DataModelDefinition(); |
92 |
2
|
formatModelDefinition.setMetadata(metaFormat); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
95 |
1
|
@Test... |
96 |
|
public void testQueryWildpath(){ |
97 |
1
|
DataModel dataModel = new DataModel(); |
98 |
1
|
dataModel.setRoot(new Data()); |
99 |
1
|
dataModel.setDefinition(rootModelDefinition); |
100 |
|
|
101 |
1
|
dataModel.set(QueryPath.parse("formats/0/title"), "Format 1"); |
102 |
1
|
dataModel.set(QueryPath.parse("formats/1/title"), "Format 2"); |
103 |
|
|
104 |
1
|
Map<QueryPath, Object> values = dataModel.query("formats"); |
105 |
1
|
Map<QueryPath, Object> formatValues = dataModel.query("formats/*"); |
106 |
|
|
107 |
1
|
assertTrue(values.size()==1); |
108 |
1
|
assertTrue(formatValues.size()==2); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1
PASS
|
|
111 |
1
|
@Test... |
112 |
|
public void testDataModelValidator(){ |
113 |
1
|
DataModel dataModel = new DataModel(); |
114 |
1
|
List<ValidationResultInfo> validationResults; |
115 |
1
|
DataModelValidator validator = new CustomDataModelValidator(); |
116 |
|
|
117 |
|
|
118 |
1
|
dataModel.setRoot(new Data()); |
119 |
1
|
dataModel.setDefinition(rootModelDefinition); |
120 |
|
|
121 |
|
|
122 |
1
|
dataModel.set(QueryPath.parse("id"), "1234"); |
123 |
1
|
validationResults = validator.validate(dataModel); |
124 |
1
|
assertEquals(1, validationResults.size()); |
125 |
1
|
assertEquals("id", validationResults.get(0).getElement()); |
126 |
|
|
127 |
|
|
128 |
1
|
dataModel.set(QueryPath.parse("id"), "0123456890"); |
129 |
1
|
validationResults = validator.validate(dataModel); |
130 |
1
|
assertEquals(0, validationResults.size()); |
131 |
|
|
132 |
|
|
133 |
1
|
dataModel.set(QueryPath.parse("formats/0/title"), "Format 1"); |
134 |
1
|
validationResults = validator.validate(dataModel); |
135 |
1
|
assertEquals(1, validationResults.size()); |
136 |
|
|
137 |
1
|
assertEquals("formats/0/title", validationResults.get(0).getElement()); |
138 |
|
|
139 |
|
|
140 |
1
|
Data data = dataModel.getRoot(); |
141 |
1
|
data = data.get("formats"); |
142 |
1
|
data = data.get(new IntegerKey(0)); |
143 |
1
|
dataModel.setRoot(data); |
144 |
1
|
dataModel.setDefinition(formatModelDefinition); |
145 |
1
|
dataModel.setParentPath("formats/0"); |
146 |
|
|
147 |
1
|
validationResults = validator.validate(dataModel); |
148 |
1
|
assertEquals(1, validationResults.size()); |
149 |
|
|
150 |
1
|
assertEquals("title", validationResults.get(0).getElement()); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
|
public class CustomDataModelValidator extends DataModelValidator { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
3
|
@Override... |
161 |
|
protected String getValidationMessage(String msgKey) { |
162 |
3
|
return msgKey; |
163 |
|
} |
164 |
|
} |
165 |
|
} |