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;
}
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 + "()");
}
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");
}
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());
}
Aggregations