1
2
3
4
5 package org.kuali.student.contract.model.impl;
6
7 import org.kuali.student.contract.model.MessageStructure;
8 import org.kuali.student.contract.model.Service;
9 import org.kuali.student.contract.model.ServiceContractModel;
10 import org.kuali.student.contract.model.ServiceMethod;
11 import org.kuali.student.contract.model.ServiceMethodParameter;
12 import org.kuali.student.contract.model.XmlType;
13 import org.kuali.student.contract.model.util.MessageStructureDumper;
14 import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.List;
18 import org.junit.After;
19 import org.junit.AfterClass;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import static org.junit.Assert.*;
24
25
26
27
28
29 public class ServiceContractModelPescXsdLoaderTest {
30
31 public ServiceContractModelPescXsdLoaderTest() {
32 }
33
34 @BeforeClass
35 public static void setUpClass() throws Exception {
36 }
37
38 @AfterClass
39 public static void tearDownClass() throws Exception {
40 }
41
42 @Before
43 public void setUp() {
44 }
45
46 @After
47 public void tearDown() {
48 }
49 private static final String RESOURCES_DIRECTORY =
50
51 "src/main/resources";
52 private static final String PESC_DIRECTORY =
53 RESOURCES_DIRECTORY + "/pesc";
54 private static final String PESC_CORE_MAIN = PESC_DIRECTORY + "/CoreMain.xsd";
55 private static final String PESC_ACAD_REC = PESC_DIRECTORY + "/AcademicRecord_v1.5.0.xsd";
56 private static final String PESC_COLL_TRANS = PESC_DIRECTORY + "/CollegeTranscript_v1.2.0.xsd";
57
58 private ServiceContractModel getModel() {
59 List<String> xsdFileNames = new ArrayList();
60
61
62 xsdFileNames.add(PESC_COLL_TRANS);
63 ServiceContractModel instance = new ServiceContractModelPescXsdLoader(xsdFileNames);
64 instance = new ServiceContractModelCache(instance);
65 validate(instance);
66 return instance;
67 }
68
69 private String dump(ServiceMethod method) {
70 StringBuilder bldr = new StringBuilder();
71 bldr.append(method.getName());
72 String comma = "";
73 bldr.append("(");
74 for (ServiceMethodParameter param : method.getParameters()) {
75 bldr.append(comma);
76 comma = ", ";
77 bldr.append(param.getType());
78 bldr.append(" ");
79 bldr.append(param.getName());
80 }
81 bldr.append(")");
82 return bldr.toString();
83 }
84
85 private void validate(ServiceContractModel model) {
86 Collection<String> errors =
87 new ServiceContractModelValidator(model).validate();
88 if (errors.size() > 0) {
89 StringBuilder buf = new StringBuilder();
90 buf.append(errors.size()).append(" errors found while validating the data.");
91 int cnt = 0;
92 for (String msg : errors) {
93 cnt++;
94 buf.append("\n");
95 buf.append("*error*").append(cnt).append(":").append(msg);
96 }
97
98 fail(buf.toString());
99 }
100 }
101
102
103
104
105 @Test
106 public void testGetServiceMethods() {
107 System.out.println("getServiceMethods");
108 ServiceContractModel model = getModel();
109 List<ServiceMethod> result = model.getServiceMethods();
110 System.out.println("Number of methods=" + result.size());
111 for (ServiceMethod method : result) {
112 System.out.println(dump(method));
113 }
114 if (result.size() < 1) {
115 fail("too few: " + result.size());
116 }
117 }
118
119
120
121
122 @Test
123 public void testGetSourceNames() {
124 System.out.println("getSourceNames");
125 ServiceContractModel model = getModel();
126 List<String> expResult = new ArrayList();
127 expResult.add(PESC_COLL_TRANS);
128 List result = model.getSourceNames();
129 assertEquals(expResult, result);
130 }
131
132
133
134
135 @Test
136 public void testGetServices() {
137 System.out.println("getServices");
138 ServiceContractModel model = getModel();
139 List<Service> result = model.getServices();
140 assertEquals(1, result.size());
141 for (Service service : result) {
142 System.out.println(service.getKey() + " " + service.getName() + " "
143 + service.getVersion() + " " + service.getStatus()
144 + " " + service.getComments()
145 + " " + service.getUrl());
146 }
147 }
148
149
150
151
152 @Test
153 public void testGetXmlTypes() {
154 System.out.println("getXmlTypes");
155 ServiceContractModel model = getModel();
156 List<XmlType> result = model.getXmlTypes();
157 if (result.size() < 10) {
158 fail("too few: " + result.size());
159 }
160 }
161
162
163
164
165 @Test
166 public void testGetMessageStructures() {
167 System.out.println("getMessageStructures");
168 ServiceContractModel model = getModel();
169 List<MessageStructure> result = model.getMessageStructures();
170 if (result.size() < 10) {
171 fail("too few: " + result.size());
172 }
173 for (MessageStructure ms : result) {
174 new MessageStructureDumper(ms, System.out).dump();
175 }
176 }
177 }