| 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.ElementType; |
| 19 |
|
import java.lang.annotation.Inherited; |
| 20 |
|
import java.lang.annotation.Retention; |
| 21 |
|
import java.lang.annotation.RetentionPolicy; |
| 22 |
|
import java.lang.annotation.Target; |
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
import org.kuali.rice.core.api.lifecycle.Lifecycle; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@link |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@link |
| 48 |
|
|
| 49 |
|
@author |
| 50 |
|
|
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 54 (54) |
Complexity: 18 |
Complexity Density: 0.51 |
|
| 52 |
|
public class BaselineTestCase extends BaseModuleTestCase { |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 56 |
|
public static enum Mode { |
| 57 |
|
CLEAR_DB, ROLLBACK, NONE |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
@Target({ElementType.TYPE}) |
| 61 |
|
@Inherited |
| 62 |
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 63 |
|
public @interface BaselineMode { |
| 64 |
|
Mode value(); |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
private Mode mode = Mode.NONE; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
@link |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
protected static boolean dirty = false; |
| 76 |
|
|
| 77 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 78 |
0
|
public BaselineTestCase(String moduleName) {... |
| 79 |
0
|
super(moduleName); |
| 80 |
0
|
readModeAnnotation(); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 86 |
0
|
public BaselineTestCase(String moduleName, Mode mode) {... |
| 87 |
0
|
super(moduleName); |
| 88 |
0
|
if (mode == null) throw new IllegalArgumentException("Mode cannot be null"); |
| 89 |
0
|
this.mode = mode; |
| 90 |
|
} |
| 91 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 92 |
0
|
private void readModeAnnotation() {... |
| 93 |
0
|
BaselineMode m = this.getClass().getAnnotation(BaselineMode.class); |
| 94 |
0
|
if (m != null) { |
| 95 |
0
|
if (m.value() != null) { |
| 96 |
0
|
mode = m.value(); |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
@return |
| 103 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
0
|
protected Mode getMode() {... |
| 105 |
0
|
return mode; |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@see |
| 111 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 112 |
0
|
@Override... |
| 113 |
|
public void setUp() throws Exception { |
| 114 |
0
|
super.setUp(); |
| 115 |
0
|
dirty = true; |
| 116 |
|
} |
| 117 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 118 |
0
|
@Override... |
| 119 |
|
protected List<Lifecycle> getPerTestLifecycles() { |
| 120 |
0
|
switch (mode) { |
| 121 |
0
|
case ROLLBACK: return getRollbackPerTestLifecycles(); |
| 122 |
0
|
case CLEAR_DB: return getClearDbPerTestLifecycles(); |
| 123 |
0
|
case NONE: return super.getPerTestLifecycles(); |
| 124 |
0
|
default: |
| 125 |
0
|
throw new RuntimeException("Invalid mode specified: " + mode); |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
|
@return |
| 131 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 132 |
0
|
protected List<Lifecycle> getClearDbPerTestLifecycles() {... |
| 133 |
0
|
List<Lifecycle> lifecycles = super.getPerTestLifecycles(); |
| 134 |
0
|
lifecycles.add(0, new ClearDatabaseLifecycle(getPerTestTablesToClear(), getPerTestTablesNotToClear())); |
| 135 |
0
|
return lifecycles; |
| 136 |
|
} |
| 137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 138 |
0
|
protected List<String> getPerTestTablesToClear() {... |
| 139 |
0
|
return new ArrayList<String>(); |
| 140 |
|
} |
| 141 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 142 |
0
|
protected List<String> getPerTestTablesNotToClear() {... |
| 143 |
0
|
return new ArrayList<String>(); |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
|
| 147 |
|
@return |
| 148 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 149 |
0
|
protected List<Lifecycle> getRollbackPerTestLifecycles() {... |
| 150 |
0
|
List<Lifecycle> lifecycles = super.getPerTestLifecycles(); |
| 151 |
0
|
lifecycles.add(0, new TransactionalLifecycle() { |
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 152 |
0
|
@Override... |
| 153 |
|
public void stop() throws Exception { |
| 154 |
0
|
super.stop(); |
| 155 |
0
|
dirty = false; |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
}); |
| 159 |
|
|
| 160 |
|
|
| 161 |
0
|
if (dirty) { |
| 162 |
0
|
log.warn("Previous test case did not clean up the database; clearing database..."); |
| 163 |
0
|
lifecycles.add(0, new ClearDatabaseLifecycle(getPerTestTablesToClear(), getPerTestTablesNotToClear())); |
| 164 |
|
} |
| 165 |
0
|
return lifecycles; |
| 166 |
|
} |
| 167 |
|
} |