1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.test;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.log4j.Logger;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Ignore;
26 import org.junit.Rule;
27 import org.junit.rules.TestName;
28 import org.kuali.rice.test.TransactionalLifecycle;
29 @Ignore
30 public class TestHarnessBase extends Assert {
31
32
33 private static final Logger LOG = Logger.getLogger(TestHarnessBase.class);
34 protected List<String> reports = new ArrayList<String>();
35 @Rule public TestName testName = new TestName();
36 protected TransactionalLifecycle transactionalLifecycle;
37
38 @Before
39 public void setUp() throws Exception {
40 logBeforeRun();
41 transactionalLifecycle = new TransactionalLifecycle();
42 transactionalLifecycle.start();
43 }
44
45 @After
46 public void tearDown() throws Exception {
47 logAfterRun();
48 try {
49 if (transactionalLifecycle != null) {
50 transactionalLifecycle.stop();
51 }
52 } finally {
53 transactionalLifecycle = null;
54 }
55 }
56
57 protected void logBeforeRun() {
58 LOG.info("##############################################################");
59 LOG.info("# Starting test " + getFullTestName() + "...");
60 LOG.info("# " + dumpMemory());
61 LOG.info("##############################################################");
62 }
63
64 protected void logAfterRun() {
65 LOG.info("##############################################################");
66 LOG.info("# ...finished test " + getFullTestName());
67 LOG.info("# " + dumpMemory());
68 for (final String report : this.reports) {
69 LOG.info("# " + report);
70 }
71 LOG.info("##############################################################\n\n\n");
72 }
73
74 protected void report(final String report) {
75 this.reports.add(report);
76 }
77
78 protected String getFullTestName() {
79 return getClass().getSimpleName() + "." + getTestName();
80 }
81
82 public String getTestName() {
83 return (testName != null ? testName.getMethodName() : "null");
84 }
85
86 protected String dumpMemory() {
87 final long total = Runtime.getRuntime().totalMemory();
88 final long free = Runtime.getRuntime().freeMemory();
89 final long max = Runtime.getRuntime().maxMemory();
90 return "[Memory] max: " + max + ", total: " + total + ", free: " + free;
91 }
92
93 }