Search in sources :

Example 56 with JoinPoint

use of org.aspectj.lang.JoinPoint in project sakuli by ConSol.

the class ModifySahiTimerAspect method determineDelay.

protected Integer determineDelay(JoinPoint joinPoint, BaseActionLoader loader) {
    Integer deleay = loader.getSahiProxyProperties().getRequestDelayMs();
    if (joinPoint.getSignature().getName().startsWith("type")) {
        Object[] args = joinPoint.getArgs();
        if (args != null && args.length > 0) {
            Object text = args[0];
            if (text instanceof String) {
                int length = ((String) text).length();
                int typeDelayMs = loader.getActionProperties().getTypeDelayMs();
                return length * (typeDelayMs + deleay);
            }
        }
    }
    return deleay;
}
Also used : JoinPoint(org.aspectj.lang.JoinPoint)

Example 57 with JoinPoint

use of org.aspectj.lang.JoinPoint 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)

Example 58 with JoinPoint

use of org.aspectj.lang.JoinPoint in project sakuli by ConSol.

the class RhinoAspectTest method testCreateLoggingString.

@Test
public void testCreateLoggingString() throws Exception {
    JoinPoint jp = mock(JoinPoint.class);
    when(jp.getArgs()).thenReturn(new Object[] { "TEST", "arguments" });
    LogToResult annotation = mock(LogToResult.class);
    when(annotation.logArgsOnly()).thenReturn(true);
    when(annotation.logArgs()).thenReturn(true);
    StringBuilder result = BeanLoader.loadBean(RhinoAspect.class).createLoggingString(jp, annotation);
    assertEquals(result.toString(), "TEST, arguments");
}
Also used : LogToResult(org.sakuli.actions.logging.LogToResult) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 59 with JoinPoint

use of org.aspectj.lang.JoinPoint in project weixin-java-mp-multi-demo by binarywang.

the class ControllerLogAspect method writeParams.

@Before("controller()")
public void writeParams(JoinPoint jp) {
    String[] names = ((CodeSignature) jp.getSignature()).getParameterNames();
    Object[] args = jp.getArgs();
    if (ArrayUtils.isEmpty(names)) {
        return;
    }
    StringBuilder sb = new StringBuilder("Arguments: ");
    for (int i = 0; i < names.length; i++) {
        sb.append(names[i] + " = " + args[i] + ",");
    }
    debugInController(jp, sb.toString());
}
Also used : CodeSignature(org.aspectj.lang.reflect.CodeSignature) JoinPoint(org.aspectj.lang.JoinPoint) Before(org.aspectj.lang.annotation.Before)

Aggregations

JoinPoint (org.aspectj.lang.JoinPoint)59 MethodSignature (org.aspectj.lang.reflect.MethodSignature)31 Method (java.lang.reflect.Method)30 Test (org.junit.Test)29 AccessDeniedException (org.springframework.security.access.AccessDeniedException)26 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)25 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)25 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)21 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)14 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)11 Before (org.aspectj.lang.annotation.Before)5 CodeSignature (org.aspectj.lang.reflect.CodeSignature)4 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 IView (com.yydcdut.note.views.IView)2 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2