View Javadoc
1   package org.kuali.student.lum.dto.test;
2   
3   import static org.junit.Assert.fail;
4   
5   import java.lang.reflect.Field;
6   import java.util.ArrayList;
7   import java.util.Arrays;
8   import java.util.LinkedHashSet;
9   import java.util.List;
10  import java.util.Set;
11  
12  import org.junit.Test;
13  import org.kuali.student.r1.common.dictionary.service.impl.ComplexSubstructuresHelper;
14  import org.kuali.student.r2.core.statement.dto.StatementInfo;
15  import org.kuali.student.r2.lum.clu.dto.AccreditationInfo;
16  import org.kuali.student.r2.lum.clu.dto.AdminOrgInfo;
17  import org.kuali.student.r2.lum.clu.dto.AffiliatedOrgInfo;
18  import org.kuali.student.r2.lum.clu.dto.CluAccountingInfo;
19  import org.kuali.student.r2.lum.clu.dto.CluCluRelationInfo;
20  import org.kuali.student.r2.lum.clu.dto.CluFeeInfo;
21  import org.kuali.student.r2.lum.clu.dto.CluFeeRecordInfo;
22  import org.kuali.student.r2.lum.clu.dto.CluIdentifierInfo;
23  import org.kuali.student.r2.lum.clu.dto.CluInfo;
24  import org.kuali.student.r2.lum.clu.dto.CluInstructorInfo;
25  import org.kuali.student.r2.lum.clu.dto.CluLoRelationInfo;
26  import org.kuali.student.r2.lum.clu.dto.CluPublicationInfo;
27  import org.kuali.student.r2.lum.clu.dto.CluResultInfo;
28  import org.kuali.student.r2.lum.clu.dto.CluSetInfo;
29  import org.kuali.student.r2.lum.clu.dto.CluSetTreeViewInfo;
30  import org.kuali.student.r2.lum.clu.dto.ExpenditureInfo;
31  import org.kuali.student.r2.lum.clu.dto.FeeInfo;
32  import org.kuali.student.r2.lum.clu.dto.FieldInfo;
33  import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
34  import org.kuali.student.r2.lum.clu.dto.MembershipQueryInfo;
35  import org.kuali.student.r2.lum.clu.dto.ResultOptionInfo;
36  import org.kuali.student.r2.lum.clu.dto.RevenueInfo;
37  import org.kuali.student.r2.lum.course.dto.ActivityInfo;
38  import org.kuali.student.r2.lum.course.dto.CourseCrossListingInfo;
39  import org.kuali.student.r2.lum.course.dto.CourseExpenditureInfo;
40  import org.kuali.student.r2.lum.course.dto.CourseFeeInfo;
41  import org.kuali.student.r2.lum.course.dto.CourseInfo;
42  import org.kuali.student.r2.lum.course.dto.CourseJointInfo;
43  import org.kuali.student.r2.lum.course.dto.CourseRevenueInfo;
44  import org.kuali.student.r2.lum.course.dto.CourseVariationInfo;
45  import org.kuali.student.r2.lum.course.dto.FormatInfo;
46  import org.kuali.student.r2.lum.course.dto.LoDisplayInfo;
47  
48  public class TestDTOEqualXMLBeanDefinition {
49  
50  	private String formatAsString(List<String> errors) {
51  		int i = 0;
52  		StringBuilder builder = new StringBuilder();
53  		for (String error : errors) {
54  			i++;
55  			builder.append(i + ". " + error + "\n");
56  		}
57  		return builder.toString();
58  	}
59  
60  	@Test
61  	public void getLinkedListFields() {
62  		ComplexSubstructuresHelper helpme = new ComplexSubstructuresHelper();
63  		ArrayList<Field> fields = new ArrayList<Field>();
64  		fields = helpme.getAllFields(fields, StatementInfo.class);
65  		for (Field field : fields) {
66  			System.out.println(field.getName());
67  		}
68  	}
69  
70  	@Test
71  	public void testCluDTOsAgainstDataDictionary() {
72  		  System.out.println("testing statement dictionary");
73  		 
74  		  Set<String> startingClasses = new LinkedHashSet();
75  		  startingClasses.add(AccreditationInfo.class.getName());
76  		  startingClasses.add(AdminOrgInfo.class.getName());
77  		  startingClasses.add(AffiliatedOrgInfo.class.getName());
78  		  startingClasses.add(CluAccountingInfo.class.getName());
79  		  startingClasses.add(CluCluRelationInfo.class.getName());
80  		  startingClasses.add(CluFeeInfo.class.getName());
81  		  startingClasses.add(CluFeeRecordInfo.class.getName()); 
82  		  startingClasses.add(CluIdentifierInfo.class.getName());
83  	      startingClasses.add(CluInfo.class.getName());
84  		  startingClasses.add(CluInstructorInfo.class.getName());
85  		  startingClasses.add(CluLoRelationInfo.class.getName());
86  		  startingClasses.add(CluPublicationInfo.class.getName());
87  		  startingClasses.add(CluResultInfo.class.getName());
88  		  startingClasses.add(CluSetInfo.class.getName());
89  		  startingClasses.add(CluSetTreeViewInfo.class.getName());
90  		  startingClasses.add(ExpenditureInfo.class.getName());
91  		  startingClasses.add(FeeInfo.class.getName());
92  		  startingClasses.add(FieldInfo.class.getName());
93  		  startingClasses.add(LuCodeInfo.class.getName());
94  		  startingClasses.add(MembershipQueryInfo.class.getName());
95  		  startingClasses.add(ResultOptionInfo.class.getName());
96  		  startingClasses.add(RevenueInfo.class.getName());
97  		  
98  		  String contextFile = "ks-cluInfo-dictionary-context";
99  		  String outFile = "target/" + contextFile + ".txt";
100 		  DictionaryDiscrepencyTesterHelper helper = new DictionaryDiscrepencyTesterHelper(
101 		    outFile, startingClasses, contextFile + ".xml", false);
102 		  helper.setPrintDescrepenciesOnly(true);
103 		  List<String> errors = helper.doTest();
104 		  if (errors.size() > 0) {
105 		   fail("failed dictionary validation:\n" + formatAsString(errors));
106 		  }
107 
108 	}
109 	
110 	@Test
111 	public void testCourseDTOsAgainstDataDictionary() {
112 		System.out.println("testing statement dictionary");
113 		Set<String> startingClasses = new LinkedHashSet();
114         List<String> exclusions = Arrays.asList("searchCourseVersions", "cluset", "findCourse");
115 		startingClasses.add(ActivityInfo.class.getName());
116 		startingClasses.add(CourseCrossListingInfo.class.getName());
117 		startingClasses.add(CourseExpenditureInfo.class.getName());
118 		startingClasses.add(CourseFeeInfo.class.getName());
119 		startingClasses.add(CourseInfo.class.getName()); 
120 		startingClasses.add(CourseJointInfo.class.getName());
121 		startingClasses.add(CourseRevenueInfo.class.getName());
122 		startingClasses.add(CourseVariationInfo.class.getName());
123 		startingClasses.add(FormatInfo.class.getName());
124 		startingClasses.add(LoDisplayInfo.class.getName());
125 		
126 		String contextFile = "ks-courseInfo-dictionary-context";
127 		String outFile = "target/" + contextFile + ".txt";
128 		DictionaryDiscrepencyTesterHelper helper = new DictionaryDiscrepencyTesterHelper(
129 				outFile, startingClasses, contextFile + ".xml", false, exclusions);
130 		helper.setPrintDescrepenciesOnly(true);
131 		List<String> errors = helper.doTest();
132 		if (errors.size() > 0) {
133 			fail("failed dictionary validation:\n" + formatAsString(errors));
134 		}
135 
136 	}
137 }