use of org.aspectj.lang.Signature in project onebusaway-application-modules by camsys.
the class CacheableMethodKeyFactoryManager method getMatchingMethodsForJoinPoint.
public List<Method> getMatchingMethodsForJoinPoint(ProceedingJoinPoint pjp) {
Signature sig = pjp.getSignature();
Object target = pjp.getTarget();
Class<?> type = target.getClass();
List<Method> matches = new ArrayList<Method>();
for (Method m : type.getDeclaredMethods()) {
if (!m.getName().equals(sig.getName()))
continue;
// if (m.getModifiers() != sig.getModifiers())
// continue;
Object[] args = pjp.getArgs();
Class<?>[] types = m.getParameterTypes();
if (args.length != types.length)
continue;
boolean miss = false;
for (int i = 0; i < args.length; i++) {
Object arg = args[i];
Class<?> argType = types[i];
if (argType.isPrimitive()) {
if (argType.equals(Double.TYPE) && !arg.getClass().equals(Double.class))
miss = true;
} else {
if (arg != null && !argType.isInstance(arg))
miss = true;
}
}
if (miss)
continue;
matches.add(m);
}
return matches;
}
use of org.aspectj.lang.Signature in project onebusaway-application-modules by camsys.
the class CacheableMethodManager method getCacheName.
protected String getCacheName(ProceedingJoinPoint pjp) {
Signature sig = pjp.getSignature();
StringBuilder b = new StringBuilder();
if (_cacheNamePrefix != null)
b.append(_cacheNamePrefix).append("-");
b.append(sig.getDeclaringTypeName()).append('.').append(sig.getName());
return b.toString();
}
use of org.aspectj.lang.Signature in project sakuli by ConSol.
the class RhinoAspectTest method testAddActionLog.
@Test(dataProvider = "logLevel")
public void testAddActionLog(LogLevel logLevel) throws Exception {
initMocks();
Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport();
final int lisSize = sahiReport.getListResult().size();
final String classContent = "Test-Action-Content";
final String className = TestCaseAction.class.getSimpleName();
final String methodName = "actionMethod";
final String sampleMessage = "sample-message-for-log";
final String arg1 = "ARG1";
final String arg2 = "NULL";
TestCaseAction testAction = mock(TestCaseAction.class);
when(testAction.toString()).thenReturn(classContent);
JoinPoint jp = mock(JoinPoint.class);
when(jp.getTarget()).thenReturn(testAction);
Signature signature = mock(Signature.class);
when(jp.getSignature()).thenReturn(signature);
when(signature.getDeclaringType()).thenReturn(TestCaseAction.class);
when(signature.getName()).thenReturn(methodName);
when(signature.getDeclaringTypeName()).thenReturn(TestCaseAction.class.getName());
when(jp.getArgs()).thenReturn(new Object[] { arg1, null });
LogToResult logToResult = mock(LogToResult.class);
when(logToResult.logClassInstance()).thenReturn(true);
when(logToResult.message()).thenReturn(sampleMessage);
when(logToResult.logArgs()).thenReturn(true);
when(logToResult.level()).thenReturn(logLevel);
RhinoAspect testling = BeanLoader.loadBean(RhinoAspect.class);
testling.addActionLog(jp, logToResult);
assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [" + arg1 + ", " + arg2 + "]");
verifySahiReport(logLevel.getResultType(), lisSize);
// hide args
when(logToResult.logArgs()).thenReturn(false);
testling.addActionLog(jp, logToResult);
assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
// without class values
when(logToResult.logClassInstance()).thenReturn(false);
testling.addActionLog(jp, logToResult);
assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
// without args
when(jp.getArgs()).thenReturn(null);
testling.addActionLog(jp, logToResult);
assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage);
// without message
when(logToResult.message()).thenReturn(null);
testling.addActionLog(jp, logToResult);
assertLastLine(logFile, className, logLevel, className + "." + methodName + "()");
}
Aggregations