| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.kuali.rice.test; |
| 17 |
|
|
| 18 |
|
import java.lang.annotation.Annotation; |
| 19 |
|
import java.lang.reflect.Method; |
| 20 |
|
import java.util.ArrayList; |
| 21 |
|
import java.util.List; |
| 22 |
|
import java.util.Map; |
| 23 |
|
import java.util.Set; |
| 24 |
|
|
| 25 |
|
import junit.framework.Assert; |
| 26 |
|
|
| 27 |
|
import org.kuali.rice.core.api.config.property.Config; |
| 28 |
|
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 29 |
|
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 30 |
|
import org.kuali.rice.core.api.resourceloader.ResourceLoader; |
| 31 |
|
import org.mortbay.jetty.webapp.WebAppClassLoader; |
| 32 |
|
|
|
|
|
| 0% |
Uncovered Elements: 87 (87) |
Complexity: 23 |
Complexity Density: 0.43 |
|
| 33 |
|
public class TestUtilities { |
| 34 |
|
|
| 35 |
|
private static Thread exceptionThreader; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 45 |
0
|
public static void waitForExceptionRouting() {... |
| 46 |
0
|
waitForExceptionRouting(5*60*1000); |
| 47 |
|
} |
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 49 |
0
|
public static void waitForExceptionRouting(long milliseconds) {... |
| 50 |
0
|
try { |
| 51 |
0
|
Thread thread = getExceptionThreader(); |
| 52 |
0
|
if (thread == null) { |
| 53 |
0
|
throw new IllegalStateException("No exception thread was established, likely message is not being processed for exception routing."); |
| 54 |
|
} |
| 55 |
0
|
thread.join(milliseconds); |
| 56 |
|
} catch (InterruptedException e) { |
| 57 |
0
|
Assert.fail("This thread was interuppted while waiting for exception routing."); |
| 58 |
|
} |
| 59 |
0
|
if (getExceptionThreader().isAlive()) { |
| 60 |
0
|
Assert.fail("Document was not put into exception routing within the specified amount of time " + milliseconds); |
| 61 |
|
} |
| 62 |
|
} |
| 63 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
0
|
public static Thread getExceptionThreader() {... |
| 65 |
0
|
return exceptionThreader; |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
0
|
public static void setExceptionThreader(Thread exceptionThreader) {... |
| 69 |
0
|
TestUtilities.exceptionThreader = exceptionThreader; |
| 70 |
|
} |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 72 |
0
|
protected List<Class> annotationsPresent(Class clazz, Class[] annotationClasses) {... |
| 73 |
0
|
List<Class> annotationsPresent = new ArrayList<Class>(); |
| 74 |
0
|
for (Class c: annotationClasses) { |
| 75 |
0
|
if (clazz.isAnnotationPresent(c)) { |
| 76 |
0
|
annotationsPresent.add(c); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
0
|
return annotationsPresent; |
| 80 |
|
} |
| 81 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 82 |
0
|
protected static boolean contains(Class[] list, Class target) {... |
| 83 |
0
|
for (Class c: list) { |
| 84 |
0
|
if (c.getName().equals(target.getName())) { |
| 85 |
0
|
return true; |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
0
|
return false; |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
@throws |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 111 |
0
|
public static List<Class> getHierarchyClassesToHandle(Class testClass, Class[] annotationClasses, Set<String> classesHandled) throws Exception {... |
| 112 |
0
|
List<Class> classesThatNeedHandling = new ArrayList<Class>(); |
| 113 |
|
|
| 114 |
0
|
List<Class> classesToCheck = new ArrayList<Class>(); |
| 115 |
|
|
| 116 |
|
{ |
| 117 |
0
|
Class clazz = testClass; |
| 118 |
0
|
superClassLoop: while (!clazz.getName().equals(Object.class.getName())) { |
| 119 |
0
|
for (Annotation annotation : clazz.getDeclaredAnnotations()) { |
| 120 |
|
|
| 121 |
0
|
if (!contains(annotationClasses, annotation.annotationType())) { |
| 122 |
0
|
continue; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
0
|
classesToCheck.add(0, clazz); |
| 127 |
|
|
| 128 |
|
|
| 129 |
0
|
if (annotationOverridesSuperClass(annotation)) { |
| 130 |
|
|
| 131 |
0
|
break superClassLoop; |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
|
| 135 |
0
|
break; |
| 136 |
|
} |
| 137 |
0
|
clazz = clazz.getSuperclass(); |
| 138 |
|
} |
| 139 |
|
} |
| 140 |
|
|
| 141 |
0
|
for (Class clazz: classesToCheck) { |
| 142 |
0
|
if (!classesHandled.contains(clazz.getName())) { |
| 143 |
0
|
classesThatNeedHandling.add(clazz); |
| 144 |
|
} |
| 145 |
|
} |
| 146 |
0
|
return classesThatNeedHandling; |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
|
@param |
| 154 |
|
@return |
| 155 |
|
@throws |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 157 |
0
|
protected static boolean annotationOverridesSuperClass(Annotation annotation) throws Exception {... |
| 158 |
0
|
boolean overrides = true; |
| 159 |
0
|
Method m = null;; |
| 160 |
0
|
try { |
| 161 |
0
|
m = annotation.getClass().getMethod("overrideSuperClasses", null); |
| 162 |
|
} catch (NoSuchMethodException nsme) { |
| 163 |
|
|
| 164 |
|
} |
| 165 |
0
|
if (m != null) { |
| 166 |
0
|
Object result = m.invoke(annotation, (Object[]) null); |
| 167 |
0
|
if (result instanceof Boolean) { |
| 168 |
0
|
overrides = (Boolean) result; |
| 169 |
|
} else { |
| 170 |
0
|
throw new RuntimeException("Annotation 'overrideSuperClasses' did not return Boolean value"); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
0
|
return overrides; |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 180 |
0
|
public static void addWebappsToContext() {... |
| 181 |
0
|
for (Map.Entry<ClassLoader, Config> configEntry : ConfigContext.getConfigs()) { |
| 182 |
0
|
if (configEntry.getKey() instanceof WebAppClassLoader) { |
| 183 |
0
|
ResourceLoader rl = GlobalResourceLoader.getResourceLoader(configEntry.getKey()); |
| 184 |
0
|
if (rl == null) { |
| 185 |
0
|
Assert.fail("didn't find resource loader for workflow test harness web app"); |
| 186 |
|
} |
| 187 |
0
|
GlobalResourceLoader.addResourceLoader(rl); |
| 188 |
0
|
ConfigContext.overrideConfig(Thread.currentThread().getContextClassLoader(), configEntry.getValue()); |
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
} |
| 192 |
|
} |