Search in sources :

Example 6 with TestCaseExampleBuilder

use of org.sakuli.builder.TestCaseExampleBuilder 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 7 with TestCaseExampleBuilder

use of org.sakuli.builder.TestCaseExampleBuilder in project sakuli by ConSol.

the class DaoTestCaseImplTest method testGetScreenshotAsSqlLobValueTestCase.

@Test
public void testGetScreenshotAsSqlLobValueTestCase() throws Exception {
    Path screenshotPath = Paths.get(this.getClass().getResource("computer.png").toURI());
    TestCase testCase = new TestCaseExampleBuilder().withException(null).withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withException(new SakuliExceptionWithScreenshot("test-exception", screenshotPath)).buildExample())).buildExample();
    SqlLobValue result = testling.getScreenshotAsSqlLobValue(testCase);
    assertNotNull(result);
}
Also used : Path(java.nio.file.Path) SqlLobValue(org.springframework.jdbc.core.support.SqlLobValue) TestCase(org.sakuli.datamodel.TestCase) SakuliExceptionWithScreenshot(org.sakuli.exceptions.SakuliExceptionWithScreenshot) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test)

Example 8 with TestCaseExampleBuilder

use of org.sakuli.builder.TestCaseExampleBuilder in project sakuli by ConSol.

the class AbstractOutputBuilderTest method testGetTextPlaceHolderTestCase.

@Test
public void testGetTextPlaceHolderTestCase() throws Exception {
    TestCase testCase = new TestCaseExampleBuilder().withState(TestCaseState.OK).withTestCaseFile(Paths.get("folder/_tc.js")).buildExample();
    final PlaceholderMap textPlaceholder = testling.getTextPlaceholder(testCase);
    assertEquals(textPlaceholder.get(STATE), "OK");
    assertEquals(textPlaceholder.get(STATE_SHORT), "[OK]");
    assertEquals(textPlaceholder.get(STATE_DESC), "ok");
    assertEquals(textPlaceholder.get(NAME), testCase.getName());
    assertEquals(textPlaceholder.get(ID), testCase.getId());
    assertEquals(textPlaceholder.get(DURATION), "3.00");
    assertEquals(textPlaceholder.get(STOP_DATE), AbstractOutputBuilder.dateFormat.format(testCase.getStopDate()));
    assertEquals(textPlaceholder.get(START_DATE), AbstractOutputBuilder.dateFormat.format(testCase.getStartDate()));
    assertEquals(textPlaceholder.get(WARN_THRESHOLD), "4");
    assertEquals(textPlaceholder.get(CRITICAL_THRESHOLD), "5");
    assertEquals(textPlaceholder.get(ERROR_MESSAGE), "");
    assertEquals(textPlaceholder.get(CASE_FILE), String.format("folder%s_tc.js", File.separator));
    assertEquals(textPlaceholder.get(CASE_LAST_URL), "http://www.last-url.com");
    assertEquals(textPlaceholder.get(CASE_START_URL), "http://www.start-url.com");
    assertEquals(textPlaceholder.get(STEP_INFORMATION), "");
    assertEquals(textPlaceholder.get(TD_CSS_CLASS), "serviceOK");
    //assert empty fields
    assertEquals(textPlaceholder.get(SUITE_SUMMARY), "");
    assertEquals(textPlaceholder.get(SUITE_FOLDER), "");
    assertEquals(textPlaceholder.get(HOST), "");
    assertEquals(textPlaceholder.get(BROWSER_INFO), "");
}
Also used : TestCase(org.sakuli.datamodel.TestCase) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) Test(org.testng.annotations.Test)

Example 9 with TestCaseExampleBuilder

use of org.sakuli.builder.TestCaseExampleBuilder in project sakuli by ConSol.

the class AbstractPerformanceDataBuilderTest method testGetPerformanceDataWithPreParsedSteps.

