Skip to content

Commit

Permalink
#310 Twig templates for Gearman introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Todorov committed Feb 23, 2018
1 parent ce0868f commit 89b8b37
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 0 deletions.
@@ -0,0 +1,14 @@
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.warning || testCase.state.critical || testCase.state.error) %}
, case "{{ testCase.name }}"$whitespace$
{% if (testCase.state.error) %}
EXCEPTION: {{ errorMessageCreator.exceptionMessageTestCase(testCase) }}
{% else %}
{% if (testCase.state.critical) %}
over runtime ( {{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s)
{% else %}
over runtime ( {{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s)
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
@@ -0,0 +1,78 @@
{# This template renders the detailed summary for the current test suite. #}
{% include 'detailed_summary_css_styles.twig' %}
<table style="border-collapse: collapse;">
<tr valign="top">
<td class="service{{ getOutputState(testsuite.state) }}">
{{ getOutputState(testsuite.state).shortState }} Sakuli suite "{{ testsuite.id }}"$whitespace$
{% if (testsuite.state.error) %}
{% else %}
{{ testsuite.state.nagiosStateDescription }}$whitespace$
{% endif %}
{% if (testsuite.state.ok) %}
({{ format("%.2fs", testsuite.duration) }})$whitespace$
{% elseif (testsuite.state.name == 'WARNING_IN_SUITE') %}
({{ format("%.2fs", testsuite.duration) }}/warn at {{ testsuite.warningTime }}s)$whitespace$
{% elseif (testsuite.state.name == 'CRITICAL_IN_SUITE') %}
({{ format("%.2fs", testsuite.duration) }}/crit at {{ testsuite.criticalTime }}s)$whitespace$
{% elseif (testsuite.state.name == 'WARNING_IN_STEP') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.warningInStep) %}
{% for testStep in testCase.steps %}
{% if (testStep.state.warning) %}
, step "{{testStep.id}}" over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s)
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% elseif (testsuite.state.name == 'WARNING_IN_CASE') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.warning) %}
, case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s)
{% endif %}
{% endfor %}
{% elseif (testsuite.state.name == 'CRITICAL_IN_CASE') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.critical) %}
, case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s)
{% endif %}
{% endfor %}
{% endif %}
{% if (testsuite.state.error) %}
({{ format("%.2fs", testsuite.duration) }})$whitespace$
{{ testsuite.state.nagiosStateDescription }}:$whitespace$
{{ errorMessageCreator.exceptionMessageTestSuite(testsuite) }}.$whitespace$
{% endif %}
. (Last suite run:$whitespace$
{% if (empty(testsuite.stopDate)) %}
xx
{% else %}
{{ testsuite.stopDate|date("dd.MM.YY HH:mm:ss") }}
{% endif %})
{% include 'exception_screenshot.twig' with { testDataEntity: testsuite } %}
</td>
</tr>
{% for testCase in testsuite.testCasesAsSortedSet %}
<tr valign="top">
<td class="service{{ getOutputState(testCase.state) }}">
{{ getOutputState(testCase.state).shortState }} case "{{ testCase.id }}"$whitespace$
{% if (testCase.state.ok) %}
ran in {{ format("%.2fs", testCase.duration) }} - {{ testCase.state.nagiosStateDescription }}
{% elseif (testCase.state.warning) %}
over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s)
{% include 'step_information.twig' with { testCase: testCase } %}$whitespace$
{% elseif (testCase.state.critical) %}
{% set errorMessage = errorMessageCreator.exceptionMessageTestCase(testCase) %}
{% if (empty(errorMessage)) %}
over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s)
{% else %}
EXCEPTION: {{ errorMessageCreator.exceptionMessageTestCase(testCase) }}
{% include 'exception_screenshot.twig' with { testDataEntity: testCase } %}
{% for testStep in testCase.stepsAsSortedSet %}
{% include 'exception_screenshot.twig' with { testDataEntity: testStep } %}
{% endfor %}
{% endif %}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
@@ -0,0 +1,60 @@
<style>
.modalDialog {
width: 640px;
}
.modalDialog:target {
width: auto;
margin: 20px auto;
overflow: scroll;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 99999;
opacity: 1;
pointer-events: auto;
}
.modalDialog:target .close {
display: block;
}
.modalDialog:target .screenshot {
width: 100%;
border: 2px solid #333;
}
.screenshot {
width: 98%;
border: 2px solid gray;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: 4px;
cursor: -webkit-zoom-in;
cursor: -moz-zoom-in;
}
.close {
display: none;
background: #aaa;
color: #fff;
line-height: 25px;
position: absolute;
right: 10px;
text-align: center;
top: 25px;
width: 65px;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
}
.close:hover {
background: #333;
}
</style>
@@ -0,0 +1,42 @@
{# macro for creating the exception message of a test data entity. If there are any suppressed exception, they will be also listed. #}
{% macro exceptionMessage (testDataEntity) %}
{% if (testDataEntity.exception is not null) %}
{{ testDataEntity.exception.message }}
{# add suppressed exceptions #}
{% for suppressedException in testDataEntity.exception.suppressed %}
$whitespace$-- Suppressed EXCEPTION: {{ suppressedException.message }}
{% endfor %}
{% endif %}
{% endmacro %}

{# macro for creating the exception message of a test case and all of its test steps. #}
{% macro exceptionMessageTestCase (testCase) %}
{% import 'error_message_creator.twig' as errorMessageCreator %}
{% set testCaseErrorMessage = errorMessageCreator.exceptionMessage(testCase) %}
{{ testCaseErrorMessage }}
{% for testStep in testCase.stepsAsSortedSet %}
{% set stepErrorMessage = errorMessageCreator.exceptionMessage(testStep) %}
{% if (not isBlank(stepErrorMessage)) %}
{% if (not isBlank(testCaseErrorMessage)) %}
$whitespace$-$whitespace$
{% endif %}
STEP "{{ testStep.id }}": {{ stepErrorMessage }}
{% endif %}
{% endfor %}
{% endmacro %}

{# macro for creating the exception message of a test suite and all of its test cases. #}
{% macro exceptionMessageTestSuite (testSuite) %}
{% import 'error_message_creator.twig' as errorMessageCreator %}
{% set parentEntityErrorMessage = errorMessageCreator.exceptionMessage(testSuite) %}
{{ parentEntityErrorMessage }}
{% for testCase in testSuite.testCasesAsSortedSet %}
{% set caseErrorMessage = errorMessageCreator.exceptionMessageTestCase(testCase) %}
{% if (not isBlank(caseErrorMessage)) %}
{% if (not isBlank(parentEntityErrorMessage)) %}
$whitespace$--$whitespace$
{% endif %}
CASE "{{ testCase.id }}": {{ caseErrorMessage }}
{% endif %}
{% endfor %}
{% endmacro %}
@@ -0,0 +1,11 @@
{% set testScreenshotDiv = extractScreenshot(testDataEntity) %}
{% if (testScreenshotDiv != null) %}
<div id="{{ testScreenshotDiv.id }}">
<div id="openModal_{{ testScreenshotDiv.id }}" class="modalDialog">
<a href="#close" title="Close" class="close">Close X</a>
<a href="#openModal_{{ testScreenshotDiv.id }}">
<img class="screenshot" src="data:image/{{ testScreenshotDiv.format }};base64,{{ testScreenshotDiv.base64screenshot }}" >
</a>
</div>
</div>
{% endif %}
@@ -0,0 +1,19 @@
{% spaceless %}
{% import 'error_message_creator.twig' as errorMessageCreator %}
type={{ gearman.serviceType }}$newline$
host_name=
{% if (not empty(gearman.nagiosHost)) %}
{{ gearman.nagiosHost }}
{% else %}
{{ testsuite.host }}
{% endif %}$newline$
start_time={{ convertToUnixTimestamp(testsuite.startDate) }}$newline$
finish_time={{ convertToUnixTimestamp(testsuite.stopDate) }}$newline$
return_code={{ testsuite.state.nagiosErrorCode }}$newline$
service_description={{ gearman.nagiosServiceDescription }}$newline$
output=
{% include 'short_summary.twig' %}\\n
{% include 'detailed_summary.twig' %}
{% include 'performance_data.twig' %}
$whitespace$[{{ gearman.nagiosCheckCommand }}]
{% endspaceless %}
@@ -0,0 +1,19 @@
{# This template renders the performance data for the current test suite. #}
|suite__state={{getOutputState(testsuite.state).errorCode}};;;;
$whitespace$suite__warning={{ testsuite.warningTime }}s;;;;$whitespace$suite__critical={{ testsuite.criticalTime }}s;;;;$whitespace$suite_{{ testsuite.id }}={{getOutputDuration(testsuite)}};{{ testsuite.warningTime }};{{ testsuite.criticalTime }};;
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% set testCaseIndex = format("%03d", loop.index) %}
$whitespace$c_{{ testCaseIndex }}__state={{getOutputState(testCase.state).errorCode}};;;;
$whitespace$c_{{ testCaseIndex }}__warning={{ testCase.warningTime }}s;;;;
$whitespace$c_{{ testCaseIndex }}__critical={{ testCase.criticalTime }}s;;;;
$whitespace$c_{{ testCaseIndex }}_{{ testCase.id }}={{getOutputDuration(testCase)}};{{ testCase.warningTime }};{{ testCase.criticalTime }};;
{% for testStep in testCase.steps %}
{% set testStepIndex = format("%03d", loop.index) %}
$whitespace$s_{{ testCaseIndex }}_{{ testStepIndex }}_{{testStep.name}}={{getOutputDuration(testStep)}};
{% set testStepWarningTime = testStep.warningTime %}
{% if (testStepWarningTime > 0) %}
{{testStepWarningTime}}
{% else %}
{% endif %};;;
{% endfor %}
{% endfor %}
@@ -0,0 +1,38 @@
{# This template renders the short summary for the current test suite. #}
{{ getOutputState(testsuite.state).shortState }} Sakuli suite "{{testsuite.id}}"$whitespace$
{% if (testsuite.state.error) %}
{% set exceptionMessages = errorMessageCreator.exceptionMessageTestSuite(testsuite) %}
({{ format("%.2fs", testsuite.duration) }}) {{testsuite.state.nagiosStateDescription}}: {{abbreviate(exceptionMessages, 200, true)}}
{% else %}
{{testsuite.state.nagiosStateDescription}}
{% if (testsuite.state.ok) %}
$whitespace$({{ format("%.2fs", testsuite.duration) }})
{% elseif (testsuite.state.name == 'WARNING_IN_SUITE') %}
$whitespace$({{ format("%.2fs", testsuite.duration) }}/warn at {{ testsuite.warningTime }}s)
{% elseif (testsuite.state.name == 'CRITICAL_IN_SUITE') %}
$whitespace$({{ format("%.2fs", testsuite.duration) }}/crit at {{ testsuite.criticalTime }}s)
{% elseif (testsuite.state.name == 'WARNING_IN_STEP') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.warningInStep) %}
{% for testStep in testCase.steps %}
{% if (testStep.state.warning) %}
, step "{{testStep.id}}" over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s)
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% elseif (testsuite.state.name == 'WARNING_IN_CASE') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.warning) %}
, case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/warn at {{ testCase.warningTime }}s)
{% endif %}
{% endfor %}
{% elseif (testsuite.state.name == 'CRITICAL_IN_CASE') %}
{% for testCaseId, testCase in testsuite.testCasesAsSortedSet %}
{% if (testCase.state.critical) %}
, case "{{testCase.id}}" over runtime ({{ format("%.2fs", testCase.duration) }}/crit at {{ testCase.criticalTime }}s)
{% endif %}
{% endfor %}
{% endif %}
.$whitespace$(Last suite run: {% if (empty(testsuite.stopDate)) %}xx{% else %}{{ testsuite.stopDate|date("dd.MM.YY HH:mm:ss") }}{% endif %})
{% endif %}
@@ -0,0 +1,9 @@
{% for testStep in testCase.stepsAsSortedSet %}
{% if (testStep.state.error) %}
, step "{{ testStep.name }}"$whitespace$
EXCEPTION: {{ errorMessageCreator.exceptionMessage(testStep) }}
{% elseif (testStep.state.warning) %}
, step "{{ testStep.name }}"$whitespace$
over runtime ({{ format("%.2fs", testStep.duration) }}/warn at {{ testStep.warningTime }}s)
{% endif %}
{% endfor %}
@@ -0,0 +1,47 @@
/*
* Sakuli - Testing and Monitoring-Tool for Websites and common UIs.
*
* Copyright 2013 - 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.sakuli.services.forwarder.gearman;

import org.jtwig.JtwigModel;
import org.sakuli.services.forwarder.AbstractTemplateOutputBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* @author Georgi Todorov
*/
@ProfileGearman
@Component
public class GearmanTemplateOutputBuilder extends AbstractTemplateOutputBuilder {

@Autowired
private GearmanProperties gearmanProperties;

@Override
public String getConverterName() {
return "Gearman";
}

@Override
public JtwigModel createModel() {
return super.createModel()
.with("gearman", gearmanProperties);
}

}

0 comments on commit 89b8b37

Please sign in to comment.