Search in sources :

Example 11 with TestSuite

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

the class CommonInitializingServiceImplTest method testInitWithOutTestCases.

@Test
public void testInitWithOutTestCases() throws Throwable {
    TestSuiteProperties props = new TestSuiteProperties();
    props.setTestSuiteId("suite_id");
    props.setLoadTestCasesAutomatic(false);
    testSuiteProperties = spy(props);
    ts = spy(new TestSuite(testSuiteProperties));
    MockitoAnnotations.initMocks(this);
    testling.initTestSuite();
    assertEquals(ts.getState(), TestSuiteState.RUNNING);
    assertNotNull(ts.getStartDate());
    assertNull(ts.getAbsolutePathOfTestSuiteFile());
    assertEquals(ts.getDbPrimaryKey(), -1);
    assertNull(ts.getTestCases());
    assertEquals(ts.getId(), "suite_id");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestSuiteProperties(org.sakuli.datamodel.properties.TestSuiteProperties) Test(org.testng.annotations.Test)

Example 12 with TestSuite

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

the class CommonResultServiceImplTest method testSaveAllResults.

@Test(dataProvider = "states")
public void testSaveAllResults(TestSuiteState testSuiteState, TestCaseState testCaseState, String stateOutputRegex) throws Exception {
    TestCaseStepState stepState = TestCaseStepState.WARNING;
    TestSuite testSuite = new TestSuiteExampleBuilder().withId("LOG_TEST_SUITE").withState(testSuiteState).withException(testSuiteState.isError() ? new SakuliException("TEST") : null).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(stepState).buildExample())).withState(testCaseState).buildExample())).buildExample();
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    Path logfile = Paths.get(properties.getLogFile());
    testling.saveAllResults();
    String lastLineOfLogFile = getLastLineOfLogFile(logfile, testSuiteState.isError() ? 42 : 39);
    List<String> regExes = getValidationExpressions(testSuiteState, testCaseState, stepState, stateOutputRegex, "TEST");
    List<String> strings = Arrays.asList(lastLineOfLogFile.split("\n"));
    Iterator<String> regExIterator = regExes.iterator();
    verifyOutputLines(strings, regExIterator);
}
Also used : Path(java.nio.file.Path) TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepState(org.sakuli.datamodel.state.TestCaseStepState) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test) LoggerTest(org.sakuli.LoggerTest)

Example 13 with TestSuite

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

the class AbstractOutputBuilderTest method testFormatTestSuiteStateMessageOK.

@Test
public void testFormatTestSuiteStateMessageOK() throws Exception {
    Date startDate = new Date();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withState(TestSuiteState.OK).withStartDate(startDate).withStopDate(DateUtils.addSeconds(startDate, 120)).buildExample();
    String result = testling.formatTestSuiteSummaryStateMessage(testSuiteExample, properties.getTemplateSuiteSummary());
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
    assertEquals(result, "[OK] Sakuli suite \"sakuli-123\" ok (120.00s). (Last suite run: " + lastRun + ")");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Example 14 with TestSuite

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

the class AbstractOutputBuilderTest method testFormatTestSuiteStateMessageException.

@Test
public void testFormatTestSuiteStateMessageException() throws Exception {
    Date startDate = new Date();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withState(TestSuiteState.ERRORS).withStartDate(startDate).withException(new SakuliException("TEST-ERROR")).withStopDate(DateUtils.addSeconds(startDate, 120)).buildExample();
    String result = testling.formatTestSuiteSummaryStateMessage(testSuiteExample, properties.getTemplateSuiteSummary());
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
    assertEquals(result, "[CRIT] Sakuli suite \"sakuli-123\" (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test)

Example 15 with TestSuite

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

the class GearmanResultServiceImplTest method testSaveAllResults.

@Test
public void testSaveAllResults() throws Exception {
    when(properties.getServiceType()).thenReturn("passive");
    final String queueName = "check_results";
    when(properties.getServerQueue()).thenReturn(queueName);
    final String host = "99.99.99.20";
    when(properties.getServerHost()).thenReturn(host);
    final int port = 4730;
    when(properties.getServerPort()).thenReturn(port);
    when(properties.getNagiosHost()).thenReturn("win7sakuli");
    when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
    GearmanClient gearmanClient = mock(GearmanClientImpl.class);
    doReturn(gearmanClient).when(testling).getGearmanClient();
    GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
    doReturn(connection).when(testling).getGearmanConnection(host, port);
    GearmanJob job = mock(GearmanJob.class);
    doReturn(job).when(testling).creatJob(any(NagiosCheckResult.class));
    Future future = mock(Future.class);
    when(gearmanClient.addJobServer(connection)).thenReturn(true);
    when(gearmanClient.submit(job)).thenReturn(future);
    GearmanJobResult jobResult = mock(GearmanJobResult.class);
    when(future.get()).thenReturn(jobResult);
    when(jobResult.jobSucceeded()).thenReturn(true);
    GearmanJobStatus jobStatus = mock(GearmanJobStatus.class);
    when(jobStatus.isRunning()).thenReturn(false);
    when(gearmanClient.getJobStatus(job)).thenReturn(jobStatus);
    Date stopDate = new GregorianCalendar(2014, 14, 7, 13, 0).getTime();
    TestSuite testSuite = new TestSuiteExampleBuilder().withHost("win7sakuli").withId("sakuli_demo22").withStopDate(stopDate).withStartDate(DateUtils.addSeconds(stopDate, -60)).withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("ok_case").withStartDate(DateUtils.addSeconds(stopDate, -12)).withStopDate(stopDate).withWarningTime(13).withCriticalTime(20).buildExample())).buildExample();
    stopDate = DateUtils.addSeconds(stopDate, 300);
    testSuite.addTestCase(new TestCaseExampleBuilder().withId("warn_case").withStartDate(DateUtils.addSeconds(stopDate, -30)).withStopDate(stopDate).withWarningTime(20).withCriticalTime(40).buildExample());
    stopDate = DateUtils.addSeconds(stopDate, 300);
    testSuite.addTestCase(new TestCaseExampleBuilder().withId("warn_in_step").withStartDate(DateUtils.addSeconds(stopDate, -30)).withStopDate(stopDate).withWarningTime(40).withCriticalTime(50).withTestCaseSteps(Arrays.asList(new TestCaseStepExampleBuilder().withName("warn_step_1").withStartDate(DateUtils.addSeconds(stopDate, -29)).withStopDate(DateUtils.addSeconds(stopDate, -20)).withWarningTime(5).buildExample(), new TestCaseStepExampleBuilder().withName("warn_step_2").withStartDate(DateUtils.addSeconds(stopDate, -19)).withStopDate(DateUtils.addSeconds(stopDate, -10)).withWarningTime(5).buildExample())).buildExample());
    stopDate = DateUtils.addSeconds(stopDate, 300);
    testSuite.addTestCase(new TestCaseExampleBuilder().withId("crit_case").withStartDate(DateUtils.addSeconds(stopDate, -14)).withStopDate(stopDate).withWarningTime(10).withCriticalTime(13).buildExample());
    stopDate = DateUtils.addSeconds(stopDate, 300);
    testSuite.addTestCase(new TestCaseExampleBuilder().withId("error_case").withStartDate(DateUtils.addSeconds(stopDate, -14)).withException(new SakuliActionException("exception test message")).buildExample());
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    testling.saveAllResults();
    //checks
    verify(gearmanCacheService, never()).cacheResults(anyList());
    verify(gearmanCacheService, never()).getCachedResults();
    verify(exceptionHandler, never()).handleException(any(Throwable.class));
    verify(exceptionHandler, never()).handleException(any(Throwable.class), anyBoolean());
    verify(testling).getGearmanClient();
    verify(testling).getGearmanConnection(host, port);
    verify(gearmanClient).addJobServer(connection);
    verify(gearmanClient).submit(job);
    verify(future).get();
    verify(gearmanClient).shutdown();
    ArgumentCaptor<NagiosCheckResult> checkresult = ArgumentCaptor.forClass(NagiosCheckResult.class);
    verify(testling).creatJob(checkresult.capture());
    assertEquals(checkresult.getValue().getQueueName(), queueName);
    assertEquals(checkresult.getValue().getUuid(), testSuite.getGuid());
    assertEquals(checkresult.getValue().getPayloadString(), testResult);
}
Also used : TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) TestSuite(org.sakuli.datamodel.TestSuite) NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) Future(java.util.concurrent.Future) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) SakuliActionException(org.sakuli.exceptions.SakuliActionException) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Aggregations

TestSuite (org.sakuli.datamodel.TestSuite)41 Test (org.testng.annotations.Test)34 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)21 BaseTest (org.sakuli.BaseTest)15 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)15 TestCase (org.sakuli.datamodel.TestCase)13 SakuliException (org.sakuli.exceptions.SakuliException)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)6 TestCaseStep (org.sakuli.datamodel.TestCaseStep)6 Path (java.nio.file.Path)5 Date (java.util.Date)5 TestCaseStepBuilder (org.sakuli.datamodel.builder.TestCaseStepBuilder)2 SakuliInitException (org.sakuli.exceptions.SakuliInitException)2 FileNotFoundException (java.io.FileNotFoundException)1 Entry (java.util.Map.Entry)1 Future (java.util.concurrent.Future)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 DateTime (org.joda.time.DateTime)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LoggerTest (org.sakuli.LoggerTest)1