I am trying to create a UrlMappingsTest and am getting the following error:
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:123)
at org.springframework.web.context.request.RequestContextHolder$currentRequestAttributes.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:121)
at grails.test.GrailsUrlMappingsTestCase.setUp(GrailsUrlMappingsTestCase.groovy:82)
at junit.framework.TestCase.runBare(TestCase.java:132)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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)
My TestCase (located in test/integration) looks as follows:
class UrlMappingsTests extends grails.test.GrailsUrlMappingsTestCase {
void testSomething() {
}
}
The test is failing in the setup. I'm using grails 1.2.1. Has anyone seen this error before?
I believe this is the error you get when you run a GrailsUrlMappingTestCase as a unit test. I know you said that it is in the test/integration folder, but is there any way you have the same class in the unit test folder as well. Or that you copied it from one folder to the other and your project didn't get cleaned properly?
Related
I'm using SonarQube plugin (version 2.6.1) for Gradle (version 4.7) and have the problem that a lot of unimportant log output is being written while running the sonar analysis on my CI server.
Is there a way to fine-tune the log level for this plugin?
I checked the documentation but the only setting related to the log output I found was the JVM argument "verbose" which I'm not using either way (I guess the default is false so this shouldn't be turned on for me).
EDIT: Here are some examples of the output I would like to get rid of:
Some huge exception stacktraces during findbugs analysis (this one is shortened, didn't want to post the whole stacktrace, it's really huge).
16:23:34.993 ERROR - Unable to create symbol table for : /opt/workspace/pipeline-1/src/main/java/com/SomeClass.java
java.lang.NullPointerException: null
at org.sonar.java.resolve.TypeAndReferenceSolver.getSymbolOfMemberSelectExpression(TypeAndReferenceSolver.java:232) ~[java-squid-2.5.1.jar:na]
at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:200) ~[java-squid-2.5.1.jar:na]
at org.sonar.java.resolve.TypeAndReferenceSolver.resolveAs(TypeAndReferenceSolver.java:182) ~[java-squid-2.5.1.jar:na]
at...
Stacktraces from PMD:
16:23:37.206 ERROR - Fail to execute PMD. Following file is ignored: /opt/workspace/pipeline-1/src/main/java/com/SomeClass.java
java.lang.RuntimeException: null
at org.objectweb.asm.MethodVisitor.visitParameter(Unknown Source) ~[asm-5.0.3.jar:5.0.3]
at org.objectweb.asm.ClassReader.b(Unknown Source) ~[asm-5.0.3.jar:5.0.3]
at org.objectweb.asm.ClassReader.accept(Unknown Source) ~[asm-5.0.3.jar:5.0.3]
at org.objectweb.asm.ClassReader.accept(Unknown Source) ~[asm-5.0.3.jar:5.0.3]
at net.sourceforge.pmd.lang.java.typeresolution.PMDASMClassLoader.getImportedClasses(PMDASMClassLoader.java:77) ~[pmd-java-5.2.1.jar:na]...
Lots of irrelevant warnings like these:
16:23:38.638 WARN - /opt/workspace/pipeline-1/src/main/java/com/SomeClass.java: Got an exception - expecting EOF, found '}'
/opt/workspace/pipeline-1/src/main/java/com/SomeClass.java:28:5: expecting RCURLY, found 'default'
16:23:38.655 WARN - /opt/workspace/pipeline-1/src/main/java/com/SomeClass.java: Got an exception - expecting EOF, found 'someVariable'
I don't know what exactly is causing these problems, but since both my app and the results of the sonar analysis are looking OK, I would like to get rid of those log outputs since they only pollute my logs on Jenkins and make them unreadable.
There's property sonar.log.level and sonar.verbose; for example:
allprojects {
sonarqube {
properties {
// property "sonar.log.level", "INFO"
property "sonar.log.level", "TRACE"
}
}
}
see the analysis parameters.
I deployed a Grails 3.2.0 WAR on Tomcat 8.5.6 and JDK 1.8.0_91 with a simple controller having following code:
package com.test
class MailController {
static responseFormats = ['json']
def index() {
Map headers = (request.headerNames as List).collectEntries { // It fails on this line
return [(it): request.getHeader(it)]
}
println "Incoming email $headers"
render status: 200
}
}
This code fails with the following exception:
Caused by: java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:225)
at groovy.util.ProxyGenerator.instantiateDelegateWithBaseClass(ProxyGenerator.java:193)
at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:185)
at groovy.util.ProxyGenerator.instantiateDelegate(ProxyGenerator.java:181)
at org.grails.web.converters.ConverterUtil.invokeOriginalAsTypeMethod(ConverterUtil.java:161)
at org.grails.web.converters.ConvertersExtension.asType(ConvertersExtension.groovy:56)
at com.test.MailController.index(MailController.groovy:7)
at org.grails.core.DefaultGrailsControllerClass$MethodHandleInvoker.invoke(DefaultGrailsControllerClass.java:222)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:187)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
... 27 common frames omitted
Before building the WAR file, I've changed the embedded tomcat to provided in build.gradle and also commented the groovy-ant dependency related to grails-core#10196
I see a answer here but that didn't worked and the above code is working fine when we run via grails run-app.
Update
I shorted down the issue. It is failing on this part only request.headerNames as List
I am pretty sure the problem is with the use of "as List". Mostly because Grails will overwrite Groovy's asType implementation which makes the "as X" coercion syntax work.
Grails does this to add support for things like JSON for marshalling known Grails types to web transport formats.
Unfortunately, in doing so Grails also breaks any asType function you might have declared yourself. Or in this case Groovy itself already declared for converting an Enumeration into a List.
It's quite annoying as Grails is effectively breaking existing contracts here and forcing you to modify upstream code to allow it to run on Grails.
That or dump Grails because it doesn't play nice with perfectly valid Groovy code.
I believe replacing "as List" with .asType(List) won't even fix the issue as you're still invoking the same code. At best you could try .collect([]) {it} instead. It may not be necessary to add the empty array as the first argument to collect.
I am working on a project that uses openSymphony 2.1.2 and struts 2.3.8.
However on that code base I am trying to apply a piece code that was written for older versions of openSymphony and struts.
Here is that piece of code:
http://www.lischke-online.de/index.php/java/action-unit-testing-with-struts-2-0-part-2
(As a side note, I need that code in order to be able to simulate running the struts actions from my inherited project, in a system that is based on a different framework.)
I have a problem with the following paragraph:
final StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory("auto", "true", servletContext);
ObjectFactory.setObjectFactory(ssf);
On the second line, I'm getting the error: The method setObjectFactory(StrutsSpringObjectFactory) is undefined for the type ObjectFactory
However, when I look at the javadoc of ObjectFactory, I do not see an alternative method that would let me set a specific ObjectFactory (e.g. StrutsSpringObjectFactory), as the ObjectFactory that will be used when executing the Actions.
So how do I set such a specific ObjectFactory with the new API?
Updated code:
static {
sessionMap = new HashMap<String, Object>();
// Create fake back end here.
// ...
// ===== Struts setup:
// Create and use a file system resource loader otherwise Tiles will not find
// our configuration file. The default resource loader is able to find struts.xml
// if it is in the classpath, but not tiles.xml.
final FileSystemResourceLoader loader = new FileSystemResourceLoader();
final String[] config = new String[] { "WEB-INF/classes/struts.xml" };
servletContext = new MockServletContext(loader);
final XmlWebApplicationContext appContext = new XmlWebApplicationContext();
// Link the servlet context and the Spring context.
appContext.setServletContext(servletContext);
appContext.setConfigLocations(config);
appContext.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
appContext);
servletContext.addInitParameter(BasicTilesContainer.DEFINITIONS_CONFIG, "WEB-INF/tiles.xml");
// Creating the tiles listener statically (not via class loader).
final StrutsTilesListener tilesListener = new StrutsTilesListener();
final ServletContextEvent event = new ServletContextEvent(servletContext);
tilesListener.contextInitialized(event);
// Use spring as the object factory for Struts
//this code not working anymore with struts 2.3.2:
//final StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory("auto", "true", servletContext);
//ObjectFactory.setObjectFactory(ssf);
//my change: (original note working with newer version of struts)
//StrutsSpringObjectFactory.setObjectFactory(ssf);
//(*) original location.
// Dispatcher is the guy that actually handles all requests. Pass in
// an empty. Map as the parameters but if you want to change stuff like
// what config files to read, you need to specify them here
// (see Dispatcher's source code)
dispatcher = new Dispatcher(servletContext, new HashMap<String, String>());
dispatcher.init();
Dispatcher.setInstance(dispatcher);
//(*) moved to here:
//http://stackoverflow.com/questions/15821643/setting-strutsspringobjectfactory-as-my-current-objectfactory?noredirect=1#comment22519072_15821643
final StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory("auto", "true", "false", servletContext, "false", dispatcher.getContainer());
}
Stack trace that I get on that code, when calling the test from within a webapp (a deployed war):
08:50:28,471 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--127.0.0.1-8080-1) #{accountLookupBean.lookupAccounts()}: java.lang.ExceptionInInitial
izerError: javax.faces.FacesException: #{accountLookupBean.lookupAccounts()}: java.lang.ExceptionInInitializerError
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.component.UIData.broadcast(UIData.java:1093) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.component.UIData.broadcast(UIData.java:1093) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.component.UIData.broadcast(UIData.java:1093) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_29]
Caused by: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.
0.Final]
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
... 23 more
Caused by: java.lang.ExceptionInInitializerError
at com.myapp.services.AccountLookupServiceImpl.getRows(AccountLookupServiceImpl.java:38) [classes:]
at com.myapp.beans.AccountLookupBean.lookupAccounts(AccountLookupBean.java:39) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_29]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_29]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_29]
at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_29]
at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.10.Final.jar:]
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.10.Final.jar:]
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0
.Final]
... 24 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/classes/struts.xml];
nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/struts.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) [spring-beans-3.2.1.RELEASE.jar:3.2.1.REL
EASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) [spring-beans-3.2.1.RELEASE.jar:3.2.1.REL
EASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) [spring-beans-3.2.1.RELEASE
.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) [spring-beans-3.2.1.RELEASE
.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) [spring-beans-3.2.1.RELEASE
.jar:3.2.1.RELEASE]
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) [spring-web-3.2.1.RELEASE.jar:3.2.1.R
ELEASE]
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) [spring-web-3.2.1.RELEASE.jar:3.2.1.RE
LEASE]
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) [spring-context-
3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) [spring-context-3.2.1.RELEASE.jar:
3.2.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) [spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at com.myapp.softgems.ActionBaseTestCase.<clinit>(ActionBaseTestCase.java:70) [classes:]
... 34 more
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/struts.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140) [spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) [spring-beans-3.2.1.RELEASE.jar:3.2.1.REL
EASE]
... 44 more
UPDATE 2:
The reason I want to be able to test an Action, is not simply to be able to right-click on it from the project explorer and than right-click "run as Junit". I actually want to run the test as part of my web application.
This is what I mean: I am trying to call the following code from one of my service classes:
DataTest test = new DataTest("testDataAction");
JUnitCore jUnitCore = new JUnitCore();
jUnitCore.run(test);
Because, in DataTest I try to execute() DataAction. That Action calls some messy db logic and eventually return some data. I need that data for my service. Instead of trying to figure out what the Action does exactly, I wan to simply execute() it and get the data. The way I'm trying to do it is by running a test that will execute() the Action.
My struts.xml is not directly in the project that I am building. Here is my situation: let's call my new project, project A; and the legacy struts project that I depend on, project B.
Project A is being built by other framework (JSF & Spring).
Project B uses struts for the UI. But its Actions were written in such a messy way, that a lot of the DB access logic was written directly within the actions. So if I want to use the logic from project B, and not rewrite it, a temporary solution (which I am trying to accomplish) would be to execute an Action from project B with the corresponding request data.
The way to do it, is by running a test on an Action from B, within a service class from A.
Since project B was packed as a war file, my way to reuse it with Maven in project A, is to define it as an overlay in project A.
The classes and other resources from the classpath of project B are packed into a jar. Then in project A I have a dependency on that jar.
So struts.xml lives in the jar that contains the classes and xml's of project B. In compile time, project A can only see struts.xml within the jar of project A.
Only when I pack project A, war B is unpacked, its content (including struts.xml) is copied into the target folder of project A, and then A + B are packed together as war. (in the final war, struts.xml will be both in the jar B, and in WEB-INF/classes witin the final war.
So in practical terms, if I try to run the test by right-clicking the test and them "run as junit", it should not find struts.xml in some WEB-INF/classes on my classpath - first there's no such thing in my workspace, only in created war. Second I only try to run the test from within a war (as I've shown above). in that time, there is WEB-INF/classes/struts.xml, why could it not be found?
Just create new instance of StrutsSpringObjectFactory but do it after creation of Dispatcher.
final StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory("auto",
"true", "false", servletContext, "false", dispatcher.getContainer());
BUT take a look at struts2-junit-plugin for testing Struts2 actions. It has StrutsSpringJUnit4TestCase with convenient methods, so you do not need to do all that stuff by yourself.
You need to include the Struts2-Spring-plugin(*.jar)
http://struts.apache.org/release/2.3.x/docs/spring-plugin.html
The Spring Plugin works by overriding the Struts ObjectFactory to
enhance the creation of core framework objects. When an object is to
be created, it uses the class attribute in the Struts configuration to
correspond to the id attribute in the Spring configuration. If not
found, the class will try to be created as usual, then be autowired by
Spring. In the case of Actions, Spring 2's bean scope feature can be
used to scope an Action instance to the session, application, or a
custom scope, providing advanced customization above the default
per-request scoping.
I'm going through the "Getting Started with Grails" ebook and have hit a wall with chapter 4 (Validation) on page 38 (actual page 50). Here is the code:
Oh, there might be a typo in the code in the book, though it didn't affect the behavior or error messages I got, on the following line:
def code = badField?.codes.find {
it == 'race.startDate.validator.invalid'
}
As I said, it doesn't affect the main execution, but was just curious if I'm right or if this is something in Groovy I haven't run across yet. I put what I thought it should be below.
package racetrack
import groovy.util.GroovyTestCase
class RaceIntegrationTests extends GroovyTestCase {
void testRaceDatesBeforeToday() {
def lastWeek = new Date() - 7
def race = new Race(startDate:lastWeek)
assertFalse "Validation should not succeed", race.validate()
// It should have errors after validation fails
assertTrue "There should be errors", race.hasErrors()
println "\nErrors:"
println race.errors ?: "no errors found"
def badField = race.errors.getFieldError('startDate')
println "\nBadField:"
println badField ?: "startDate wasn't a bad field"
assertNotNull "Expecting to find an error on the startDate field", badField
def code = badField ?: codes.find {
it == 'race.startDate.validator.invalid'
}
println "\nCode:"
println code ?:"the custom validator for startDate wasn't found"
assertNotNull "startDate field should be the culprit", code
}
}
where, when running "grails test-app", I get the following:
Error executing script TestApp: java.lang.RuntimeException: Could not load class in test type 'integration'
java.lang.RuntimeException: Could not load class in test type 'integration'
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:391)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.RuntimeException: Could not load class in test type 'integration'
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:261)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
... 10 more
The book is using Grails 1.2.x and I'm using 1.3.x and already noticed some discrepancies between the versions (nothing unsurmountable), so it could be something like that, but I can't seem to figure it out. Being new to Groovy and Grails isn't helping! :-D
Can anyone explain what I can do to get past this?
I just got this error, my cause was that my test class was in the wrong package.
I could not find a way to get a clearer description of the problem, even running with the --stacktrace option showed no more information.
It seems like this error can be caused by different compilation issues, perhaps?
I had the same problem (although I'm using Grails 2.3.4) - I fixed it by explicitly including
import racetrack.Race
instead of
package racetrack
Interestingly, after I tried this I commented it out and everything still worked - until I did a grails clean. Then it failed again. Suspect something not quite 100% in the grails / groovy auto compilation stuff.
I hit this problem with Grails 2.4.2. The cause was I had a test file named FooTest, but the class was named FooTest**s**.
Running grails test-app --stacktrace helped find the offending class.
First of all, I don't think you need this to be an 'integration' test. Place it under the 'src/test/unit/...' directory structure. Second of all, if you want to test the Grails 'validate()' method that is going to be injected by the Grails framework based on your 'constraints' block, you must make the test extend 'GrailsUnitTest' and call 'mockDomain(Race)' on the first line of your unit test method. If that is unclear, ping me and I'll post code but my guess is your book has a pretty good example of this. Here is some 'free hand' code that might fix it...
class RaceTests extends GrailsUnitTest {
void testRaceDatesBeforeToday() {
mockDomain(Race)
...
please make sure that your package name is correct, the above error means that its trying to run the test but since the package name is specified wrong its not able to find the file with that particular package name.
I have generated a java package with the wsdl2java CXF command.
Now i want to deploy the wsdl to the tomcat server but I got these errors in logs when i start the server
I use opebEjb.
It looks like the wsdl is not valid.
How can i check this?
Log:
Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:268)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:202)
at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:397)
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.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1412)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1373)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 30 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:274)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:371)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:525)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:422)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:190)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:164)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:100)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:117)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:168)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:339)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:252)
... 39 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 48 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an #XmlElementDecl for the element {urn:hl7-org:v3}assignedDevice.
this problem is related to the following location:
at protected javax.xml.bind.JAXBElement com.santeos.dmp.iheprofiles.hl7.MFMIMT700701UV01AuthorOrPerformer.assignedDevice
at com.santeos.dmp.iheprofiles.hl7.MFMIMT700701UV01AuthorOrPerformer
at protected java.util.List com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess.authorOrPerformer
at com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess
at protected com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MCCIMT000100UV01Message.controlActProcess
at com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MCCIMT000100UV01Message
There's no ObjectFactory with an #XmlElementDecl for the element {urn:hl7-org:v3}assignedPerson.
this problem is related to the following location:
at protected javax.xml.bind.JAXBElement com.santeos.dmp.iheprofiles.hl7.MFMIMT700701UV01AuthorOrPerformer.assignedPerson
at com.santeos.dmp.iheprofiles.hl7.MFMIMT700701UV01AuthorOrPerformer
at protected java.util.List com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess.authorOrPerformer
at com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess
at protected com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MFMIMT700701UV01ControlActProcess com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MCCIMT000100UV01Message.controlActProcess
at com.santeos.dmp.iheprofiles.hl7.PRPAIN201304UV02MCCIMT000100UV01Message
As Julien told in a comment above, this issue can be resolved by changing the package name for each wsdl if you are using more than one wsdl. In my case, I had two wsdl's, one downloaded in my work-space along with all the required xsd's and second used using a URL. Both of them pointing to same server. The reason for downloading the first wsdl was two name collision in object factory. Yes, the external bindings didn't worked, simply because the wsdl was total mess.
So, when I was trying to generate sources using wsdltojava, it was failing with "There's no ObjectFactory with an #XmlElementDecl...". I followed Julien's comments and the issue got resolved. I am not sure if this is the best and cleaner solution, but it worked.
What flags are you passing to wsdl2java?
Can you check the generated code for ObjectFactory classes? Check those to see if any methods are annotated with #XmlElementDecl.