Java Code Examples for com.consol.citrus.util.FileUtils#findFiles()

The following examples show how to use com.consol.citrus.util.FileUtils#findFiles() . 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: TestCaseService.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Lists all available Citrus test cases grouped in test packages.
 * @param project
 * @return
 */
public List<TestGroup> getTestPackages(Project project) {
    Map<String, TestGroup> testPackages = new LinkedHashMap<>();

    List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));
    List<Test> tests = testProviders.parallelStream()
                                    .flatMap(provider -> provider.findTests(project, sourceFiles).stream())
                                    .collect(Collectors.toList());

    for (Test test : tests) {
        if (!testPackages.containsKey(test.getPackageName())) {
            TestGroup testPackage = new TestGroup();
            testPackage.setName(test.getPackageName());
            testPackages.put(test.getPackageName(), testPackage);
        }

        testPackages.get(test.getPackageName()).getTests().add(test);
    }

    return Arrays.asList(testPackages.values().toArray(new TestGroup[testPackages.size()]));
}
 
Example 2
Source File: TestCaseService.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Get total number of tests in project.
 * @param project
 * @return
 */
public long getTestCount(Project project) {
    long testCount = 0L;
    try {
        List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));
        for (File sourceFile : sourceFiles) {
            String sourceCode = FileUtils.readToString(new FileSystemResource(sourceFile));

            testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusTest");
            testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusXmlTest");
        }
    } catch (IOException e) {
        log.warn("Failed to read Java source files - list of test cases for this project is incomplete", e);
    }

    return testCount;
}
 
Example 3
Source File: JUnit4TestReportLoader.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Access file resource representing the TestNG results file.
 * @param activeProject
 * @return
 */
private Resource getTestResultsFile(Project activeProject) {
    FileSystemResource testSuiteFile = new FileSystemResource(activeProject.getProjectHome() + "/target/failsafe-reports/TEST-TestSuite.xml");
    if (testSuiteFile.exists()) {
        return testSuiteFile;
    }

    if (new File(activeProject.getProjectHome() + "/target/failsafe-reports").exists()) {
        List<File> testCaseFiles = FileUtils.findFiles(activeProject.getProjectHome() + "/target/failsafe-reports", Collections.singleton("/TEST-*.xml"));
        if (!CollectionUtils.isEmpty(testCaseFiles)) {
            return new FileSystemResource(testCaseFiles.get(0));
        }
    }

    return null;
}
 
Example 4
Source File: CucumberJUnit4TestProvider.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Test> findTests(Project project, File sourceFile, String packageName, String className) {
    List<Test> tests = new ArrayList<>();

    try {
        String sourceCode = FileUtils.readToString(new FileSystemResource(sourceFile));
        Matcher matcher = Pattern.compile("@RunWith\\(Cucumber\\.class\\)").matcher(sourceCode);
        if (matcher.find()) {
            List<File> featureFiles = FileUtils.findFiles(project.getXmlDirectory() + packageName.replaceAll("\\.", File.separator), StringUtils.commaDelimitedListToSet("/**/*.feature"));

            for (File featureFile : featureFiles) {
                Test test = new Test();
                test.setType(TestType.CUCUMBER);
                test.setClassName(className);
                test.setPackageName(packageName);
                test.setMethodName(FilenameUtils.getBaseName(featureFile.getName()));

                test.setName(className + "." + test.getMethodName());

                tests.add(test);
            }
        }
    } catch (IOException e) {
        log.error("Failed to read test source file", e);
    }

    return tests;
}