1 29 package net.sourceforge.groboutils.autodoc.v1.testserver; 30 31 32 import net.sourceforge.groboutils.util.throwable.v1.ThrowableParser; 33 import net.sourceforge.groboutils.util.throwable.v1.StackTraceLineParser; 34 35 import org.apache.log4j.Logger; 36 37 38 45 public abstract class TestCorrelate 46 { 47 private static final Logger LOG = Logger.getLogger( TestCorrelate.class ); 48 49 private MonitorFinder finder; 50 private Class owner; 51 52 53 public TestCorrelate( Class owner, MonitorFinder finder ) 54 { 55 if (finder == null) 56 { 57 throw new IllegalArgumentException ("no null arguments"); 58 } 59 this.owner = owner; 60 this.finder = finder; 61 } 62 63 64 65 70 protected String findClassMethodFromStack() 71 { 72 Throwable t = new Throwable (); 73 t.fillInStackTrace(); 74 75 ThrowableParser tp = new ThrowableParser( t ); 76 for (StackTraceLineParser stlp = tp.next(); stlp != null; 77 stlp = tp.next() ) 78 { 79 if (stlp.getClassName().equals( getOwnerName() )) 80 { 81 String methodName = stlp.getMethodName(); 82 LOG.debug( "Owning method for stack trace is '"+methodName+ 83 "'", t ); 84 return methodName; 85 } 86 } 87 88 return null; 90 } 91 92 93 97 protected TestInfo createTestInfoFromStack() 98 { 99 return new DefaultTestInfo( getOwnerName(), 100 findClassMethodFromStack() ); 101 } 102 103 104 108 protected TestInfo createTestInfo( String methodName ) 109 { 110 return new DefaultTestInfo( getOwnerName(), methodName ); 111 } 112 113 114 protected MonitorFinder getFinder() 115 { 116 return this.finder; 117 } 118 119 120 125 protected TestData getTestData( TestInfo info ) 126 { 127 try 129 { 130 return getFinder().getMonitor().getTestData( info ); 131 } 132 catch (IllegalArgumentException iae) 133 { 134 LOG.warn( "Test "+info+" caused error w/ monitor", iae ); 135 } 136 catch (IllegalStateException ise) 137 { 138 LOG.warn( "Test "+info+" caused error w/ monitor", ise ); 139 } 140 return null; 141 } 142 143 144 protected Class getOwner() 145 { 146 return this.owner; 147 } 148 149 150 protected String getOwnerName() 151 { 152 Class c = getOwner(); 153 String res; 154 if (c == null) 155 { 156 res = null; 157 } 158 else 159 { 160 res = c.getName(); 161 } 162 return res; 163 } 164 } 165 166 | Popular Tags |