I tried something like this but still throwing NullPointerException
#RunWith(MockitoJUnitRunner.class)
public class MyActionTest extends BaseActionTestCase {
#Mock private ServletActionContext context;
#Mock
private serviceclass serviceMock;
#InjectMocks
private MyAction action;
#Test
public void testSave() throws Exception {
when(serviceMock.getTaskCode()).thenReturn("tc");
action.save();
verify(serviceMock).saveObject(any(Task.class));
}
posting stacktrace:
java.lang.NullPointerException
at org.apache.struts2.ServletActionContext.getRequest(ServletActionContext.java:112)
at com.princess.ilo.webapp.action.BaseAction.getRequest(BaseAction.java:176)
at com.princess.ilo.webapp.action.BaseAction.getSession(BaseAction.java:198)
at com.princess.ilo.webapp.action.BaseAction.getUser(BaseAction.java:206)
at com.princess.ilo.webapp.action.TaskAction.save(TaskAction.java:116)
at com.princess.ilo.webapp.action.TaskActionTest.testSave(TaskActionTest.java:97)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
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
hm, I would say you still need to create the action object, like
#InjectMocks private MyAction action = new MyAction();
see http://docs.mockito.googlecode.com/hg/org/mockito/InjectMocks.html for some examples
Related
one to many association is getting stack over flow error in groovy with grails. Please Check below classes, error log to see if there are any association.
errors.
This is what I tried so far:
Earlier association is from B to C class, now we modified it A to B class after making this association changes. Changes looks good to me but while accessing b's from A class its throwing stackoverflow error getBs method from A.groovy. If I remove getBs method its giving null as B even though b's available for that contract in db. Also calling B.findAllByContract dynamic finder method its throwing could not resolve property 'a' even though its available at class level. Could you please guide me here
class A implements Serializable {
static stampable = true
static auditable = true
static hasMany = [
bs: B]
static mapping = {
bs joinTable: [column: "a_id"]
}
static mappedBy = [ bs: "a"]
def getBs() {
println "calling ..."
return bs
}
}
class B implements Serializable {
A a
static constraints = {
a nullable:true
}
static mapping = {
sort title: "asc"
a column: "a_id"
}
static transients = ['BValue']
}
error log:
2021-03-28 13:06:10,825 {yyyy-MM-dd HH:mm:ss} admin ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/app].[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [/app] threw exception [Handler processing failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:583)
at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:575)
at org.codehaus.groovy.runtime.InvokerHelper.toString(InvokerHelper.java:130)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.println(DefaultGroovyMethods.java:642)
at org.codehaus.groovy.runtime.dgm$504.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:251)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at app.A.getBs(A.groovy:245)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1852)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1155)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1167)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassGetPropertySite.getProperty(PogoMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at app.A.getBs(A.groovy:246)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1852)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1155)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1167)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassGetPropertySite.getProperty(PogoMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at app.A.getBs(A.groovy:246)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Try updating the method getBs as follows:
def getBs() {
println "calling ..."
return this.bs
}
I think referring bs might be recursively calling getBs().
i've created a simple grails app with latest v3.2.6. created a Authors and Book classes in grails-app/domain.
book class in grails-app/domain looks like this ( i have a books class also )
package org.softwood
//Author has many books logical model
class Author {
String name
Collection books
//static hasMany = [books:Book]
static constraints = {
books nullable:true
}
}
and book domain class for completeness
package org.softwood
class Book {
String title
Author author
//static belongsTo = [author:Author]
static constraints = {
author nullable:true
}
}
I started app - no errors and tried to use grails console to create a instance of Author and got an error like this
java.lang.IllegalStateException: Either class [org.softwood.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
so i edited BootStrap.groovy to try and create one at startup like this. Why does it not brought up Gorm correctly?
import org.softwood.*
class BootStrap {
def init = { servletContext ->
environments {
development{
createDevData()
}
test {}
production {}
}
}
def destroy = {
}
def createDevData() {
Author a = new Author(name:"will")
def res = a.save (flush:true, failOnExit:true)
assert res
assert Author.get(1).name == "will"
}
}
this errors when i start the app with same message, stack trace as follows
java.lang.IllegalStateException: Either class [org.softwood.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:387)
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:273)
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:270)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormInstanceApi(GormEntity.groovy:1326)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at org.softwood.Author.save(Author.groovy)
at org.softwood.Author.save(Author.groovy)
at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at test.BootStrap.createDevData(BootStrap.groovy:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
at test.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy:10)
at test.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:408)
at grails.util.Environment$EnvironmentBlockEvaluator.execute(Environment.java:529)
at grails.util.Environment.executeForEnvironment(Environment.java:510)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:485)
at org.grails.web.servlet.boostrap.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:62)
at org.grails.web.servlet.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:65)
at org.grails.plugins.web.servlet.context.BootStrapClassRunner.onStartup(BootStrapClassRunner.groovy:53)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:256)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at test.Application.main(Application.groovy:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
try with this
package org.softwood
//Author has many books logical model
class Author {
String name
//Collection books
static hasMany = [books:Book]
static constraints = {
books nullable:true // you may not need this.
}
}
I have a custom converter annotated as a #Component and it depends on MyBean which is injected by Spring via #Autowired at boot time.
MyEntity has a field MyObject to be converted by that converter. OGM will call toEntityAttribute from MyObjectToStringConverter as soon as I retrieve MyEntity from Neo4j. However, I'm getting a NPE. It seems OGM does not reuse my converter created by Spring and MyBean dependency is always NULL.
Should OGM be able to get my converter from Spring context?
Is there a way MyBean could be initialized by OGM?
If not, can I register a converter by myselft?
#NodeEntity
class MyEntity {
#Convert(MyObjectToStringConverter.class)
private MyObject myObject;
...
}
#Component
class MyObjectToStringConverter implements AttributeConverter<MyObject, String> {
#Autowired
private MyBean myBean;
#Override
public String toGraphProperty(MyObject value) {
return value.getName();
}
#Override
public MyObject toEntityAttribute(String value) {
return myBean.convert(value); // myBean is NULL
}
}
...
repository.find(myEntityID) // NPE from MyObjectToStringConverter
java.lang.NullPointerException: null
at org.myproject.mvc.converter.MyObjectToStringConverter.toEntityAttribute(MyObjectToStringConverter.java:25)
at org.myproject.mvc.converter.MyObjectToStringConverter.toEntityAttribute(MyObjectToStringConverter.java:12)
at org.neo4j.ogm.entityaccess.FieldWriter.write(FieldWriter.java:64)
at org.neo4j.ogm.mapper.GraphEntityMapper.writeProperty(GraphEntityMapper.java:162)
at org.neo4j.ogm.mapper.GraphEntityMapper.setProperties(GraphEntityMapper.java:127)
at org.neo4j.ogm.mapper.GraphEntityMapper.mapNodes(GraphEntityMapper.java:108)
at org.neo4j.ogm.mapper.GraphEntityMapper.mapEntities(GraphEntityMapper.java:92)
at org.neo4j.ogm.mapper.GraphEntityMapper.map(GraphEntityMapper.java:67)
at org.neo4j.ogm.session.response.SessionResponseHandler.loadById(SessionResponseHandler.java:161)
at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:45)
at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:36)
at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:99)
at org.springframework.data.neo4j.repository.GraphRepositoryImpl.findOne(GraphRepositoryImpl.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy87.findOne(Unknown Source)
at org.myproject.mvc.service.AbstractService.find(AbstractService.java:40)
The OGM will not get the converter from the Spring context- it has no dependencies at all on Spring. Perhaps you can use Springs ConversionService?
http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RELEASE/reference/html/#_spring_s_conversionservice
I want to use DeltaSpike for CDI-based tests. I use a lot of GroupedConversationScoped Beans for my application and when I'm trying to test them, I always run into this failure:
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type org.apache.deltaspike.core.api.scope.GroupedConversationScoped
at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:708)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
at com.pass.project.generated.context.MainDataContext$Proxy$_$$_WeldClientProxy.setTestAttr(Unknown Source)
at com.pass.project.test.DeltaSpikeTest.main(DeltaSpikeTest.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.invokeMethod(CdiTestRunner.java:340)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$ContainerAwareMethodInvoker.evaluate(CdiTestRunner.java:312)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:174)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:75)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:366)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:392)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:141)
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:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
I can't figure why it's not active. That's my test
#RunWith(CdiTestRunner.class)
public class DeltaSpikeTest {
#Inject
private DlgListBoRoleFormBean dlgListBoRoleFormBean;
#Inject
private MainDataContext mainDataContext;
#Test
public void main() {
TblTestAttrListBeanList tbl = (TblTestAttrListBeanList) dlgListBoRoleFormBean.getTblTestAttr();
List<ContactpersonValueImpl> li = new ArrayList<>();
mainDataContext.setTestAttr(li);
{
ContactpersonValueImpl person = new ContactpersonValueImpl();
person.setName("Harald");
li.add(person);
}
{
ContactpersonValueImpl person = new ContactpersonValueImpl();
person.setName("Wilhelm");
li.add(person);
}
tbl.update();
Assert.assertTrue(tbl.getList().size() == 2);
Assert.assertTrue(tbl.getList().get(0).getName().equals("Harald"));
System.out.println(tbl.toString());
}
}
Every help is highly appreciated!
You just need to activate a (test-)window, because grouped-conversations are based on the window-context to support different windows. #Inject WindowContext and use the method activateWindow. Provide any value you like.
See the example provided by OS890:
https://github.com/os890/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/PageBeanTest.java
If you ask such questions on their mailing-list, you get answers petty quickly.
#John:
You don't need to list it via that annotation in this case.
It looks like you may have over looked the #TestControl() annotation, which is meant to start a context. Pass startScopes = GroupedConversationScoped.class into that to get the right output.
You can read more here: http://deltaspike.apache.org/documentation/test-control.html
Basically, I'm trying to run a simple unit test but cannot make it work when I use freemarker as the result type. Other types like jsp or redirectAction worked fine. What am I missing?
ForwardActionTest.java:
public class ForwardActionTest extends StrutsSpringTestCase {
....
public void testExecuteAction() throws Exception {
String output = executeAction("/home.do"); <--- Exception points here
...
}
}
struts.xml
<action name="home" class="forwardAction">
<result type="freemarker">templates/home.ftl</result>
</action>
templates/home.ftl
Hello! You are home!
Stacktrace:
javax.servlet.ServletException: Error code [500], Error: [Template /templates/home.ftl not found.]
at org.apache.struts2.StrutsTestCase.executeAction(StrutsTestCase.java:120)
at com.telus.ccs.survey.web.action.ForwardActionTest.testExecuteAction(ForwardActionTest.java:22)
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 junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
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)