How to use findFiles method of com.consol.citrus.util.FileUtils class

Best Citrus code snippet using com.consol.citrus.util.FileUtils.findFiles

Source:TestCaseService.java Github

copy

Full Screen

...61 * @return62 */63 public List<TestGroup> getTestPackages(Project project) {64 Map<String, TestGroup> testPackages = new LinkedHashMap<>();65 List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));66 List<Test> tests = testProviders.parallelStream()67 .flatMap(provider -> provider.findTests(project, sourceFiles).stream())68 .collect(Collectors.toList());69 for (Test test : tests) {70 if (!testPackages.containsKey(test.getPackageName())) {71 TestGroup testPackage = new TestGroup();72 testPackage.setName(test.getPackageName());73 testPackages.put(test.getPackageName(), testPackage);74 }75 testPackages.get(test.getPackageName()).getTests().add(test);76 }77 return Arrays.asList(testPackages.values().toArray(new TestGroup[testPackages.size()]));78 }79 /**80 * List test names of latest, meaning newest or last modified tests in project.81 *82 * @param project83 * @return84 */85 public List<TestGroup> getLatest(Project project, int limit) {86 Map<String, TestGroup> grouped = new LinkedHashMap<>();87 final List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()))88 .stream()89 .sorted((f1, f2) -> f1.lastModified() >= f2.lastModified() ? -1 : 1)90 .limit(limit)91 .collect(Collectors.toList());92 List<Test> tests = testProviders.parallelStream()93 .flatMap(provider -> provider.findTests(project, sourceFiles).stream())94 .collect(Collectors.toList());95 for (Test test : tests) {96 if (!grouped.containsKey(test.getClassName())) {97 TestGroup testGroup = new TestGroup();98 testGroup.setName(test.getClassName());99 grouped.put(test.getClassName(), testGroup);100 }101 grouped.get(test.getClassName()).getTests().add(test);102 }103 return Arrays.asList(grouped.values().toArray(new TestGroup[grouped.size()]));104 }105 /**106 * Finds test for given package, class and method name.107 * @param project108 * @param packageName109 * @param className110 * @return111 */112 public Test findTest(Project project, String packageName, String className) {113 return findTest(project, packageName, className, null);114 }115 /**116 * Finds test for given package, class and method name.117 * @param project118 * @param packageName119 * @param className120 * @param methodName121 * @return122 */123 public Test findTest(Project project, String packageName, String className, String methodName) {124 final FileSystemResource sourceFile = new FileSystemResource(project.getJavaDirectory() + packageName.replace('.', File.separatorChar) + System.getProperty("file.separator") + className + ".java");125 if (!sourceFile.exists()) {126 throw new ApplicationRuntimeException("Unable to find test source file: " + packageName + "." + className + " in " + project.getJavaDirectory());127 }128 Optional<Test> test = testProviders.parallelStream()129 .flatMap(provider -> provider.findTests(project, Collections.singletonList(sourceFile.getFile())).stream())130 .filter(candidate -> methodName == null || methodName.equals(candidate.getMethodName()))131 .findFirst();132 if (test.isPresent()) {133 return test.get();134 } else {135 throw new ApplicationRuntimeException("Unable to find test: " + packageName + "." + className + "#" + methodName);136 }137 }138 /**139 * Gets test case details such as status, description, author.140 * @param project141 * @param test142 * @return143 */144 public TestDetail getTestDetail(Project project, Test test) {145 TestDetail testDetail = new TestDetail(test);146 TestcaseModel testModel = getTestModel(project, testDetail);147 if (testModel.getVariables() != null) {148 for (VariablesModel.Variable variable : testModel.getVariables().getVariables()) {149 testDetail.getVariables().add(new Property<>(variable.getName(), variable.getValue()));150 }151 }152 if (testModel.getDescription() != null) {153 testDetail.setDescription(testModel.getDescription().trim().replaceAll(" +", " ").replaceAll("\t", ""));154 }155 if (testModel.getMetaInfo() != null) {156 testDetail.setAuthor(testModel.getMetaInfo().getAuthor());157 if (testModel.getMetaInfo().getLastUpdatedOn() != null) {158 testDetail.setLastModified(testModel.getMetaInfo().getLastUpdatedOn().getTimeInMillis());159 }160 }161 if (test.getType().equals(TestType.JAVA)) {162 testDetail.setFile(project.getJavaDirectory() + test.getPackageName().replace('.', File.separatorChar) + File.separator + test.getClassName());163 } else if (test.getType().equals(TestType.XML)) {164 testDetail.setFile(project.getXmlDirectory() + test.getPackageName().replace('.', File.separatorChar) + File.separator + FilenameUtils.getBaseName(test.getName()));165 } else if (test.getType().equals(TestType.CUCUMBER)) {166 testDetail.setFile(project.getXmlDirectory() + test.getPackageName().replace('.', File.separatorChar) + File.separator + test.getMethodName());167 } else if (test.getType().equals(TestType.GROOVY)) {168 testDetail.setFile(project.getXmlDirectory() + test.getPackageName().replace('.', File.separatorChar) + File.separator + FilenameUtils.getBaseName(test.getName()));169 } else {170 throw new ApplicationRuntimeException("Unsupported test type: " + test.getType());171 }172 if (testModel.getActions() != null) {173 for (Object actionType : testModel.getActions().getActionsAndSendsAndReceives()) {174 TestActionModel model = null;175 for (TestActionConverter converter : actionConverter) {176 if (converter.getSourceModelClass().isInstance(actionType)) {177 model = converter.convert(actionType);178 break;179 }180 }181 if (model == null) {182 if (actionType.getClass().getAnnotation(XmlRootElement.class) == null) {183 log.info(actionType.getClass().getName());184 } else {185 model = new ActionConverter(actionType.getClass().getAnnotation(XmlRootElement.class).name()).convert(actionType);186 }187 }188 if (model != null) {189 testDetail.getActions().add(model);190 }191 }192 }193 return testDetail;194 }195 /**196 * Gets the source code for the given test.197 * @param filePath198 * @return199 */200 public String getSourceCode(Project project, String filePath) {201 try {202 String sourcePath = project.getAbsolutePath(filePath);203 if (new File(sourcePath).exists()) {204 return FileUtils.readToString(new FileInputStream(sourcePath));205 } else {206 throw new ApplicationRuntimeException("Unable to find source code for path: " + sourcePath);207 }208 } catch (IOException e) {209 throw new ApplicationRuntimeException("Failed to load test case source code", e);210 }211 }212 /**213 * Updates the source code for the given test.214 * @param filePath215 * @param sourceCode216 * @return217 */218 public void updateSourceCode(Project project, String filePath, String sourceCode) {219 String sourcePath = project.getAbsolutePath(filePath);220 FileUtils.writeToFile(sourceCode, new File(sourcePath));221 }222 /**223 * Get total number of tests in project.224 * @param project225 * @return226 */227 public long getTestCount(Project project) {228 long testCount = 0L;229 try {230 List<File> sourceFiles = FileUtils.findFiles(project.getJavaDirectory(), StringUtils.commaDelimitedListToSet(project.getSettings().getJavaFilePattern()));231 for (File sourceFile : sourceFiles) {232 String sourceCode = FileUtils.readToString(new FileSystemResource(sourceFile));233 testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusTest");234 testCount += StringUtils.countOccurrencesOf(sourceCode, "@CitrusXmlTest");235 }236 } catch (IOException e) {237 log.warn("Failed to read Java source files - list of test cases for this project is incomplete", e);238 }239 return testCount;240 }241 /**242 * Reads either XML or Java test definition to model class.243 * @param project244 * @return...

Full Screen

Full Screen

Source:CucumberJUnit4TestProvider.java Github

copy

Full Screen

...43 try {44 String sourceCode = FileUtils.readToString(new FileSystemResource(sourceFile));45 Matcher matcher = Pattern.compile("@RunWith\\(Cucumber\\.class\\)").matcher(sourceCode);46 if (matcher.find()) {47 List<File> featureFiles = FileUtils.findFiles(project.getXmlDirectory() + packageName.replaceAll("\\.", File.separator), StringUtils.commaDelimitedListToSet("/**/*.feature"));48 for (File featureFile : featureFiles) {49 Test test = new Test();50 test.setType(TestType.CUCUMBER);51 test.setClassName(className);52 test.setPackageName(packageName);53 test.setMethodName(FilenameUtils.getBaseName(featureFile.getName()));54 test.setName(className + "." + test.getMethodName());55 tests.add(test);56 }57 }58 } catch (IOException e) {59 log.error("Failed to read test source file", e);60 }61 return tests;...

Full Screen

Full Screen

Source:CleanupUtils.java Github

copy

Full Screen

...19import java.util.Set;20public class CleanupUtils {21 public void deleteFiles(final String startDir, final Set<String> fileNamePatterns){22 //noinspection ResultOfMethodCallIgnored23 FileUtils.findFiles(startDir, fileNamePatterns).24 forEach(File::delete);25 }26 public void deleteFile(File fileToDelete){27 if(fileToDelete.exists()){28 //noinspection ResultOfMethodCallIgnored29 fileToDelete.delete();30 }31 }32}...

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.util;2import java.io.File;3import java.util.List;4import org.testng.Assert;5import org.testng.annotations.Test;6public class FileUtilsTest {7 public void testFindFiles() {8 List<File> files = FileUtils.findFiles("src/test/resources/com/consol/citrus/util");9 Assert.assertEquals(files.size(), 3);10 }11}12[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ citrus-util ---13List<File> files = FileUtils.findFiles(".");14List<File> files = FileUtils.findFiles("..");15List<File> files = FileUtils.findFiles("src/test/resources/com/consol/citrus/util");16List<File> files = FileUtils.findFiles("src/test/resources/com/consol/citrus/util", true);

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.util;2import java.io.File;3import java.io.IOException;4import java.util.List;5public class FindFiles {6 public static void main(String[] args) throws IOException {7 FileUtils fileUtils = new FileUtils();8 List<File> files = fileUtils.findFiles(new File("C:\\Users\\admin\\Desktop\\New folder"), "java");9 for (File file : files) {10 System.out.println(file.getName());11 }12 }13}14package com.consol.citrus.util;15import java.io.File;16import java.io.IOException;17import java.util.List;18public class FindFiles {19 public static void main(String[] args) throws IOException {20 FileUtils fileUtils = new FileUtils();21 List<File> files = fileUtils.findFiles(new File("C:\\Users\\admin\\Desktop\\New folder"), "java", true);22 for (File file : files) {23 System.out.println(file.getName());24 }25 }26}27package com.consol.citrus.util;28import java.io.File;29import java.io.IOException;30import java.util.List;31public class FindFiles {32 public static void main(String[] args) throws IOException {33 FileUtils fileUtils = new FileUtils();34 List<File> files = fileUtils.findFiles(new File("C:\\Users\\admin\\Desktop\\New folder"), "java", false);35 for (File file : files) {36 System.out.println(file.getName());37 }38 }39}40package com.consol.citrus.util;41import java.io.File;42import java.io.IOException;43import java.util.List;44public class FindFiles {45 public static void main(String[] args) throws IOException {46 FileUtils fileUtils = new FileUtils();47 List<File> files = fileUtils.findFiles(new File("C:\\Users\\admin\\Desktop\\New folder"), "java", true, 2

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.util;2import java.util.ArrayList;3import java.util.List;4import java.io.File;5public class FileUtilsTest {6 public static void main(String[] args) {7 List<String> fileNames = new ArrayList<String>();8 fileNames = FileUtils.findFiles("C:\\Users\\user\\Desktop\\citrus", ".java");9 for (String fileName : fileNames) {10 System.out.println(fileName);11 }12 }13}14package com.consol.citrus.util;15import java.util.ArrayList;16import java.util.List;17import java.io.File;18public class FileUtilsTest {19 public static void main(String[] args) {20 List<String> fileNames = new ArrayList<String>();21 fileNames = FileUtils.findFiles("C:\\Users\\user\\Desktop\\citrus", ".java", true);22 for (String fileName : fileNames) {23 System.out.println(fileName);24 }25 }26}27package com.consol.citrus.util;28import java.util.ArrayList;29import java.util.List;30import java.io.File;31public class FileUtilsTest {32 public static void main(String[] args) {33 List<String> fileNames = new ArrayList<String>();34 fileNames = FileUtils.findFiles("C:\\Users\\user\\Desktop\\citrus", ".java", false);35 for (String fileName : fileNames

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.util;2import java.io.File;3import java.util.List;4public class FindFiles {5public static void main(String[] args) {6List<File> files = FileUtils.findFiles("C:\\", "xml");7for (File file : files) {8System.out.println(file.getAbsolutePath());9}10}11}12C:\Documents and Settings\All Users\Documents\My Music\Album Art_{4E1B5E7E-8F4D-4B51-8C8A-FA1F7A9F6F9D}_Large.jpg13C:\Documents and Settings\All Users\Documents\My Music\Album Art_{4E1B5E7E-8F4D-4B51-8C8A-FA1F7A9F6F9D}_Small.jpg14C:\Documents and Settings\All Users\Documents\My Music\Album Art_{4E1B5E7E-8F4D-4B51-8C8A-FA1F7A9F6F9D}_Source.jpg15C:\Documents and Settings\All Users\Documents\My Music\Album Art_{4E1B5E7E-8F4D-4B51-8C8A-FA1F7A9F6F9D}_Thumb.jpg16C:\Documents and Settings\All Users\Documents\My Music\Album Art_{A3A2E3C6-8E6D-4A7E-B6A1-7A8A6E1A7F9F}_Large.jpg17C:\Documents and Settings\All Users\Documents\My Music\Album Art_{A3A2E3C6-8E6D-4A7E-B6A1-7A8A6E1A7F9F}_Small.jpg18C:\Documents and Settings\All Users\Documents\My Music\Album Art_{A3A2E3C6-8E6D-4A7E-B6A1-7A8A6E1A7F9F}_Source.jpg19C:\Documents and Settings\All Users\Documents\My Music\Album Art_{A3A2E3C6-8E6D-4A7E-B6A1-7A8

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.util;2import org.testng.annotations.Test;3import java.io.File;4import java.util.List;5import java.util.regex.Pattern;6import java.util.regex.PatternSyntaxException;7public class FindFilesTest {8public void testFindFiles() {9File dir = new File("/home/abc");10List<File> files = FileUtils.findFiles(dir, Pattern.compile(".*\\.java$"));11for (File file : files) {12System.out.println(file.getName());13}14}15}

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.util.FileUtils;2import java.util.List;3public class findFiles {4public static void main(String[] args) {5String path = "/home/citrus";6String fileName = "test.txt";7List fileList = FileUtils.findFiles(path, fileName);8System.out.println(fileList);9}10}

Full Screen

Full Screen

findFiles

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 File file = new File("C:\\Users\\user\\Desktop\\test");4 List<File> list = FileUtils.findFiles(file, new PatternFileFilter(".*\\.txt"));5 for (File f : list) {6 System.out.println(f.getAbsolutePath());7 }8 }9}10import java.io.File;11import java.io.IOException;12import java.util.List;13import org.apache.commons.io.filefilter.DirectoryFileFilter;14import org.apache.commons.io.filefilter.IOFileFilter;15import org.apache.commons.io.filefilter.PatternFileFilter;16import org.apache.commons.io.filefilter.TrueFileFilter;17import org.springframework.util.Assert;18import org.springframework.util.CollectionUtils;19public class 5 {20 public static void main(String[] args) throws IOException {21 File file = new File("C:\\Users\\user\\Desktop\\test");22 List<File> list = FileUtils.findFiles(file, new PatternFileFilter(".*\\.txt"), DirectoryFileFilter.INSTANCE);23 for (File f : list) {24 System.out.println(f.getAbsolutePath());25 }26 }27}28import java.io.File;29import java.io.IOException;30import java.util.List;31import org.apache.commons.io.filefilter.DirectoryFileFilter;32import org.apache.commons.io.filefilter.IOFileFilter;33import org.apache.commons.io.filefilter.PatternFileFilter;34import org.apache.commons.io.filefilter.TrueFileFilter;35import org.springframework.util.Assert;36import org.springframework.util.CollectionUtils;37public class 6 {38 public static void main(String[] args) throws IOException {39 File file = new File("C:\\Users\\user\\Desktop\\test");40 List<File> list = FileUtils.findFiles(file, new PatternFileFilter(".*\\.txt"), DirectoryFileFilter.INSTANCE, TrueFileFilter.INSTANCE);41 for (File f : list) {42 System.out.println(f.getAbsolutePath());43 }44 }45}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful