Search in sources :

Example 1 with TestPlan

use of de.simpleworks.staf.commons.elements.TestPlan in project staf by simpleworks-gmbh.

the class UtilsTestplan method readTestplan.

/**
 * @return null, if file has not been read correctly, otherwise if not.
 */
public static TestPlan readTestplan(final File file) {
    if (file == null) {
        throw new IllegalArgumentException("file can't be null.");
    }
    if (!file.exists()) {
        throw new IllegalArgumentException(String.format("file does not exist at '%s'.", file.getAbsolutePath()));
    }
    TestPlan result = null;
    final Gson gson = new GsonBuilder().setPrettyPrinting().create();
    try {
        result = gson.fromJson(UtilsIO.getAllContentFromFile(file), TestPlan.class);
    } catch (final SystemException e) {
        UtilsTestplan.logger.error(String.format("can't read test plan from file: '%s'.", file), e);
    // FIXME throw an exception.
    }
    return result;
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) TestPlan(de.simpleworks.staf.commons.elements.TestPlan) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Example 2 with TestPlan

use of de.simpleworks.staf.commons.elements.TestPlan in project staf by simpleworks-gmbh.

the class STAFSurefirePlugin method getTestPlans.

private List<TestPlan> getTestPlans(final String filepath) {
    if (Convert.isEmpty(filepath)) {
        throw new IllegalArgumentException("filepath can't be null or empty string.");
    }
    final File testplanFile = new File(filepath);
    if (!testplanFile.exists()) {
        throw new RuntimeException(String.format("testplan at '%s' does not exist.", file));
    }
    if (STAFSurefirePlugin.logger.isDebugEnabled()) {
        STAFSurefirePlugin.logger.debug(String.format("read test plan from file: '%s'.", testplanFile));
    }
    final List<TestPlan> testplans;
    try {
        testplans = new MapperTestplan().readAll(testplanFile);
    } catch (final Exception ex) {
        final String msg = String.format("cannot read testplans from '%s'.", filepath);
        STAFSurefirePlugin.logger.error(msg, ex);
        throw new RuntimeException(msg);
    }
    return testplans;
}
Also used : TestPlan(de.simpleworks.staf.commons.elements.TestPlan) File(java.io.File) MapperTestplan(de.simpleworks.staf.commons.mapper.elements.MapperTestplan) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException)

Example 3 with TestPlan

use of de.simpleworks.staf.commons.elements.TestPlan in project staf by simpleworks-gmbh.

the class STAFSurefirePlugin method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (getProject() == null) {
        throw new MojoExecutionException("project can't be null.");
    }
    final List<TestPlan> testPlans = getTestPlans(file);
    if (Convert.isEmpty(testPlans)) {
        STAFSurefirePlugin.logger.info("no test plans found.");
        return;
    }
    final List<Class<?>> testCaseClasses = new ArrayList<>();
    try {
        final TestcaseFinder finder = STAFSurefirePlugin.createTestcaseFinder(getProject());
        final TestplanValidator validator = new TestplanValidator(finder);
        for (final TestPlan testPlan : testPlans) {
            testCaseClasses.addAll(validator.validate(testPlan));
        }
    } catch (final SystemException ex) {
        final String msg = "can't add implementation to test plan.";
        STAFSurefirePlugin.logger.error(msg, ex);
        throw new MojoFailureException(msg);
    }
    if (Convert.isEmpty(testCaseClasses)) {
        STAFSurefirePlugin.logger.info("no testcases were defined, will execute tests, from the command line.");
        return;
    }
    setTest(String.join(STAFSurefirePlugin.TEST_CLASSES_DELIMETER, testCaseClasses.stream().map(clazz -> clazz.getName()).collect(Collectors.toList())));
    super.execute();
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) SurefirePlugin(org.apache.maven.plugin.surefire.SurefirePlugin) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) TestPlan(de.simpleworks.staf.commons.elements.TestPlan) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MavenProject(org.apache.maven.project.MavenProject) LifecyclePhase(org.apache.maven.plugins.annotations.LifecyclePhase) MapperTestplan(de.simpleworks.staf.commons.mapper.elements.MapperTestplan) ResolutionScope(org.apache.maven.plugins.annotations.ResolutionScope) LogManager(org.apache.logging.log4j.LogManager) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) Convert(de.simpleworks.staf.commons.utils.Convert) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SystemException(de.simpleworks.staf.commons.exceptions.SystemException) TestPlan(de.simpleworks.staf.commons.elements.TestPlan) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with TestPlan

