Java Code Examples for com.intuit.karate.FileUtils#scanForFeatureFiles()

The following examples show how to use com.intuit.karate.FileUtils#scanForFeatureFiles() . 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: Karate.java    From karate with MIT License 6 votes vote down vote up
public Karate(Class<?> clazz) throws InitializationError, IOException {
    super(clazz);
    List<FrameworkMethod> testMethods = getTestClass().getAnnotatedMethods(Test.class);
    if (!testMethods.isEmpty()) {
        logger.warn("WARNING: there are methods annotated with '@Test', they will NOT be run when using '@RunWith(Karate.class)'");
    }
    RunnerOptions options = RunnerOptions.fromAnnotationAndSystemProperties(clazz);
    List<Resource> resources = FileUtils.scanForFeatureFiles(options.getFeatures(), clazz.getClassLoader());
    children = new ArrayList(resources.size());
    featureMap = new HashMap(resources.size());
    for (Resource resource : resources) {
        Feature feature = FeatureParser.parse(resource);
        feature.setCallName(options.getName());
        feature.setCallLine(resource.getLine());
        children.add(feature);
    }
    tagSelector = Tags.fromKarateOptionsTags(options.getTags());
}
 
Example 2
Source File: JarLoadingTest.java    From karate with MIT License 6 votes vote down vote up
@Test
public void testRunningFromJarFile() throws Exception {
    ClassLoader cl = getJarClassLoader1();
    Class main = cl.loadClass("demo.jar1.Main");
    Method meth = main.getMethod("hello");
    Object result = meth.invoke(null);
    assertEquals("hello world", result);
    List<Resource> list = FileUtils.scanForFeatureFiles(Collections.singletonList("classpath:demo"), cl);
    assertEquals(4, list.size());
    logger.debug("resources: {}", list);
    list = FileUtils.scanForFeatureFiles(Collections.singletonList("classpath:demo/jar1/caller.feature"), cl);
    assertEquals(1, list.size());
    Resource resource = list.get(0);
    assertTrue(FileUtils.isJarPath(resource.getPath().toUri()));
    Path path = FileUtils.fromRelativeClassPath("classpath:demo/jar1/caller.feature", cl);
    String relativePath = FileUtils.toRelativeClassPath(path, cl);
    assertEquals("classpath:demo/jar1/caller.feature", relativePath);
    Feature feature = FeatureParser.parse(resource);
    Thread.currentThread().setContextClassLoader(cl);
    Map<String, Object> map = Runner.runFeature(feature, null, false);
    assertEquals(true, map.get("success"));
}
 
Example 3
Source File: AllKarateFeaturesTest.java    From karate with MIT License 5 votes vote down vote up
@Test
public void testParsingAllFeaturesInKarate() {
    List<Resource> files = FileUtils.scanForFeatureFiles(false, "..", null);
    logger.debug("found files count: {}", files.size());
    assertTrue(files.size() > 200);
    for (Resource file : files) {
        logger.trace("parsing: {}", file.getRelativePath());
        FeatureParser.parse(file);
    }
}