@Test
public void testGetPerformanceDataWithPreParsedSteps() throws Exception {
    Date startDate = new GregorianCalendar(2014, 14, 7, 13, 0).getTime();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 120)).withWarningTime(100).withCriticalTime(150).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withState(TestCaseState.WARNING_IN_STEP).withId("case-warning").withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 20)).withWarningTime(19).withCriticalTime(25).withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withName("step1").withState(TestCaseStepState.WARNING).withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 10)).withWarningTime(9).buildExample(), new TestCaseStepBuilder("step2_not_started").withState(TestCaseStepState.INIT).build())).buildExample())).buildExample();
    testSuiteExample.refreshState();
    assertEquals(AbstractPerformanceDataBuilder.getTestSuitePerformanceData(testSuiteExample), "suite__state=1;;;; " + "suite__warning=100s;;;; " + "suite__critical=150s;;;; " + "suite_sakuli-123=120.00s;100;150;; " + "c_001__state=1;;;; " + "c_001__warning=19s;;;; " + "c_001__critical=25s;;;; " + "c_001_case-warning=20.00s;19;25;; " + "s_001_001_step1=10.00s;9;;; " + "s_001_002_step2_not_started=U;;;;");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepBuilder(org.sakuli.datamodel.builder.TestCaseStepBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Example 10 with TestCaseExampleBuilder

use of org.sakuli.builder.TestCaseExampleBuilder in project sakuli by ConSol.

the class CheckMKTemplateOutputBuilderTest method testOK.

@Test
public void testOK() throws Exception {
    doReturn("example_xfce").when(testSuite).getId();
    doReturn(TestSuiteState.OK).when(testSuite).getState();
    doReturn(300).when(testSuite).getWarningTime();
    doReturn(400).when(testSuite).getCriticalTime();
    doReturn(44.99f).when(testSuite).getDuration();
    doReturn(new DateTime(1970, 1, 1, 10, 30, 0).toDate()).when(testSuite).getStartDate();
    doReturn(new DateTime(1970, 1, 1, 10, 30, 44, 99).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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 14, 20).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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 160).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 7, 290).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Editor").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 500).toDate()).buildExample())).buildExample(), new TestCaseExampleBuilder().withState(TestCaseState.OK).withWarningTime(20).withCriticalTime(30).withStartDate(new DateTime(1970, 1, 1, 10, 30, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 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, 30, 0).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 30).toDate()).buildExample(), new TestCaseStepExampleBuilder().withState(TestCaseStepState.OK).withName("Calculation_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 10).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 7, 80).toDate()).buildExample(), new TestCaseStepExampleBuilder().withName("Editor_(case2)").withWarningTime(10).withStartDate(new DateTime(1970, 1, 1, 10, 30, 0, 20).toDate()).withStopDate(new DateTime(1970, 1, 1, 10, 30, 1, 390).toDate()).buildExample())).buildExample()));
    doReturn(testCaseAsSortedSet).when(testSuite).getTestCasesAsSortedSet();
    String output = testling.createOutput();
    Assert.assertEquals(output, loadExpectedOutput(TestCaseState.OK.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)

Aggregations

TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)29 Test (org.testng.annotations.Test)29 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)17 BaseTest (org.sakuli.BaseTest)15 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)15 TestSuite (org.sakuli.datamodel.TestSuite)15 TestCase (org.sakuli.datamodel.TestCase)14 TreeSet (java.util.TreeSet)7 DateTime (org.joda.time.DateTime)7 SakuliException (org.sakuli.exceptions.SakuliException)7 Path (java.nio.file.Path)6 SakuliExceptionWithScreenshot (org.sakuli.exceptions.SakuliExceptionWithScreenshot)5 GearmanProperties (org.sakuli.services.forwarder.gearman.GearmanProperties)4 Date (java.util.Date)2 SqlLobValue (org.springframework.jdbc.core.support.SqlLobValue)2 Future (java.util.concurrent.Future)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 LoggerTest (org.sakuli.LoggerTest)1 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)1 TestCaseStepState (org.sakuli.datamodel.state.TestCaseStepState)1