Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to use CukesHttpPlugin #137

Open
Kidlike opened this issue Jun 5, 2018 · 4 comments
Open

Impossible to use CukesHttpPlugin #137

Kidlike opened this issue Jun 5, 2018 · 4 comments

Comments

@Kidlike
Copy link

Kidlike commented Jun 5, 2018

I'm trying to write a plugin for cukes-rest but I can't seem to register it.

@Singleton
public class PluginImpl implements CukesHttpPlugin {

    @Override
    public void beforeRequest(RequestSpecification requestSpecification) {
        System.out.println("====== beforeRequest ======");
        requestSpecification
            .filter(new RequestLoggingFilter())
            .filter(new ResponseLoggingFilter());
    }

    // ...other empty overrides...
}

It doesn't seem to have any effect.

I also tried with/without this:

@CukesInjectableModule
public class PluginConf extends AbstractCukesHttpModule {

    @Override
    protected void configure() {
        System.out.println("====== PluginConf ======");
        registerHttpPlugin(PluginImpl.class);
    }
}

Which didn't make any difference either.

EDIT: This is how my main test class looks like:

@RunWith(Cucumber.class)
@CucumberOptions(
    format = {"pretty", "json:target/cucumber.json", "lv.ctco.cukes.core.formatter.CukesJsonFormatter:target/cucumber2.json"},
    glue = "lv.ctco.cukes",
    strict = true
)
public class RunCucumberTest {

I'm using IntelliJ IDEA, and I've tried running the feature files directly, and from the main test class.

@Kidlike Kidlike changed the title How to use CukesHttpPlugin Impossible to use CukesHttpPlugin Aug 3, 2018
@Kidlike
Copy link
Author

Kidlike commented Aug 3, 2018

After some investigation I found out that the @CukesInjectableModule annotation is only possible to be used in classes under the lv.ctco.cukes package.

This should be at least configurable in cukes.properties, so that anyone can register a plugin.

Relevant snippet:

private void addExternalModules() {
        Reflections reflections = new Reflections("lv.ctco.cukes");
        for (Class targetClass : reflections.getTypesAnnotatedWith(CukesInjectableModule.class)) {
            try {
                Constructor<Module> constructor = targetClass.getConstructor();
                Module module = constructor.newInstance();
                addModule(module);
            } catch (Exception e) {
                throw new CukesRuntimeException("Unable to add External Module to Guice");
            }
        }
    }

https://github.com/ctco/cukes/blob/master/cukes-core/src/main/java/lv/ctco/cukes/core/internal/di/SingletonObjectFactory.java#L77

@JekabsK
Copy link

JekabsK commented Sep 12, 2018

Have you registered your plugin in cukes.properties file under cukes.plugins property?

@Kidlike
Copy link
Author

Kidlike commented Sep 12, 2018

Yes I did try that too, made no difference whatsoever.

The only solution that worked was to move the PluginRegistry under lv.ctco.cukes:

package lv.ctco.cukes;

import com.tamedia.cms.uat.plugins.AuthenticationPlugin;

import lv.ctco.cukes.core.extension.CukesInjectableModule;
import lv.ctco.cukes.http.extension.AbstractCukesHttpModule;

@CukesInjectableModule
public class PluginRegistry extends AbstractCukesHttpModule {

    @Override
    protected void configure() {
        registerHttpPlugin(AuthenticationPlugin.class);
    }
}

@michaelruocco
Copy link

Any update on this at all? I have hit this problem too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants