Search in sources :

Example 26 with Signature

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;
}
Also used : Signature(org.aspectj.lang.Signature) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 27 with Signature

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();
}
Also used : Signature(org.aspectj.lang.Signature)

Example 28 with Signature

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 + "()");
}
Also used : LogToResult(org.sakuli.actions.logging.LogToResult) Report(net.sf.sahi.report.Report) TestCaseAction(org.sakuli.actions.TestCaseAction) Signature(org.aspectj.lang.Signature) JoinPoint(org.aspectj.lang.JoinPoint) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Aggregations

Signature (org.aspectj.lang.Signature)28 MethodSignature (org.aspectj.lang.reflect.MethodSignature)17 Method (java.lang.reflect.Method)12 Around (org.aspectj.lang.annotation.Around)6 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)4 JoinPoint (org.aspectj.lang.JoinPoint)3 CodeSignature (org.aspectj.lang.reflect.CodeSignature)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Test (org.testng.annotations.Test)2 DataSource (com.ikoori.vip.common.annotion.DataSource)1 BussinessLog (com.ikoori.vip.common.annotion.log.BussinessLog)1 AbstractDictMap (com.ikoori.vip.common.constant.dictmap.base.AbstractDictMap)1 ShiroUser (com.ikoori.vip.server.core.shiro.ShiroUser)1 RequestLockable (com.jim.framework.annotationlock.annotation.RequestLockable)1 DynamicDataSource (com.junliang.spring.config.DynamicDataSource)1 User (gemma.gsec.model.User)1 AnnotationFormatError (java.lang.annotation.AnnotationFormatError)1 Executable (java.lang.reflect.Executable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1