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;
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations