-
1. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
aslak Aug 27, 2012 10:03 AM (in response to dominik42)could you post your testcase ?
-
2. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 27, 2012 3:16 PM (in response to aslak)I took the LoginControllerTestCase from arquillian-warp-spring-ftest and start with small modifications according my own SpringMVC webapp project. Therefor, my version differs from the original from GitHub only on foloowings lines:
@WarpTest
@RunWith(Arquillian.class)
@SpringAnnotationConfiguration(classes = AppConfig.class)
public class LoginControllerTestCase {
AppConfig is the Java-based @Configuration class for my own SpringMVC webApp
Furthermore, in order to avoid ClassNotFoundExceptions, I've add the following artifacts to the deployment
.artifacts("org.slf4j:slf4j-api:1.5.6")
.artifacts("org.slf4j:slf4j-log4j12:1.5.6")
.artifacts("log4j:log4j:1.2.17")
.artifacts("javax.servlet:jstl:1.2")
.artifacts("javax.servlet:servlet-api:2.5")
And the ShrinkWrap:
return ShrinkWrap.create(WebArchive.class, "spring-test.war")
.addPackage(LoginController.class.getPackage())
.addAsWebInfResource("WEB-INF/web-arquillian.xml", "web.xml")
.addAsWebInfResource("WEB-INF/welcome-servlet.xml", "welcome-servlet.xml")
.addAsWebInfResource("WEB-INF/views/login.jsp", "views/login.jsp")
.addAsLibraries(libs);
The other parts of LoginControllerTestCase I left untouched ...
-
3. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 27, 2012 3:56 PM (in response to dominik42)Something like this?:
{code}
@WarpTest
@RunWith(Arquillian.class)
@SpringAnnotationConfiguration(classes = AppConfig.class)
public class LoginControllerTestCase {
@Drone
WebDriver browser;
@ArquillianResource
URL contextPath;
@Deployment
public static WebArchive createDeployment() {
File[] libs = DependencyResolvers.use(MavenDependencyResolver.class)
.loadMetadataFromPom("pom.xml")
.artifacts("org.springframework:spring-webmvc:3.1.1.RELEASE")
.artifacts("javax.validation:validation-api:1.0.0.GA")
.artifacts("org.hibernate:hibernate-validator:4.1.0.Final")
.artifacts("org.slf4j:slf4j-api:1.5.6")
.artifacts("org.slf4j:slf4j-log4j12:1.5.6")
.artifacts("log4j:log4j:1.2.17")
.artifacts("javax.servlet:jstl:1.2")
.artifacts("javax.servlet:servlet-api:2.5")
.resolveAsFiles();
return ShrinkWrap.create(WebArchive.class, "spring-test.war")
.addPackage(LoginController.class.getPackage())
.addAsWebInfResource("WEB-INF/web-arquillian.xml", "web.xml")
.addAsWebInfResource("WEB-INF/welcome-servlet.xml", "welcome-servlet.xml")
.addAsWebInfResource("WEB-INF/views/login.jsp", "views/login.jsp")
.addAsLibraries(libs);
}
@Test
@RunAsClient
public void testGetLogin() {
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.navigate().to(contextPath + "login.do");
}
}).verify(new LoginControllerGetVerification());
}
@Test
@RunAsClient
public void testLoginValidationErrors() {
browser.navigate().to(contextPath + "login.do");
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.findElement(By.id("loginForm")).submit();
}
}).verify(new LoginControllerValidationErrorsVerification());
}
@Test
@RunAsClient
public void testLoginSuccess() {
browser.navigate().to(contextPath + "login.do");
browser.findElement(By.id("login")).sendKeys("warp");
browser.findElement(By.id("password")).sendKeys("warp");
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.findElement(By.id("loginForm")).submit();
}
}).verify(new LoginSuccessVerification());
}
public static class LoginControllerGetVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@AfterServlet
public void testGetLogin() {
assertEquals("login", modelAndView.getViewName());
assertNotNull(modelAndView.getModel().get("userCredentials"));
}
}
public static class LoginControllerValidationErrorsVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@SpringMvcResource
private Errors errors;
@AfterServlet
public void testGetLogin() {
assertEquals("login", modelAndView.getViewName());
assertNotNull(modelAndView.getModel().get("userCredentials"));
assertEquals("Two errors were expected.", 2, errors.getAllErrors().size());
assertTrue("The login hasn't been validated.", errors.hasFieldErrors("login"));
assertTrue("The password hasn't been validated.", errors.hasFieldErrors("password"));
}
}
public static class LoginSuccessVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@SpringMvcResource
private Errors errors;
@AfterServlet
public void testGetLogin() {
assertEquals("welcome", modelAndView.getViewName());
assertFalse(errors.hasErrors());
}
}
}
{code}
Now some things needs clarification the @SpringAnnotationConfiguration(classes = AppConfig.class) is somehow similart to Spring @ContextConfiguration it is responsible for instantating the Spring context with configured classes for each test case. But in this scenarios there are no tests that are actually executing on the server side, you can notice the @RunAsClient annotations at each test method. If you intended to inject spring beans into the warp tests you will need annotate each server assertion:
{code}
@SpringAnnotationConfiguration(classes = AppConfig.class)
public static class LoginControllerValidationErrorsVerification extends ServerAssertion {
}
{code}
But you have to bear in mind that this will create the Spring AnnotationConfigApplicationContext for each executing test so testing some side effects on the beans after executing particular controller won't be possible, if the AppConfig is similar to the configuration that was used for creating the dispatcher servlet you could do something better, access the ApplicationContext of the configured DispatcherServlet, simply by using @SpringWebConfiguration.
{code}
@SpringWebConfiguration(servlet = "welcome")
public static class LoginControllerValidationErrorsVerification extends ServerAssertion {
@Autowired
Bean servletDispatcherBean; // some bean
}
{code}
And add the fallowing line to the web.xml:
{code}
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
{code}
In case you just wanted to inject beans into your test case, maybe you don't need the warp at all?
-
4. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 28, 2012 4:32 AM (in response to jmnarloch)Hi Jakub,
thanks for your explanation. Unfortunately the error still occurs with the modifications you've mentioned.
Neither the annotation @SpringAnnotationConfiguration(classes = AppConfig.class) nor
@SpringWebConfiguration(servlet = "welcome") avoids the RuntimeException. I also append the filter in the web-arquillian.xml which is mapped as web.xml by
.addAsWebInfResource("WEB-INF/web-arquillian.xml", "web.xml")
but without any changes. BTW, it seems to be, that the execution hasn't reached that point because if I modify that line into
.addAsWebInfResource("WEB-INF/web-arquillianXYZ.xml", "web.xml")
nothing changed at all.
So there are any other hints ?
Thanks in advance
Dominik
Here is my test class:
@WarpTest
@RunWith(Arquillian.class)
public class LoginControllerTestCase {
@Drone
WebDriver browser;
@ArquillianResource
URL contextPath;
@Deployment
public static WebArchive createDeployment() {
File[] libs = DependencyResolvers.use(MavenDependencyResolver.class)
.loadMetadataFromPom("pom.xml")
.artifacts("org.springframework:spring-webmvc:3.1.1.RELEASE")
.artifacts("javax.validation:validation-api:1.0.0.GA")
.artifacts("org.hibernate:hibernate-validator:4.1.0.Final")
.artifacts("org.slf4j:slf4j-api:1.5.6")
.artifacts("org.slf4j:slf4j-log4j12:1.5.6")
.artifacts("log4j:log4j:1.2.17")
.artifacts("javax.servlet:jstl:1.2")
.artifacts("javax.servlet:servlet-api:2.5")
.resolveAsFiles();
return ShrinkWrap.create(WebArchive.class, "spring-test.war")
.addPackage(LoginController.class.getPackage())
.addAsWebInfResource("WEB-INF/web-arquillian.xml", "web.xml")
.addAsWebInfResource("WEB-INF/welcome-servlet.xml", "welcome-servlet.xml")
.addAsWebInfResource("WEB-INF/views/login.jsp", "views/login.jsp")
.addAsLibraries(libs);
}
@Test
@RunAsClient
public void testGetLogin() {
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.navigate().to(contextPath + "login.do");
}
}).verify(new LoginControllerGetVerification());
}
@Test
@RunAsClient
public void testLoginValidationErrors() {
browser.navigate().to(contextPath + "login.do");
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.findElement(By.id("loginForm")).submit();
}
}).verify(new LoginControllerValidationErrorsVerification());
}
@Test
@RunAsClient
public void testLoginSuccess() {
browser.navigate().to(contextPath + "login.do");
browser.findElement(By.id("login")).sendKeys("warp");
browser.findElement(By.id("password")).sendKeys("warp");
Warp.execute(new ClientAction() {
@Override
public void action() {
browser.findElement(By.id("loginForm")).submit();
}
}).verify(new LoginSuccessVerification());
}
@SpringAnnotationConfiguration(classes = AppConfig.class)
public static class LoginControllerGetVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@AfterServlet
public void testGetLogin() {
assertEquals("login", modelAndView.getViewName());
assertNotNull(modelAndView.getModel().get("userCredentials"));
}
}
@SpringAnnotationConfiguration(classes = AppConfig.class)
public static class LoginControllerValidationErrorsVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@SpringMvcResource
private Errors errors;
@AfterServlet
public void testGetLogin() {
assertEquals("login", modelAndView.getViewName());
assertNotNull(modelAndView.getModel().get("userCredentials"));
assertEquals("Two errors were expected.", 2, errors.getAllErrors().size());
assertTrue("The login hasn't been validated.", errors.hasFieldErrors("login"));
assertTrue("The password hasn't been validated.", errors.hasFieldErrors("password"));
}
}
@SpringAnnotationConfiguration(classes = AppConfig.class)
public static class LoginSuccessVerification extends ServerAssertion {
private static final long serialVersionUID = 1L;
@SpringMvcResource
private ModelAndView modelAndView;
@SpringMvcResource
private Errors errors;
@AfterServlet
public void testGetLogin() {
assertEquals("welcome", modelAndView.getViewName());
assertFalse(errors.hasErrors());
}
}
}
-
5. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 4:34 AM (in response to dominik42)Could you, please paste the stack trace of the exception?
-
6. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 28, 2012 4:38 AM (in response to jmnarloch)java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:160)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
... 10 more
Caused by: java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.core.impl.ManagerImpl
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:160)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:111)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:97)
at org.jboss.arquillian.core.spi.ManagerBuilder.create(ManagerBuilder.java:77)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:55)
... 15 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.jboss.arquillian.core.spi.SecurityActions.newInstance(SecurityActions.java:156)
... 19 more
Caused by: java.lang.RuntimeException: Could not create and process manager
at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:104)
... 24 more
Caused by: java.lang.RuntimeException: A InjectionPoint of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss.arquillian.core.api.annotation.Scope annotation, bad definition for field: private org.jboss.arquillian.core.api.InstanceProducer org.jboss.arquillian.container.spring.embedded.SpringEmbeddedApplicationContextProducer.testApplicationContext
at org.jboss.arquillian.core.impl.Reflections.isInjectionPoint(Reflections.java:204)
at org.jboss.arquillian.core.impl.Reflections.getFieldInjectionPoints(Reflections.java:76)
at org.jboss.arquillian.core.impl.ExtensionImpl.of(ExtensionImpl.java:51)
at org.jboss.arquillian.core.impl.ManagerImpl.createExtensions(ManagerImpl.java:410)
at org.jboss.arquillian.core.impl.ManagerImpl.fireProcessing(ManagerImpl.java:345)
at org.jboss.arquillian.core.impl.ManagerImpl.<init>(ManagerImpl.java:98)
... 24 more
-
7. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 4:43 AM (in response to dominik42)Have you added the spring embedded container to the project (arquillian-container-spring for Alpha 2 or arquillian-service-container-spring for Beta 1)?
BTW. I will report bug for that.
-
8. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 4:48 AM (in response to jmnarloch)If you have that dependency in the pom, then remove it, you won't need it.
-
9. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 28, 2012 5:10 AM (in response to jmnarloch)If I remove arquillian-service-container-spring from the POM but leave all the other Arquillian Spring depedencies within, I've got the following exception:
Caused by: java.lang.IllegalStateException: Defined default protocol Servlet 3.0 can not be found on classpath
at org.jboss.arquillian.container.test.impl.client.protocol.ProtocolRegistryCreator.createRegistry(ProtocolRegistryCreator.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.ManagerImpl.bindAndFire(ManagerImpl.java:236)
at org.jboss.arquillian.core.impl.InstanceImpl.set(InstanceImpl.java:74)
at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.ManagerImpl.start(ManagerImpl.java:261)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:56)
... 15 more
I thought, the Arquillian-Tomcat-Container contains this protocol as well..
my POM contains this as profile setting:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-managed-7</artifactId>
<version>1.0.0.Final-SNAPSHOT</version>
<scope>test</scope>
</dependency>
-
10. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 5:14 AM (in response to dominik42)Hmm, this time I'm not sure but you could try to add to the project fallowing dependency:
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
-
11. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 28, 2012 5:57 AM (in response to jmnarloch)1) I've added the protocol dependency.
2) After that, I've got:
org.jboss.arquillian.container.spi.ConfigurationException: Either JAVA_HOME environment variable or javaHome property in Arquillian configuration must be set and point to a valid directory! null is not valid directory!
3) Therefor, I've add
<
property name="javaHome">/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home</property>
to the container definition in arquillian.xml
4) Now, I've got:
org.springframework.beans.factory.BeanDefinitionStoreException
: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
This is strange, because I'll use Spring Java Config and there is no applicationContext.xml...
-
12. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 6:00 AM (in response to dominik42)Dominik Hirt wrote:
4) Now, I've got:
org.springframework.beans.factory.BeanDefinitionStoreException
: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
This is strange, because I'll use Spring Java Config and there is no applicationContext.xml...
But I know that exception
The
org.springframework.web.context.ContextLoaderListener
that was added to the web.xml is by default looking for the applicationContext.xml in WEB-INF. You could add the montioned file containg only <beans></beans> and nothing else to the deployment. -
13. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
jmnarloch Aug 28, 2012 6:04 AM (in response to jmnarloch)BTW. I'm affriad that currently the WarpDispatcherServlet can not be used directly with Java based config due to the compatibilty issue with Spring 2.5. So although it is possible to configure it through WebApplicationInitializer but it will still require the xml for configuration.
-
14. Re: Injection Point A of type org.jboss.arquillian.core.api.InstanceProducer must define a org.jboss...annotation.Scope annotation
dominik42 Aug 28, 2012 6:36 AM (in response to jmnarloch)ok, one step forward ;-)
Now, the Browser object is null in
public void action() {
browser.navigate().to("http://localhost:8080/webapp/");
}
so it seems to be some Warp/Drone/Selenium dependencies are not resolved. The test case creates the full shrinkwrap archive for all my maven dependencies by
return ShrinkWrap.create(WebArchive.class,"spring-test.war")
.addAsLibraries(DependencyResolvers.use(MavenDependencyResolver.class)
.includeDependenciesFromPom("./pom.xml").resolveAs(WebArchive.class));
so I'll double check my POM...