use of de.simpleworks.staf.commons.elements.TestPlan in project staf by simpleworks-gmbh.

the class UploadResultMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (UploadResultMojo.logger.isInfoEnabled()) {
        UploadResultMojo.logger.info(String.format("start update test plan based on: '%s'.", testplanFile));
    }
    init();
    try {
        final Map<String, TestcaseReport> reports = readResults();
        final List<TestPlan> testPlans = readTestPlan();
        final StringBuilder builder = new StringBuilder();
        for (final TestPlan testPlan : testPlans) {
            try {
                upload(testPlan, reports);
            } catch (final SystemException ex) {
                final String message = String.format("can't update test plan: '%s'.", testPlan.getId());
                UploadResultMojo.logger.error(message, ex);
                builder.append(", '").append(ex.getMessage()).append("'");
            }
        }
        if (2 < builder.length()) {
            throw new MojoExecutionException(String.format("can't update test plan(s): %s.", builder.substring(2)));
        }
    } catch (final SystemException ex) {
        final String message = String.format("can't update update test plan based on: '%s'.", testplanFile);
        UploadResultMojo.logger.error(message, ex);
        throw new MojoExecutionException(message);
    }
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TestPlan(de.simpleworks.staf.commons.elements.TestPlan) TestcaseReport(de.simpleworks.staf.commons.report.TestcaseReport) MapperTestcaseReport(de.simpleworks.staf.commons.mapper.report.MapperTestcaseReport)

Example 5 with TestPlan

use of de.simpleworks.staf.commons.elements.TestPlan in project staf by simpleworks-gmbh.

the class DebugTestPlanStart method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (DebugTestPlanStart.logger.isInfoEnabled()) {
        DebugTestPlanStart.logger.info(String.format("start test plan: '%s'.", testPlanId));
    }
    try {
        clientNG.moveTestPlanToNextIteration(testPlanId);
        final TestPlan testPlan = clientNG.readTestPlan(testPlanId);
        clientNG.startTestPlan(testPlan);
        final File file = new File(fileName);
        if (DebugTestPlanStart.logger.isInfoEnabled()) {
            DebugTestPlanStart.logger.info(String.format("write test plan into file: '%s'.", file));
        }
        UtilsIO.deleteFile(file);
        new MapperTestplan().write(file, Arrays.asList(testPlan));
    } catch (final SystemException ex) {
        final String message = String.format("can't start test plan: '%s'.", testPlanId);
        DebugTestPlanStart.logger.error(message, ex);
        throw new MojoExecutionException(message);
    }
}
Also used : SystemException(de.simpleworks.staf.commons.exceptions.SystemException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TestPlan(de.simpleworks.staf.commons.elements.TestPlan) File(java.io.File) MapperTestplan(de.simpleworks.staf.commons.mapper.elements.MapperTestplan)

Aggregations

TestPlan (de.simpleworks.staf.commons.elements.TestPlan)13 SystemException (de.simpleworks.staf.commons.exceptions.SystemException)11 File (java.io.File)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 MapperTestplan (de.simpleworks.staf.commons.mapper.elements.MapperTestplan)8 MojoFailureException (org.apache.maven.plugin.MojoFailureException)5 MapperTestcaseReport (de.simpleworks.staf.commons.mapper.report.MapperTestcaseReport)3 TestcaseReport (de.simpleworks.staf.commons.report.TestcaseReport)3 Convert (de.simpleworks.staf.commons.utils.Convert)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 LogManager (org.apache.logging.log4j.LogManager)3 Issue (com.atlassian.jira.rest.client.api.domain.Issue)2 Inject (com.google.inject.Inject)2 Named (com.google.inject.name.Named)2 JsonPath (com.jayway.jsonpath.JsonPath)2 TestCase (de.simpleworks.staf.commons.elements.TestCase)2 Arrays (edu.emory.mathcs.backport.java.util.Arrays)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2