Search in sources :

Example 1 with TestCase

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

the class TestSuiteBuilder method createEmptyTestSuite.

public static TestSuite createEmptyTestSuite() {
    TestSuite newTestSuite = new TestSuite();
    newTestSuite.setName("Integration Test Sample Test Suite");
    newTestSuite.setId("IntegrationTest_" + System.nanoTime());
    newTestSuite.setStartDate(new Date());
    newTestSuite.setWarningTime(0);
    newTestSuite.setCriticalTime(0);
    newTestSuite.setState(TestSuiteState.RUNNING);
    newTestSuite.setBrowserInfo("Firefox Test Browser");
    TestCase testCase = TestCaseBuilder.createEmptyTestCase();
    newTestSuite.addTestCase(testCase.getId(), testCase);
    return newTestSuite;
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCase(org.sakuli.datamodel.TestCase) Date(java.util.Date)

Example 2 with TestCase

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

the class TestCaseBuilder method createEmptyTestCase.

public static TestCase createEmptyTestCase(String name, String id) {
    TestCase newTestCase = new TestCase(name, id);
    newTestCase.setState(TestCaseState.OK);
    newTestCase.setStartDate(new Date());
    newTestCase.setStopDate(new Date());
    return newTestCase;
}
Also used : TestCase(org.sakuli.datamodel.TestCase) Date(java.util.Date)

Example 3 with TestCase

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

the class CheckMKTemplateOutputBuilderTest method testWarnInSuite.

@Test
public void testWarnInSuite() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.WARNING_IN_SUITE).when(testSuite).getState();
    doReturn(3).when(testSuite).getWarningTime();
    doReturn(400).when(testSuite).getCriticalTime();
    doReturn(46.94f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 32, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 32, 46, 940).toDate()).when(testSuite).getStopDate();
    SortedSet<TestCase> testCaseAsSortedSet = new TreeSet<>(Arrays.asList(new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 14, 130).toDate()).withId("case1").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 1, 210).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 7, 410).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 1, 430).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 32, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 23, 580).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 1, 60).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 7, 80).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 32, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 32, 1, 360).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestSuiteState.WARNING_IN_SUITE.name()));
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TreeSet(java.util.TreeSet) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 4 with TestCase

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

the class CheckMKTemplateOutputBuilderTest method testException.

@Test
public void testException() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.ERRORS).when(testSuite).getState();
    doReturn(300).when(testSuite).getWarningTime();
    doReturn(400).when(testSuite).getCriticalTime();
    doReturn(44.80f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 36, 44, 800).toDate()).when(testSuite).getStopDate();
    when(testSuite.getExceptionMessages(anyBoolean())).thenCallRealMethod();
    when(testSuite.getException()).thenCallRealMethod();
    SortedSet<TestCase> testCaseAsSortedSet = new TreeSet<>(Arrays.asList(new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 14, 200).toDate()).withId("case1").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Test_Sahi_landing_page").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 140).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 7, 540).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 470).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.ERRORS).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 23, 550).toDate()).withId("case2").withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withName("Test_Sahi_landing_page_(case2)").withWarningTime(5).withStartDate(new DateTime(1970, 1, 1, 10, 36, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 1, 50).toDate()).withException(new SakuliException("_highlight(_link(\"xSL Manager\")); TypeError: el is undefined Sahi.prototype._highlight@http://sahi.example.com/_s_/spr/concat.js:1210:9 @http://sahi.example.com/_s_/spr/concat.js line 3607 > eval:1:1 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/concat.js:3607:9 Sahi.prototype.ex@http://sahi.example.com/_s_/spr/sakuli/inject.js:46:12 @http://sahi.example.com/_s_/spr/concat.js:3373:5  <a href='/_s_/dyn/Log_getBrowserScript?href=/root/sakuli/example_test_suites/example_xfce/case2/sakuli_demo.js&n=1210'><b>Click for browser script</b></a>")).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 17, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 36, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 36, 21, 390).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    ScreenshotDiv screenshotDiv = new ScreenshotDiv();
    screenshotDiv.setId("sakuli_screenshot243575009");
    screenshotDiv.setFormat("jpg");
    screenshotDiv.setBase64screenshot("/9j/4AAQSkZJRgABAgAAAQABAAD9k=");
    doReturn(screenshotDiv).when(screenshotDivConverter).convert(notNull(Throwable.class));
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestSuiteState.ERRORS.name()));
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TreeSet(java.util.TreeSet) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) ScreenshotDiv(org.sakuli.services.forwarder.gearman.model.ScreenshotDiv) DateTime(org.joda.time.DateTime) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 5 with TestCase

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

the class DatabaseResultServiceImplTest method testSaveResultsInDatabaseWithTestcases.

@Test
public void testSaveResultsInDatabaseWithTestcases() throws Exception {
    Integer tcPrimaryKey = 22;
    TestCase tc1 = mock(TestCase.class);
    TestCaseStep tcs1 = mock(TestCaseStep.class);
    when(tc1.getDbPrimaryKey()).thenReturn(tcPrimaryKey);
    SortedSet<TestCaseStep> tcStepList = new TreeSet<>(Collections.singleton(tcs1));
    when(tc1.getStepsAsSortedSet()).thenReturn(tcStepList);
    TestCase tc2 = mock(TestCase.class);
    when(tc2.getSteps()).thenReturn(new ArrayList<>());
    Map<String, TestCase> testCaseMap = new HashMap<>();
    testCaseMap.put("1", tc1);
    testCaseMap.put("2", tc2);
    testSuite = new TestSuite();
    testSuite.setTestCases(testCaseMap);
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    testling.saveAllResults();
    verify(daoTestSuite).saveTestSuiteResult();
    verify(daoTestSuite).saveTestSuiteToSahiJobs();
    verify(daoTestCase).saveTestCaseResult(tc1);
    verify(daoTestCase).saveTestCaseResult(tc2);
    verify(daoTestCase, times(2)).saveTestCaseResult(any(TestCase.class));
    verify(daoTestCaseStep).saveTestCaseSteps(tcStepList, tcPrimaryKey);
    verify(daoTestCaseStep).saveTestCaseSteps(any(SortedSet.class), anyInt());
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) DaoTestSuite(org.sakuli.services.forwarder.database.dao.DaoTestSuite) DaoTestCase(org.sakuli.services.forwarder.database.dao.DaoTestCase) TestCase(org.sakuli.datamodel.TestCase) DaoTestCaseStep(org.sakuli.services.forwarder.database.dao.DaoTestCaseStep) TestCaseStep(org.sakuli.datamodel.TestCaseStep) Test(org.testng.annotations.Test)

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