| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.student.contract.model.impl; |
| 17 |
|
|
| 18 |
|
import java.io.File; |
| 19 |
|
import java.io.FileNotFoundException; |
| 20 |
|
import java.io.PrintStream; |
| 21 |
|
import java.util.ArrayList; |
| 22 |
|
import java.util.Collection; |
| 23 |
|
import java.util.List; |
| 24 |
|
import java.util.Set; |
| 25 |
|
import java.util.Stack; |
| 26 |
|
import org.junit.After; |
| 27 |
|
import org.junit.AfterClass; |
| 28 |
|
import org.junit.Before; |
| 29 |
|
import org.junit.BeforeClass; |
| 30 |
|
import org.junit.Test; |
| 31 |
|
import static org.junit.Assert.*; |
| 32 |
|
|
| 33 |
|
import org.kuali.student.contract.model.MessageStructure; |
| 34 |
|
import org.kuali.student.contract.model.Service; |
| 35 |
|
import org.kuali.student.contract.model.ServiceContractModel; |
| 36 |
|
import org.kuali.student.contract.model.ServiceMethod; |
| 37 |
|
import org.kuali.student.contract.model.ServiceMethodParameter; |
| 38 |
|
import org.kuali.student.contract.model.XmlType; |
| 39 |
|
import org.kuali.student.contract.model.util.HtmlContractServiceWriter; |
| 40 |
|
import org.kuali.student.contract.model.util.MessageStructureHierarchyDumper; |
| 41 |
|
import org.kuali.student.contract.model.util.ModelFinder; |
| 42 |
|
import org.kuali.student.contract.model.validation.ServiceContractModelValidator; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@author |
| 47 |
|
|
|
|
|
| 0% |
Uncovered Elements: 111 (111) |
Complexity: 19 |
Complexity Density: 0.22 |
|
| 48 |
|
public class ServiceContractModelQDoxLoaderTest { |
| 49 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 50 |
0
|
public ServiceContractModelQDoxLoaderTest() {... |
| 51 |
|
} |
| 52 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 53 |
0
|
@BeforeClass... |
| 54 |
|
public static void setUpClass() throws Exception { |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 57 |
0
|
@AfterClass... |
| 58 |
|
public static void tearDownClass() throws Exception { |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 61 |
0
|
@Before... |
| 62 |
|
public void setUp() { |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 65 |
0
|
@After... |
| 66 |
|
public void tearDown() { |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
private static final String RESOURCES_DIRECTORY = "src/test/resources"; |
| 70 |
|
private static final String TEST_SOURCE_DIRECTORY = |
| 71 |
|
"src/test/java/org/kuali/student/contract/model/test/source"; |
| 72 |
|
private static final String ENROLL_PROJECT_SRC_MAIN = "C:/svn/ks-1.3/ks-enroll/ks-enroll-api/src/main"; |
| 73 |
|
private static final String ENROLL_PROJECT_JAVA_DIRECTORY = ENROLL_PROJECT_SRC_MAIN + "/java"; |
| 74 |
|
private static final String RICE_CORE_API_DIRECTORY = "C:/svn/rice/trunk/core/api/src/main/java"; |
| 75 |
|
private static final String RICE_KIM_API_DIRECTORY = "C:/svn/rice/trunk/kim/kim-api/src/main/java"; |
| 76 |
|
private static final String RICE_LOCATION_API_DIRECTORY = "C:/svn/rice/trunk/location/api/src/main/java"; |
| 77 |
|
private static final String RICE_KEW_API_DIRECTORY = "C:/svn/rice/trunk/kew/api/src/main/java"; |
| 78 |
|
private static final String RICE_KEN_API_DIRECTORY = "C:/svn/rice/trunk/ken/api/src/main/java"; |
| 79 |
|
private static final String RICE_KSB_API_DIRECTORY = "C:/svn/rice/trunk/ksb/api/src/main/java"; |
| 80 |
|
private static final String RICE_KRMS_API_DIRECTORY = "C:/svn/rice/trunk/krms/api/src/main/java"; |
| 81 |
|
private static ServiceContractModel model = null; |
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
| 82 |
0
|
private ServiceContractModel getModel() {... |
| 83 |
0
|
if (model != null) { |
| 84 |
0
|
return model; |
| 85 |
|
} |
| 86 |
0
|
List<String> srcDirs = new ArrayList(); |
| 87 |
0
|
System.out.println("User directory=" + System.getProperty("user.dir")); |
| 88 |
0
|
System.out.println("Current directory=" + new File(".").getAbsolutePath()); |
| 89 |
|
|
| 90 |
|
|
| 91 |
0
|
srcDirs.add(RICE_CORE_API_DIRECTORY); |
| 92 |
0
|
srcDirs.add(RICE_KIM_API_DIRECTORY); |
| 93 |
0
|
srcDirs.add(RICE_LOCATION_API_DIRECTORY); |
| 94 |
0
|
srcDirs.add(RICE_KEW_API_DIRECTORY); |
| 95 |
0
|
srcDirs.add(RICE_KEN_API_DIRECTORY); |
| 96 |
0
|
srcDirs.add(RICE_KSB_API_DIRECTORY); |
| 97 |
0
|
srcDirs.add(RICE_KRMS_API_DIRECTORY); |
| 98 |
0
|
boolean validateKualiStudent = false; |
| 99 |
0
|
ServiceContractModel instance = new ServiceContractModelQDoxLoader(srcDirs, validateKualiStudent); |
| 100 |
|
|
| 101 |
0
|
instance = new ServiceContractModelCache(instance); |
| 102 |
0
|
validate(instance); |
| 103 |
0
|
model = instance; |
| 104 |
0
|
return instance; |
| 105 |
|
} |
| 106 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
| 107 |
0
|
private String dump(ServiceMethod method) {... |
| 108 |
0
|
StringBuilder bldr = new StringBuilder(); |
| 109 |
0
|
bldr.append(method.getName()); |
| 110 |
0
|
String comma = ""; |
| 111 |
0
|
bldr.append("("); |
| 112 |
0
|
for (ServiceMethodParameter param : method.getParameters()) { |
| 113 |
0
|
bldr.append(comma); |
| 114 |
0
|
comma = ", "; |
| 115 |
0
|
bldr.append(param.getType()); |
| 116 |
0
|
bldr.append(" "); |
| 117 |
0
|
bldr.append(param.getName()); |
| 118 |
|
} |
| 119 |
0
|
bldr.append(")"); |
| 120 |
0
|
return bldr.toString(); |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 123 |
0
|
private void validate(ServiceContractModel model) {... |
| 124 |
0
|
Collection<String> errors = |
| 125 |
|
new ServiceContractModelValidator(model).validate(); |
| 126 |
0
|
if (errors.size() > 0) { |
| 127 |
0
|
StringBuilder buf = new StringBuilder(); |
| 128 |
0
|
buf.append(errors.size()).append(" errors found while validating the data."); |
| 129 |
0
|
int cnt = 0; |
| 130 |
0
|
for (String msg : errors) { |
| 131 |
0
|
cnt++; |
| 132 |
0
|
buf.append("\n"); |
| 133 |
0
|
buf.append("*error*").append(cnt).append(":").append(msg); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
0
|
fail(buf.toString()); |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
4
-
|
|
| 143 |
0
|
@Test... |
| 144 |
|
public void testGetServiceMethods() { |
| 145 |
0
|
System.out.println("getServiceMethods"); |
| 146 |
0
|
ServiceContractModel model = getModel(); |
| 147 |
0
|
List<ServiceMethod> result = model.getServiceMethods(); |
| 148 |
0
|
System.out.println("Number of methods=" + result.size()); |
| 149 |
0
|
for (ServiceMethod method : result) { |
| 150 |
0
|
System.out.println(dump(method)); |
| 151 |
|
} |
| 152 |
0
|
if (result.size() < 10) { |
| 153 |
0
|
fail("too few: " + result.size()); |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
| 161 |
0
|
public void testGetSourceNames() {... |
| 162 |
0
|
System.out.println("getSourceNames"); |
| 163 |
0
|
ServiceContractModel model = getModel(); |
| 164 |
0
|
List<String> expResult = new ArrayList(); |
| 165 |
0
|
expResult.add(TEST_SOURCE_DIRECTORY); |
| 166 |
0
|
List result = model.getSourceNames(); |
| 167 |
0
|
assertEquals(expResult, result); |
| 168 |
|
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
4
-
|
|
| 174 |
0
|
public void testGetServices() {... |
| 175 |
0
|
System.out.println("getServices"); |
| 176 |
0
|
ServiceContractModel model = getModel(); |
| 177 |
0
|
List<Service> result = model.getServices(); |
| 178 |
0
|
for (Service service : result) { |
| 179 |
0
|
System.out.println(service.getKey() + " " + service.getName() + " " |
| 180 |
|
+ service.getVersion() + " " + service.getStatus()); |
| 181 |
|
} |
| 182 |
0
|
assertEquals(4, result.size()); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
4
-
|
|
| 189 |
0
|
public void testGetXmlTypes() {... |
| 190 |
0
|
System.out.println("getXmlTypes"); |
| 191 |
0
|
ServiceContractModel model = getModel(); |
| 192 |
0
|
List<XmlType> result = model.getXmlTypes(); |
| 193 |
0
|
for (XmlType xmlType : result) { |
| 194 |
0
|
System.out.println("XmlType=" + xmlType.getName() + " " |
| 195 |
|
+ xmlType.getPrimitive()); |
| 196 |
|
} |
| 197 |
0
|
if (result.size() < 10) { |
| 198 |
0
|
fail("too few: " + result.size()); |
| 199 |
|
} |
| 200 |
|
} |
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 3 |
Complexity Density: 0.16 |
4
-
|
|
| 206 |
0
|
public void testGetMessageStructures() throws FileNotFoundException {... |
| 207 |
0
|
System.out.println("getMessageStructures"); |
| 208 |
0
|
ServiceContractModel model = getModel(); |
| 209 |
0
|
List<MessageStructure> result = model.getMessageStructures(); |
| 210 |
0
|
for (MessageStructure ms : result) { |
| 211 |
0
|
if (ms.getId().equalsIgnoreCase("academicCalendarInfo.typeKey")) { |
| 212 |
0
|
System.out.println("MessageStructure=" + ms.getId() + " " + ms.getType() + "required=["+ ms.getRequired() + "]"); |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
0
|
if (result.size() < 10) { |
| 216 |
0
|
fail("too few: " + result.size()); |
| 217 |
|
} |
| 218 |
0
|
String outputFileName = "target/messageStructures.txt"; |
| 219 |
0
|
File file = new File(outputFileName); |
| 220 |
0
|
PrintStream out = new PrintStream(file); |
| 221 |
0
|
new MessageStructureHierarchyDumper(out, model).writeTabbedHeader(); |
| 222 |
0
|
Set<XmlType> rootTypes = HtmlContractServiceWriter.calcMainMessageStructures( |
| 223 |
|
model, null); |
| 224 |
0
|
ModelFinder finder = new ModelFinder(model); |
| 225 |
0
|
for (XmlType rootType : rootTypes) { |
| 226 |
0
|
Stack<String> stack = new Stack(); |
| 227 |
0
|
stack.push(rootType.getName()); |
| 228 |
0
|
for (MessageStructure ms : finder.findMessageStructures(rootType.getName())) { |
| 229 |
0
|
new MessageStructureHierarchyDumper(out, model).writeTabbedData(ms, stack); |
| 230 |
|
} |
| 231 |
|
} |
| 232 |
|
} |
| 233 |
|
} |