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

TypeRegistryConfigurer with @Autowired #1516

Closed
bojanv55 opened this issue Dec 12, 2018 · 9 comments
Closed

TypeRegistryConfigurer with @Autowired #1516

bojanv55 opened this issue Dec 12, 2018 · 9 comments
Labels
🙏 help wanted Help wanted - not prioritized by core team ⚡ enhancement Request for new functionality

Comments

@bojanv55
Copy link

bojanv55 commented Dec 12, 2018

Is it possible to use @Autowired spring annotation inside TypeRegistryConfigurer?

@Component
public class TypeRegistryConfiguration implements TypeRegistryConfigurer {

	private SpecifierMapper specifierMapper;

	public TypeRegistryConfiguration(SpecifierMapper specifierMapper){
		this.specifierMapper = specifierMapper;
	}

	@Override
...

Currently I get an error:

cucumber.runtime.CucumberException: java.lang.NoSuchMethodException: com.a.b.TypeRegistryConfiguration.<init>()

	at cucumber.runtime.Reflections.newInstance(Reflections.java:53)
	at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:35)
	at cucumber.runtime.Reflections.instantiateExactlyOneSubclass(Reflections.java:17)
	at cucumber.runtime.BackendModuleBackendSupplier.loadBackends(BackendModuleBackendSupplier.java:46)
	at cucumber.runtime.BackendModuleBackendSupplier.get(BackendModuleBackendSupplier.java:37)
	at cucumber.runner.ThreadLocalRunnerSupplier.createRunner(ThreadLocalRunnerSupplier.java:44)
	at cucumber.runner.ThreadLocalRunnerSupplier.access$000(ThreadLocalRunnerSupplier.java:15)
	at cucumber.runner.ThreadLocalRunnerSupplier$1.initialValue(ThreadLocalRunnerSupplier.java:24)
	at cucumber.runner.ThreadLocalRunnerSupplier$1.initialValue(ThreadLocalRunnerSupplier.java:21)
	at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
	at java.lang.ThreadLocal.get(ThreadLocal.java:170)
	at cucumber.runner.ThreadLocalRunnerSupplier.get(ThreadLocalRunnerSupplier.java:40)
	at cucumber.api.junit.Cucumber.<init>(Cucumber.java:108)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
	at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.NoSuchMethodException: com.a.b.TypeRegistryConfiguration.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.getConstructor(Class.java:1825)
	at cucumber.runtime.Reflections.newInstance(Reflections.java:45)
	... 26 more
@mpkorstanje
Copy link
Contributor

Currently not. To make use of this the type registry has to be created by the ObjectFactory. However the type registry is not created by the ObjectFactory because the ObjectFactory is restricted to the JavaBackend.

To fix this some refactoring is needed. This refactoring is done in develop-v5/BackendServiceLoader. If some one is willing to do the work there is no reason this can't be moved into the current v4 branch.

@mpkorstanje mpkorstanje added ⚡ enhancement Request for new functionality 🙏 help wanted Help wanted - not prioritized by core team labels Dec 12, 2018
@mpkorstanje
Copy link
Contributor

Additionally the creation of the TypeRegistryConfigurer would have to be delayed until the Runner uses buildBackendWorlds. In buildBackendWorlds 1) the object factory would have to be started, 2) the backend should discover all glue, then the type registry should be created and configured.

@davidyscott
Copy link

Hi! Just wondering if this has been prioritized in any way? Working around this issue isn't too hard, but it's ugly.

@mpkorstanje
Copy link
Contributor

From the read me:

Please bear in mind that this project is almost entirely developed by volunteers. If you do not provide the implementation yourself (or pay someone to do it for you), the bug might never get fixed.

And in this case it would require a significant refactor as mentioned before.

@mpkorstanje
Copy link
Contributor

I'm going to consider this resolved by #1458.

@bojanv55
Copy link
Author

I guess this should be the way of using this new functionality?

@TestConfiguration
public class CucumberConfig {

	@Autowired
	private SpecifierMapper specifierMapper;

	@ParameterType(name="specifierName", value="\"(.*)\"")
	public Specifier getS(String s) {
		return specifierMapper.specifierNameToSpecifier(s);
	}

}

Question - are there any jars I can include in my project to try this? I tried with jitpack

<dependency>
            <groupId>com.github.cucumber.cucumber-jvm</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>master-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.cucumber.cucumber-jvm</groupId>
            <artifactId>cucumber-spring</artifactId>
            <version>master-SNAPSHOT</version>
            <scope>test</scope>
        </dependency>

But complains related to

java.lang.NoClassDefFoundError: gherkin/ParserException

	at io.cucumber.core.feature.FeatureBuilder.parse(FeatureBuilder.java:24)
	at io.cucumber.core.feature.FeatureLoader.loadFromFeaturePath(FeatureLoader.java:35)
	at io.cucumber.core.feature.FeatureLoader.load(FeatureLoader.java:22)
	at io.cucumber.core.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:34)
	at io.cucumber.junit.Cucumber.<init>(Cucumber.java:142)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
	at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: gherkin.ParserException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 19 more

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Sep 16, 2019

You may have to build cucumber locally first. We're no longer publishing snapshots - it's rather hard to keep the credentials secure.

Also might be worth checking you're not explicitly overriding any transitive dependencies.

@bojanv55
Copy link
Author

bojanv55 commented Sep 17, 2019

After changing project SDK version and updating maven, it works now. Thanks.
I just needed to remove that @TestConfiguration since it complained about duplicating spring beans.

Do you know any date or current plan - when this version should be available on maven central repo?

@mpkorstanje
Copy link
Contributor

Not really. This project is almost entirely developed by volunteers and so in addition to the usual unpredictably of software development it heavily depends on the contributions people can make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help wanted Help wanted - not prioritized by core team ⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

3 participants