Search in sources :

Example 6 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)

Example 7 with Resource

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

the class CucumberFeatureTest method mockFileResource.

private void mockFileResource(ResourceLoader resourceLoader, String featurePath, String extension, String feature) throws IOException {
    Resource resource = mock(Resource.class);
    when(resource.getPath()).thenReturn(featurePath);
    when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(feature.getBytes("UTF-8")));
    when(resourceLoader.resources(featurePath, extension)).thenReturn(singletonList(resource));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(cucumber.runtime.io.Resource)

Example 8 with Resource

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

the class CucumberFeatureTest method mockFeatureFileResourceForAnyFeaturePath.

private ResourceLoader mockFeatureFileResourceForAnyFeaturePath(String feature) throws IOException {
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    Resource resource = mock(Resource.class);
    when(resource.getPath()).thenReturn("");
    when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(feature.getBytes("UTF-8")));
    when(resourceLoader.resources(anyString(), anyString())).thenReturn(singletonList(resource));
    return resourceLoader;
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(cucumber.runtime.io.Resource)

Example 9 with Resource

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

the class TestFeatureBuilder method feature.

static CucumberFeature feature(final String path, final String source) throws IOException {
    ArrayList<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    FeatureBuilder featureBuilder = new FeatureBuilder(cucumberFeatures);
    featureBuilder.parse(new Resource() {

        @Override
        public String getPath() {
            return path;
        }

        @Override
        public String getAbsolutePath() {
            throw new UnsupportedOperationException();
        }

        @Override
        public InputStream getInputStream() {
            try {
                return new ByteArrayInputStream(source.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getClassName(String extension) {
            throw new UnsupportedOperationException();
        }
    }, new ArrayList<Object>());
    featureBuilder.close();
    return cucumberFeatures.get(0);
}
Also used : FeatureBuilder(cucumber.runtime.FeatureBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CucumberFeature(cucumber.runtime.model.CucumberFeature) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 10 with Resource

use of cucumber.runtime.io.Resource in project tomee by apache.

the class ArchiveResourceIteratorFactory method findResources.

private Collection<Resource> findResources(final String path, final String suffix) {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final Collection<Resource> resources = new ArrayList<Resource>();
    if (SWClassLoader.class.isInstance(loader)) {
        final Collection<Archive<?>> archives = SWClassLoader.class.cast(loader).getArchives();
        final ClassLoader parent = loader.getParent();
        for (final Archive<?> archive : archives) {
            final Map<ArchivePath, Node> content = archive.getContent(new Filter<ArchivePath>() {

                @Override
                public boolean include(final ArchivePath object) {
                    final String currentPath = classloaderPath(object);
                    return !(parent != null && parent.getResource(currentPath) != null) && currentPath.startsWith('/' + path) && currentPath.endsWith(suffix);
                }
            });
            for (final Map.Entry<ArchivePath, Node> entry : content.entrySet()) {
                resources.add(new SWResource(entry.getKey(), entry.getValue()));
            }
        }
    }
    return resources;
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) Node(org.jboss.shrinkwrap.api.Node) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) SWClassLoader(org.apache.openejb.arquillian.openejb.SWClassLoader) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) SWClassLoader(org.apache.openejb.arquillian.openejb.SWClassLoader) Map(java.util.Map)

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