Search in sources :

Example 1 with Resource

use of cucumber.runtime.io.Resource in project cucumber-jvm by cucumber.

the class CucumberFeature method loadFromFeaturePath.

private static void loadFromFeaturePath(FeatureBuilder builder, ResourceLoader resourceLoader, String featurePath, final List<Object> filters, boolean failOnNoResource) {
    PathWithLines pathWithLines = new PathWithLines(featurePath);
    ArrayList<Object> filtersForPath = new ArrayList<Object>(filters);
    filtersForPath.addAll(pathWithLines.lines);
    Iterable<Resource> resources = resourceLoader.resources(pathWithLines.path, ".feature");
    if (failOnNoResource && !resources.iterator().hasNext()) {
        throw new IllegalArgumentException("No resource found for: " + pathWithLines.path);
    }
    for (Resource resource : resources) {
        builder.parse(resource, filtersForPath);
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource)

Example 2 with Resource

use of cucumber.runtime.io.Resource in project cucumber-jvm by cucumber.

the class FeatureBuilderTest method works_when_path_and_uri_are_the_same.

@Test
public void works_when_path_and_uri_are_the_same() throws IOException {
    char fileSeparatorChar = '/';
    String featurePath = "path" + fileSeparatorChar + "foo.feature";
    Resource resource = createResourceMock(featurePath);
    List<CucumberFeature> features = new ArrayList<CucumberFeature>();
    FeatureBuilder builder = new FeatureBuilder(features, fileSeparatorChar);
    builder.parse(resource, NO_FILTERS);
    assertEquals(1, features.size());
    assertEquals(featurePath, features.get(0).getPath());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Resource(cucumber.runtime.io.Resource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with Resource

use of cucumber.runtime.io.Resource in project cucumber-jvm by cucumber.

the class FeatureBuilderTest method createResourceMock.

private Resource createResourceMock(String featurePath) throws IOException {
    Resource resource = mock(Resource.class);
    when(resource.getPath()).thenReturn(featurePath);
    ByteArrayInputStream feature = new ByteArrayInputStream("Feature: foo".getBytes("UTF-8"));
    when(resource.getInputStream()).thenReturn(feature);
    return resource;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(cucumber.runtime.io.Resource)

Example 4 with Resource

use of cucumber.runtime.io.Resource in project cucumber-jvm by cucumber.

the class AndroidResourceLoader method resources.

@Override
public Iterable<Resource> resources(final String path, final String suffix) {
    try {
        final List<Resource> resources = new ArrayList<Resource>();
        final AssetManager assetManager = context.getAssets();
        addResourceRecursive(resources, assetManager, path, suffix);
        return resources;
    } catch (final IOException e) {
        throw new CucumberException("Error loading resources from " + path + " with suffix " + suffix, e);
    }
}
Also used : AssetManager(android.content.res.AssetManager) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) IOException(java.io.IOException) CucumberException(cucumber.runtime.CucumberException)

Example 5 with Resource

use of cucumber.runtime.io.Resource in project cucumber-jvm by cucumber.

the class GosuBackend method loadGlue.

@Override
public void loadGlue(Glue glue, List<String> gluePaths) {
    this.glue = glue;
    GlueSource source = new GlueSource();
    for (String gluePath : gluePaths) {
        for (Resource glueScript : resourceLoader.resources(gluePath, ".gsp")) {
            source.addGlueScript(glueScript);
        }
    }
    Gosu gosu = new Gosu();
    gosu.start(source.toArgInfo());
}
Also used : Resource(cucumber.runtime.io.Resource) Gosu(gw.lang.Gosu)

Aggregations

Resource (cucumber.runtime.io.Resource)17 ArrayList (java.util.ArrayList)9 CucumberFeature (cucumber.runtime.model.CucumberFeature)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)3 CucumberException (cucumber.runtime.CucumberException)2 FeatureBuilder (cucumber.runtime.FeatureBuilder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AssetManager (android.content.res.AssetManager)1 ResourceLoader (cucumber.runtime.io.ResourceLoader)1 DocString (gherkin.formatter.model.DocString)1 Binding (groovy.lang.Binding)1 Script (groovy.lang.Script)1 Gosu (gw.lang.Gosu)1 Map (java.util.Map)1 SWClassLoader (org.apache.openejb.arquillian.openejb.SWClassLoader)1 InvokerInvocationException (org.codehaus.groovy.runtime.InvokerInvocationException)1 Archive (org.jboss.shrinkwrap.api.Archive)1