1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data;
17
18 import org.apache.log4j.Level;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.kuali.rice.core.api.data.DataType;
22 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
23 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
24 import org.kuali.rice.krad.datadictionary.RelationshipDefinition;
25 import org.kuali.rice.krad.test.KRADTestCase;
26 import org.kuali.rice.krad.test.TestDictionaryConfig;
27 import org.kuali.rice.krad.uif.control.TextControl;
28
29 import static org.junit.Assert.*;
30
31
32
33
34 @TestDictionaryConfig(namespaceCode="KR-NS",dataDictionaryFiles="classpath:org/kuali/rice/krad/test/datadictionary/TestDataObject.xml")
35 public class DataDictionaryMetadataDefaultingTest extends KRADTestCase {
36
37 protected static final String MAIN_DATA_OBJECT_FOR_TESTING = "org.kuali.rice.krad.data.jpa.testbo.TestDataObject";
38
39 @Override
40 @Before
41 public void setUp() throws Exception {
42 setLogLevel("org.kuali.rice.krad.data.jpa.eclipselink.EclipseLinkJpaMetadataProviderImpl", Level.DEBUG);
43 setLogLevel("org.kuali.rice.krad.data.jpa.JpaMetadataProviderImpl", Level.DEBUG);
44 setLogLevel("org.kuali.rice.krad.data.provider.spring.SpringMetadataProviderImpl", Level.DEBUG);
45 setLogLevel("org.kuali.rice.krad.data.provider.impl.CompositeMetadataProviderImpl", Level.DEBUG);
46
47 setLogLevel("org.kuali.rice.krad.datadictionary.AttributeDefinition", Level.DEBUG);
48 setLogLevel("org.kuali.rice.krad.datadictionary.DataObjectEntry", Level.DEBUG);
49 setLogLevel("org.kuali.rice.krad.datadictionary.AttributeDefinitionBase", Level.DEBUG);
50 setLogLevel("org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase", Level.DEBUG);
51
52 super.setUp();
53
54 assertNotNull( "DD not set - configuration error!!!", dd );
55 }
56
57 @Test
58 public void verifyInRegistry() {
59 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
60 assertNotNull( "No embedded metadata object for TestDataObject", dataObjectEntry.getDataObjectMetadata() );
61 }
62
63 @Test
64 public void verifyLabelOverride() {
65 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
66
67 assertEquals("Label for DO not pulled from metadata: " + dataObjectEntry + "\n", "A Spring-Provided Label",
68 dataObjectEntry.getObjectLabel());
69 }
70
71 @Test
72 public void verifyUifObjectDescriptionOverride() {
73 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
74
75 assertEquals("Description not overridden", "UIF-Provided Description", dataObjectEntry.getObjectDescription());
76 }
77
78 @Test
79 public void verifyAttributeLabelOverrideFromSpringMetadata() {
80 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
81 AttributeDefinition attributeDefinition = dataObjectEntry.getAttributeDefinition("nonStandardDataType");
82 assertNotNull("nonStandardDataType attribute did not exist",attributeDefinition);
83 assertEquals(
84 "Label on nonStandardDataType attribute not pulled from Spring metadata: " + attributeDefinition + "\n",
85 "Non Standard Label-Spring", attributeDefinition.getLabel());
86 }
87
88 @Test
89 public void verifyAttributesExist() {
90 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
91
92 assertNotNull("attribute list should not have been null", dataObjectEntry.getAttributes() );
93 assertFalse("attribute list should not have been empty", dataObjectEntry.getAttributes().isEmpty());
94
95 assertNotNull("stringProperty should have been present in the list", dataObjectEntry.getAttributeDefinition("stringProperty") );
96 }
97
98 @Test
99 public void verifyAttributeProvidedAttributes() {
100 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
101
102 AttributeDefinition attributeDefinition = dataObjectEntry.getAttributeDefinition("stringProperty");
103 assertEquals("springProperty label incorrect", "Attribute Label From Annotation",
104 attributeDefinition.getLabel());
105 assertEquals("springProperty data type incorrect", DataType.STRING, attributeDefinition.getDataType());
106 }
107
108 public void verifyTitleAttribute() {
109 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
110
111 assertEquals("title attribute property incorrect", "primaryKeyProperty", dataObjectEntry.getTitleAttribute());
112 }
113
114 @Test
115 public void verifyPrimaryKey() {
116 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
117
118 assertNotNull("PK list should not have been null", dataObjectEntry.getPrimaryKeys() );
119 assertFalse("PK list should not have been empty", dataObjectEntry.getPrimaryKeys().isEmpty());
120 assertEquals("PK list length wrong", 1, dataObjectEntry.getPrimaryKeys().size());
121 assertEquals("PK field incorrect", "primaryKeyProperty", dataObjectEntry.getPrimaryKeys().get(0));
122 }
123
124 @Test
125 public void verifyDefaultedControl_stringProperty() {
126 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
127 String propertyName = "stringProperty";
128 AttributeDefinition attributeDefinition = dataObjectEntry.getAttributeDefinition(propertyName);
129 assertNotNull(propertyName + " should have been present in the attribute list", attributeDefinition );
130
131 assertNotNull( "the ControlField should not have been null", attributeDefinition.getControlField() );
132 assertTrue("Type of control field is incorrect", attributeDefinition.getControlField() instanceof TextControl);
133 assertEquals("Size of control is incorrect", 40,
134 ((TextControl) attributeDefinition.getControlField()).getSize());
135 assertNotNull( "MaxLength of control is missing", ((TextControl) attributeDefinition.getControlField()).getMaxLength() );
136 assertEquals("MaxLength of control is incorrect", 40,
137 ((TextControl) attributeDefinition.getControlField()).getMaxLength().intValue());
138 assertEquals("textExpand property incorrect", false,
139 ((TextControl) attributeDefinition.getControlField()).isTextExpand());
140 }
141
142 @Test
143 public void verifyDefaultedControl_longStringProperty() {
144 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
145 String propertyName = "longStringProperty";
146 AttributeDefinition attributeDefinition = dataObjectEntry.getAttributeDefinition(propertyName);
147 assertNotNull(propertyName + " should have been present in the attribute list", attributeDefinition );
148
149 assertNotNull( "the ControlField should not have been null", attributeDefinition.getControlField() );
150 assertTrue("Type of control field is incorrect", attributeDefinition.getControlField() instanceof TextControl);
151 assertEquals("Size of control is incorrect", 200,
152 ((TextControl) attributeDefinition.getControlField()).getSize());
153 assertNotNull( "MaxLength of control is missing", ((TextControl) attributeDefinition.getControlField()).getMaxLength() );
154 assertEquals("MaxLength of control is incorrect", 200,
155 ((TextControl) attributeDefinition.getControlField()).getMaxLength().intValue());
156 assertEquals("textExpand property incorrect", true,
157 ((TextControl) attributeDefinition.getControlField()).isTextExpand());
158 }
159
160 @Test
161 public void verifyDefaultedControl_dateProperty() {
162 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
163 String propertyName = "dateProperty";
164 AttributeDefinition attributeDefinition = dataObjectEntry.getAttributeDefinition(propertyName);
165 assertNotNull(propertyName + " should have been present in the attribute list", attributeDefinition );
166
167 assertNotNull( "the ControlField should not have been null", attributeDefinition.getControlField() );
168 assertTrue("Type of control field is incorrect", attributeDefinition.getControlField() instanceof TextControl);
169 assertNotNull( "control field is missing a datepicker", ((TextControl) attributeDefinition.getControlField()).getDatePicker() );
170 }
171
172 @Test
173 public void verifyDefaultedRelationship_existence() {
174 DataObjectEntry dataObjectEntry = getDataObjectEntry(MAIN_DATA_OBJECT_FOR_TESTING);
175 String relationshipName = "referencedObject";
176 RelationshipDefinition relationshipDefinition = dataObjectEntry.getRelationshipDefinition(relationshipName);
177 assertNotNull(relationshipName + " should have been present in the relationship list", relationshipDefinition );
178 }
179
180 protected DataObjectEntry getDataObjectEntry( String dataObjectClassName ) {
181 DataObjectEntry dataObjectEntry = dd.getDataObjectEntry(dataObjectClassName);
182 LOG.info("Loading DataObjectEntry for : " + dataObjectClassName);
183 assertNotNull( "Unable to retrieve data object entry for : " + dataObjectClassName, dataObjectEntry );
184 LOG.info( "DataObjectEntry: " + dataObjectEntry);
185 return dataObjectEntry;
186 }
187
188 }