Hi all,

I have a service that works with the Request and the Session

class myService{

def boolean detectSomething(){
GrailsWebRequest request = RequestContextHolder.currentRequestAttributes()
GrailsHttpSession session = request.session
// do some stuff ..... with the request and the session
}
}

then I have a Unit test and tried

void testMyServiceDetectSomething() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("user-agent",userAgentForTesting_HTC_Hero)
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));

def something =myService.detectSomething();

// do some stuff

}

If I start the test, I receive this Class-Cast-error

org.codehaus.groovy.runtime.typehandling.GroovyCas tException: Cannot cast object 'org.springframework.mock.web.MockHttpServletReque st@6f8495' with class 'org.springframework.web.context.request.ServletRe questAttributes' to class 'org.codehaus.groovy.grails.web.servlet.mvc.Grails WebRequest'
at org.codehaus.groovy.runtime.typehandling.DefaultTy peTransformation.castToType(DefaultTypeTransformat ion.java:360)

How can I unit test the Service avoiding this class-cast-Error, I need the GrailsWebRequestClass in myService, can I inject this maybe in some way?

Thanks a lot for helping

Andy