Search in sources :

Example 41 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class TestCaseStepHelperTest method testWriteCachedStepsError.

@Test
public void testWriteCachedStepsError() throws Throwable {
    Path tcFile = getResource("stephelper/tc.js");
    TestSuite testSuite = mock(TestSuite.class);
    TestCase tc = mock(TestCase.class);
    when(tc.getTcFile()).thenReturn(tcFile);
    when(tc.getSteps()).thenReturn(Arrays.asList(new TestCaseStepBuilder("step_warning").withState(TestCaseStepState.WARNING).build(), new TestCaseStepBuilder("step_ok").withState(TestCaseStepState.OK).build(), new TestCaseStepBuilder("step_not_started_1").build(), new TestCaseStepBuilder("step_not_started_2").build()));
    when(testSuite.getTestCases()).thenReturn(Collections.singletonMap("1", tc));
    TestCaseStepHelper.writeCachedStepDefinitions(testSuite);
    Path cacheFile = getResource(CACHEFILE_NAME);
    assertTrue(Files.exists(cacheFile));
    assertEquals(FileUtils.readFileToString(cacheFile.toFile(), Charset.forName("UTF-8")), "step_warning\nstep_ok\nstep_not_started_1\nstep_not_started_2\n");
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 42 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testSaveExceptionsInStep.

@Test
public void testSaveExceptionsInStep() throws Exception {
    TestSuite ts = new TestSuite();
    when(loader.getTestSuite()).thenReturn(ts);
    TestCase tc = new TestCase(null, null);
    when(loader.getCurrentTestCase()).thenReturn(tc);
    TestCaseStep step = new TestCaseStep();
    when(loader.getCurrentTestCaseStep()).thenReturn(step);
    testling.saveException(new SakuliException("test"));
    assertNull(ts.getException());
    assertNull(tc.getException());
    assertEquals(step.getException().getMessage(), "test");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 43 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testGetAllExceptions.

@Test
public void testGetAllExceptions() throws Exception {
    TestSuite ts = new TestSuite();
    ts.addException(new SakuliException("bla"));
    TestCase tc = new TestCase(null, null);
    tc.addException(new SakuliException("bla2"));
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    step.addException(new SakuliException("bla3"));
    tc.addStep(step);
    List<Throwable> allExceptions = SakuliExceptionHandler.getAllExceptions(ts);
    assertEquals(allExceptions.size(), 3);
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 44 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method testContainsExceptionsCase.

@Test
public void testContainsExceptionsCase() throws Exception {
    TestSuite ts = new TestSuite();
    TestCase tc = new TestCase(null, null);
    tc.addException(new SakuliException("bla2"));
    ts.addTestCase(tc);
    TestCaseStep step = new TestCaseStep();
    tc.addStep(step);
    assertTrue(SakuliExceptionHandler.containsException(ts));
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 45 with TestCase

use of org.sakuli.datamodel.TestCase in project sakuli by ConSol.

the class SakuliExceptionHandlerTest method setUp.

private void setUp() throws Exception {
    expectedScreenshotPath = Paths.get(screenShotFolder + "test.jpg");
    when(screenshotActionsMock.takeScreenshot(anyString(), any(Path.class))).thenReturn(expectedScreenshotPath);
    when(loader.getScreenshotActions()).thenReturn(screenshotActionsMock);
    testCase = new TestCase("testling", "1234_");
    HashMap<String, TestCase> testCases = new HashMap<>();
    testCases.put(testCase.getId(), testCase);
    testSuite = new TestSuite();
    testSuite.setState(TestSuiteState.RUNNING);
    ReflectionTestUtils.setField(testSuite, "testCases", testCases);
    when(loader.getActionProperties()).thenReturn(actionProperties);
    when(actionProperties.isTakeScreenshots()).thenReturn(true);
    when(loader.getSakuliProperties()).thenReturn(sakuliProperties);
    when(sakuliProperties.isSuppressResumedExceptions()).thenReturn(false);
    when(loader.getSahiReport()).thenReturn(sahiReport);
    when(loader.getTestSuite()).thenReturn(testSuite);
    when(loader.getCurrentTestCase()).thenReturn(testCase);
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

TestCase (org.sakuli.datamodel.TestCase)49 Test (org.testng.annotations.Test)33 BaseTest (org.sakuli.BaseTest)20 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)14 Path (java.nio.file.Path)13 TestSuite (org.sakuli.datamodel.TestSuite)13 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)11 DateTime (org.joda.time.DateTime)8 TestCaseStep (org.sakuli.datamodel.TestCaseStep)8 TreeSet (java.util.TreeSet)7 IOException (java.io.IOException)5 Date (java.util.Date)5 SakuliException (org.sakuli.exceptions.SakuliException)5 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)5 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)4 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)3 DaoTestCase (org.sakuli.services.forwarder.database.dao.DaoTestCase)2 DaoTestCaseStep (org.sakuli.services.forwarder.database.dao.DaoTestCaseStep)2 SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)2 File (java.io.File)1