Search in sources :

Example 1 with TestCaseAction

use of org.sakuli.actions.TestCaseAction in project sakuli by ConSol.

the class RhinoAspectTest method testDoTestCaseActionLog.

@Test
public void testDoTestCaseActionLog() throws Exception {
    initMocks();
    BaseActionLoader loader = mock(BaseActionLoader.class);
    TestCase sampleTc = new TestCase("test", "testID");
    when(loader.getCurrentTestCase()).thenReturn(sampleTc);
    TestCaseAction testAction = new TestCaseAction();
    ReflectionTestUtils.setField(testAction, "loader", loader, BaseActionLoader.class);
    testAction.init("testID", 3, 4, "imagefolder1", "imagefolder2");
    assertLastLine(logFile, testAction.getClass().getSimpleName(), LogLevel.INFO, "\"test case [" + sampleTc.getActionValueString() + "]\" TestCaseAction.init() - init a new test case with arg(s) [testID, 3, 4, [imagefolder1, imagefolder2]]");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TestCaseAction(org.sakuli.actions.TestCaseAction) BaseActionLoader(org.sakuli.loader.BaseActionLoader) Test(org.testng.annotations.Test)

Example 2 with TestCaseAction

use of org.sakuli.actions.TestCaseAction 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

TestCaseAction (org.sakuli.actions.TestCaseAction)2 Test (org.testng.annotations.Test)2 Report (net.sf.sahi.report.Report)1 JoinPoint (org.aspectj.lang.JoinPoint)1 Signature (org.aspectj.lang.Signature)1 LogToResult (org.sakuli.actions.logging.LogToResult)1 TestCase (org.sakuli.datamodel.TestCase)1 BaseActionLoader (org.sakuli.loader.BaseActionLoader)1