Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
60   177   17   4.62
8   135   0.28   13
13     1.31  
1    
 
  ServiceContractModelPescXsdLoaderTest       Line # 29 60 0% 17 81 0% 0.0
 
No Tests
 
1    /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
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    * @author nwright
28    */
 
29    public class ServiceContractModelPescXsdLoaderTest {
30   
 
31  0 toggle public ServiceContractModelPescXsdLoaderTest() {
32    }
33   
 
34  0 toggle @BeforeClass
35    public static void setUpClass() throws Exception {
36    }
37   
 
38  0 toggle @AfterClass
39    public static void tearDownClass() throws Exception {
40    }
41   
 
42  0 toggle @Before
43    public void setUp() {
44    }
45   
 
46  0 toggle @After
47    public void tearDown() {
48    }
49    private static final String RESOURCES_DIRECTORY =
50    // "C:/svn/student/ks-core/ks-core-api/src/main/java";
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  0 toggle private ServiceContractModel getModel() {
59  0 List<String> xsdFileNames = new ArrayList();
60    // xsdFileNames.add(PESC_CORE_MAIN);
61    // xsdFileNames.add(PESC_ACAD_REC);
62  0 xsdFileNames.add(PESC_COLL_TRANS);
63  0 ServiceContractModel instance = new ServiceContractModelPescXsdLoader(xsdFileNames);
64  0 instance = new ServiceContractModelCache(instance);
65  0 validate(instance);
66  0 return instance;
67    }
68   
 
69  0 toggle private String dump(ServiceMethod method) {
70  0 StringBuilder bldr = new StringBuilder();
71  0 bldr.append(method.getName());
72  0 String comma = "";
73  0 bldr.append("(");
74  0 for (ServiceMethodParameter param : method.getParameters()) {
75  0 bldr.append(comma);
76  0 comma = ", ";
77  0 bldr.append(param.getType());
78  0 bldr.append(" ");
79  0 bldr.append(param.getName());
80    }
81  0 bldr.append(")");
82  0 return bldr.toString();
83    }
84   
 
85  0 toggle private void validate(ServiceContractModel model) {
86  0 Collection<String> errors =
87    new ServiceContractModelValidator(model).validate();
88  0 if (errors.size() > 0) {
89  0 StringBuilder buf = new StringBuilder();
90  0 buf.append(errors.size()).append(" errors found while validating the data.");
91  0 int cnt = 0;
92  0 for (String msg : errors) {
93  0 cnt++;
94  0 buf.append("\n");
95  0 buf.append("*error*").append(cnt).append(":").append(msg);
96    }
97   
98  0 fail(buf.toString());
99    }
100    }
101   
102    /**
103    * Test of getServiceMethods method, of class ServiceContractModelQDoxLoader.
104    */
 
105  0 toggle @Test
106    public void testGetServiceMethods() {
107  0 System.out.println("getServiceMethods");
108  0 ServiceContractModel model = getModel();
109  0 List<ServiceMethod> result = model.getServiceMethods();
110  0 System.out.println("Number of methods=" + result.size());
111  0 for (ServiceMethod method : result) {
112  0 System.out.println(dump(method));
113    }
114  0 if (result.size() < 1) {
115  0 fail("too few: " + result.size());
116    }
117    }
118   
119    /**
120    * Test of getSourceNames method, of class ServiceContractModelQDoxLoader.
121    */
 
122  0 toggle @Test
123    public void testGetSourceNames() {
124  0 System.out.println("getSourceNames");
125  0 ServiceContractModel model = getModel();
126  0 List<String> expResult = new ArrayList();
127  0 expResult.add(PESC_COLL_TRANS);
128  0 List result = model.getSourceNames();
129  0 assertEquals(expResult, result);
130    }
131   
132    /**
133    * Test of getServices method, of class ServiceContractModelQDoxLoader.
134    */
 
135  0 toggle @Test
136    public void testGetServices() {
137  0 System.out.println("getServices");
138  0 ServiceContractModel model = getModel();
139  0 List<Service> result = model.getServices();
140  0 assertEquals(1, result.size());
141  0 for (Service service : result) {
142  0 System.out.println(service.getKey() + " " + service.getName() + " "
143    + service.getVersion() + " " + service.getStatus()
144    + " " + service.getComments()
145    + " " + service.getUrl());
146    }
147    }
148   
149    /**
150    * Test of getXmlTypes method, of class ServiceContractModelQDoxLoader.
151    */
 
152  0 toggle @Test
153    public void testGetXmlTypes() {
154  0 System.out.println("getXmlTypes");
155  0 ServiceContractModel model = getModel();
156  0 List<XmlType> result = model.getXmlTypes();
157  0 if (result.size() < 10) {
158  0 fail("too few: " + result.size());
159    }
160    }
161   
162    /**
163    * Test of getMessageStructures method, of class ServiceContractModelQDoxLoader.
164    */
 
165  0 toggle @Test
166    public void testGetMessageStructures() {
167  0 System.out.println("getMessageStructures");
168  0 ServiceContractModel model = getModel();
169  0 List<MessageStructure> result = model.getMessageStructures();
170  0 if (result.size() < 10) {
171  0 fail("too few: " + result.size());
172    }
173  0 for (MessageStructure ms : result) {
174  0 new MessageStructureDumper(ms, System.out).dump();
175    }
176    }
177    }