cukes
cukes copied to clipboard
Impossible to use CukesHttpPlugin
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.
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
Have you registered your plugin in cukes.properties file under cukes.plugins
property?
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);
}
}
Any update on this at all? I have hit this problem too.