ru.yandex.qatools.allure.config.AllureModelUtils Java Examples

The following examples show how to use ru.yandex.qatools.allure.config.AllureModelUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void skipTestFireTestCaseStartedEvent() {
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getTestContext().getSuite().getName()).thenReturn(DEFAULT_SUITE_NAME);
    when(testResult.getTestContext().getCurrentXmlTest().getName()).thenReturn(DEFAULT_XML_TEST_NAME);
    when(testResult.getTestClass().getName()).thenReturn(DEFAULT_CLASS_NAME);
    when(testResult.getMethod().getMethodName()).thenReturn(DEFAULT_TEST_NAME);
    doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

    String uid = UUID.randomUUID().toString();
    when(testContext.getAttribute("SUITE_UID")).thenReturn(uid);
    testngListener.onTestSkipped(testResult);

    String suiteUid = testngListener.getSuiteUid(testContext);
    verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, DEFAULT_TEST_NAME).withLabels(
            AllureModelUtils.createTestSuiteLabel(DEFAULT_SUITE_NAME),
            AllureModelUtils.createTestGroupLabel(DEFAULT_XML_TEST_NAME),
            AllureModelUtils.createTestClassLabel(DEFAULT_CLASS_NAME),
            AllureModelUtils.createTestMethodLabel(DEFAULT_TEST_NAME)))));
}
 
Example #2
Source File: Allure.java    From allure1 with Apache License 2.0 6 votes vote down vote up
/**
 * Process TestSuiteFinishedEvent. Using event.getUid() to access testSuite.
 * Then remove this suite from storage and marshal testSuite to xml using
 * AllureResultsUtils.writeTestSuiteResult()
 *
 * @param event to process
 */
public void fire(TestSuiteFinishedEvent event) {
    String suiteUid = event.getUid();

    TestSuiteResult testSuite = testSuiteStorage.remove(suiteUid);
    if (testSuite == null) {
        return;
    }
    event.process(testSuite);

    testSuite.setVersion(getVersion());
    testSuite.getLabels().add(AllureModelUtils.createProgrammingLanguageLabel());

    writeTestSuiteResult(testSuite);

    notifier.fire(event);
}
 
Example #3
Source File: WriteTestSuiteResultTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void invalidCharacterTest() throws Exception {
    TestSuiteResult testSuiteResult = new TestSuiteResult()
            .withName("somename");

    String titleWithInvalidXmlCharacter = String.valueOf(Character.toChars(0x0));
    testSuiteResult.setTitle(titleWithInvalidXmlCharacter);

    AllureResultsUtils.writeTestSuiteResult(testSuiteResult);

    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDirectory)) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #4
Source File: AllureTestListenerMultipleSuitesTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSuiteFilesTest() throws Exception {
    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDir.toFile())) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #5
Source File: AllureReporter.java    From colibri-ui with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeStory(Story story, boolean givenStory) {
    uid = generateSuiteUid(story);
    String path = story.getPath();
    int secondIndex = StringUtils.ordinalIndexOf(path, "/", 2);
    String subPath = path.substring(secondIndex + 1);
    TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, story.getName());
    event.withLabels(AllureModelUtils.createTestFrameworkLabel("JBehave"));
    event.withTitle(subPath);
    allure.fire(event);
}
 
Example #6
Source File: AllureTestListenerXmlValidationTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSuiteFilesTest() throws Exception {
    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDir.toFile())) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #7
Source File: AllureTestListenerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void parametrizedTest() {
    double doubleParameter = 10.0;
    String stringParameter = "string";
    String anotherStringParameter = "anotherString";
    String nullValueParameter = null;
    when(testResult.getTestContext()).thenReturn(testContext);
    when(testResult.getName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getTestContext().getSuite().getName()).thenReturn(DEFAULT_SUITE_NAME);
    when(testResult.getTestContext().getCurrentXmlTest().getName()).thenReturn(DEFAULT_XML_TEST_NAME);
    when(testResult.getTestClass().getName()).thenReturn(DEFAULT_CLASS_NAME);
    when(testResult.getMethod().getMethodName()).thenReturn(DEFAULT_TEST_NAME);
    when(testResult.getParameters()).thenReturn(new Object[]{doubleParameter, stringParameter, anotherStringParameter, nullValueParameter});

    doReturn(new Annotation[0]).when(testngListener).getMethodAnnotations(testResult);

    String uid = UUID.randomUUID().toString();
    when(testContext.getAttribute("SUITE_UID")).thenReturn(uid);
    testngListener.onTestStart(testResult);

    String suiteUid = testngListener.getSuiteUid(testContext);
    String testName = String.format("%s[%s,%s,%s,%s]",
            DEFAULT_TEST_NAME, Double.toString(doubleParameter), stringParameter, anotherStringParameter, nullValueParameter);
    verify(allure).fire(eq(withExecutorInfo(new TestCaseStartedEvent(suiteUid, testName).withLabels(
            AllureModelUtils.createTestSuiteLabel(DEFAULT_SUITE_NAME),
            AllureModelUtils.createTestGroupLabel(DEFAULT_XML_TEST_NAME),
            AllureModelUtils.createTestClassLabel(DEFAULT_CLASS_NAME),
            AllureModelUtils.createTestMethodLabel(DEFAULT_TEST_NAME)))));

    ArgumentCaptor<AddParameterEvent> captor = ArgumentCaptor.forClass(AddParameterEvent.class);
    verify(allure, times(3)).fire(captor.capture());

    Iterator<AddParameterEvent> addParameterEvents = captor.getAllValues().iterator();
    assertParameterEvent("doubleParameter", doubleParameter + "", addParameterEvents.next(), false);
    assertParameterEvent("valueFromAnnotation", anotherStringParameter, addParameterEvents.next(), true);
    assertParameterEvent("valueFromAnnotation", "null", addParameterEvents.next(), true);
    assertFalse(addParameterEvents.hasNext());
}
 
Example #8
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Override
public void onTestStart(ITestResult iTestResult) {
    ITestNGMethod method = iTestResult.getMethod();
    String testSuiteLabel = iTestResult.getTestContext().getSuite().getName();
    String testGroupLabel = iTestResult.getTestContext().getCurrentXmlTest().getName();
    String testClassLabel = iTestResult.getTestClass().getName();
    String testMethodLabel = method.getMethodName();
    String suitePrefix = getCurrentSuitePrefix(iTestResult);
    String testName = getName(iTestResult);
    startedTestNames.add(testName);
    testName = testName.replace(suitePrefix, "");

    String invoc = getMethodInvocationsAndSuccessPercentage(iTestResult);
    Description description = new Description().withValue(method.getDescription());
    String suiteUid = getSuiteUid(iTestResult.getTestContext());
    TestCaseStartedEvent event = new TestCaseStartedEvent(suiteUid, testName + invoc).withLabels(
            AllureModelUtils.createTestSuiteLabel(testSuiteLabel),
            AllureModelUtils.createTestGroupLabel(testGroupLabel),
            AllureModelUtils.createTestClassLabel(testClassLabel),
            AllureModelUtils.createTestMethodLabel(testMethodLabel));
    if (description.getValue() != null) {
        event.setDescription(description);
    }
    AnnotationManager am = new AnnotationManager(getMethodAnnotations(iTestResult));
    am.setDefaults(getClassAnnotations(iTestResult));
    am.update(event);

    getLifecycle().fire(event);

    if (AllureConfig.newInstance().areTestNgParametersEnabled()) {
        fireAddParameterEvents(iTestResult);
    }
}
 
Example #9
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart(ITestContext iTestContext) {
    getLifecycle().fire(new TestSuiteStartedEvent(
            getSuiteUid(iTestContext), getCurrentSuiteTitle(iTestContext)
    ).withTitle(
            getCurrentSuiteTitle(iTestContext)
    ).withLabels(
            AllureModelUtils.createTestFrameworkLabel("TestNG")
    ));
    addPendingMethods(iTestContext);
}
 
Example #10
Source File: AllureListenerXmlValidationTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSuiteFilesTest() throws Exception {
    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDirectory)) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #11
Source File: BadXmlCharacterEscapeHandlerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void dataWithInvalidCharacterTest() throws Exception {
    AllureResultsUtils.writeTestSuiteResult(result, testSuiteResultFile);

    Validator validator = AllureModelUtils.getAllureSchemaValidator();
    validator.validate(new StreamSource(testSuiteResultFile));

    TestSuiteResult testSuite = JAXB.unmarshal(testSuiteResultFile, TestSuiteResult.class);
    assertThat(testSuite.getName(), is("name-and-кириллицей-also"));
    assertTrue(testSuite.getTitle().startsWith("prefix "));
    assertTrue(testSuite.getTitle().endsWith(" suffix"));
}
 
Example #12
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public void validateTestSuite() throws SAXException, IOException {
    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDirectory)) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #13
Source File: AllureRunListener.java    From allure-cucumberjvm with Apache License 2.0 5 votes vote down vote up
public void testSuiteStarted(Description description, String suiteName) throws IllegalAccessException {

        String[] annotationParams = findFeatureByScenarioName(suiteName);

        //Create feature and story annotations. Remove unnecessary words from it
        Features feature = getFeaturesAnnotation(new String[]{annotationParams[0].split(":")[1].trim()});
        Stories story = getStoriesAnnotation(new String[]{annotationParams[1].split(":")[1].trim()});

        //If it`s Scenario Outline, add example string to story name
        if (description.getDisplayName().startsWith("|")
                || description.getDisplayName().endsWith("|")) {
            story = getStoriesAnnotation(new String[]{annotationParams[1].split(":")[1].trim()
                    + " " + description.getDisplayName()});
        }

        String uid = generateSuiteUid(suiteName);
        TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, story.value()[0]);

        event.setTitle(story.value()[0]);

        //Add feature and story annotations
        Collection<Annotation> annotations = new ArrayList<>();
        for (Annotation annotation : description.getAnnotations()) {
            annotations.add(annotation);
        }
        annotations.add(story);
        annotations.add(feature);
        AnnotationManager am = new AnnotationManager(annotations);
        am.update(event);

        event.withLabels(AllureModelUtils.createTestFrameworkLabel("CucumberJVM"));

        getLifecycle().fire(event);
    }
 
Example #14
Source File: AllureMarathonRunListener.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted(Description description) {
    TestCaseStartedEvent event = new TestCaseStartedEvent(getSuiteUid(description), getTestName());

    SeverityLevel severityLevel = SeverityLevel.NORMAL;
    Properties testProperties = getTestProperties();
    String severity = testProperties.getProperty("severity");
    if (severity != null) {
        severityLevel = SeverityLevel.fromValue(severity);
    }
    event.getLabels().add(AllureModelUtils.createSeverityLabel(severityLevel));

    String desc = testProperties.getProperty("description");
    if (desc != null) {
        String dType = "text";
        if (desc.startsWith("html:")) {
            dType = "html";
            desc = desc.substring(5);
        } else if (desc.startsWith("markdown:")) {
            dType = "markdown";
            desc = desc.substring(9);
        }
        event.setDescription(
                new ru.yandex.qatools.allure.model.Description().withType(DescriptionType.fromValue(dType)).withValue(desc));
    }

    String id = testProperties.getProperty("id");
    if (id != null) {
        event.getLabels().add(AllureModelUtils.createTestLabel(id));
    }

    Path testPath = Paths.get(testProperties.getProperty("path", ""));
    addGroups(issues, event.getLabels(), testPath, LabelName.ISSUE);
    addGroups(features, event.getLabels(), testPath, LabelName.FEATURE);
    addGroups(stories, event.getLabels(), testPath, LabelName.STORY);
    getLifecycle().fire(event);
}
 
Example #15
Source File: AllureReporter.java    From allure-cucumberjvm with Apache License 2.0 4 votes vote down vote up
@Override
public void startOfScenarioLifeCycle(Scenario scenario) {

    //to avoid duplicate steps in case of Scenario Outline
    if (SCENARIO_OUTLINE_KEYWORDS.contains(scenario.getKeyword())) {
        synchronized (gherkinSteps) {
            gherkinSteps.clear();
        }
    }

    currentStatus = PASSED;

    TestCaseStartedEvent event = new TestCaseStartedEvent(uid, scenario.getName());
    event.setTitle(scenario.getName());

    Collection<Annotation> annotations = new ArrayList<>();

    SeverityLevel level = getSeverityLevel(scenario);

    if (level != null) {
        annotations.add(getSeverityAnnotation(level));
    }

    Issues issues = getIssuesAnnotation(scenario);
    if (issues != null) {
        annotations.add(issues);
    }

    TestCaseId testCaseId = getTestCaseIdAnnotation(scenario);
    if (testCaseId != null) {
        annotations.add(testCaseId);
    }

    annotations.add(getFeaturesAnnotation(feature.getName()));
    annotations.add(getStoriesAnnotation(scenario.getName()));
    annotations.add(getDescriptionAnnotation(scenario.getDescription()));

    AnnotationManager am = new AnnotationManager(annotations);
    am.update(event);

    event.withLabels(AllureModelUtils.createTestFrameworkLabel("CucumberJVM"));

    ALLURE_LIFECYCLE.fire(event);
}
 
Example #16
Source File: AllureMarathonRunListener.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void addGroups(List<Group> groups, List<Label> labels, Path testPath, LabelName labelName) {
    List<Group> matched = groups.stream().filter((g) -> g.hasTest(testPath)).collect(Collectors.toList());
    for (Group group : matched) {
        labels.add(AllureModelUtils.createLabel(labelName, group.getName()));
    }
}
 
Example #17
Source File: AllureRunListener.java    From allure1 with Apache License 2.0 3 votes vote down vote up
public void testSuiteStarted(Description description) {
    String uid = generateSuiteUid(description.getClassName());

    TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, description.getClassName());
    AnnotationManager am = new AnnotationManager(description.getAnnotations());

    am.update(event);

    event.withLabels(AllureModelUtils.createTestFrameworkLabel("JUnit"));

    getLifecycle().fire(event);
}
 
Example #18
Source File: AllureMarathonRunListener.java    From marathonv5 with Apache License 2.0 3 votes vote down vote up
public void testSuiteStarted(Description description) {
    String uid = generateSuiteUid(getSuiteName(description));

    TestSuiteStartedEvent event = new TestSuiteStartedEvent(uid, getSuiteName(description));
    AnnotationManager am = new AnnotationManager(description.getAnnotations());

    am.update(event);

    event.withLabels(AllureModelUtils.createTestFrameworkLabel("Marathon"));

    getLifecycle().fire(event);
}