isis-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Haywood <...@haywood-associates.co.uk>
Subject Re: nullpointer exception when testing event
Date Mon, 30 Mar 2015 11:57:22 GMT
the NPE is at:

    at org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:151)

which is:

    switch (ev.getEventPhase()) {

and so the event isn't properly initialized in the test.

The issue this time is that the event has an old deprecated
getPhase()/setPhase() and a newer getEventPhase()/setEventPhase().  Your
test is calling setPhase() but your code checks for getEventPhase():


            Party.RemoveEvent event = new RemoveEvent(oldParty, null,
(Object[]) null);
            event.setEventPhase(EventPhase.VALIDATE);


To avoid future confusion we ought to refactor Party.RemoveEvent to inherit
from AbstractDomainEvent rather than (deprecated) AbstractInteractionEvent;
but there's no urgency.

Cheers
Dan

PS: The deprecated stuff was as a result of the new annotations in ISIS-970.



On 30 March 2015 at 12:41, <JohanDoornenbal@filternet.nl> wrote:

>
> Thank you Dan,
>
>
>
> I refactored my code and verfied it testing 'by hand' in de UI. It works
> as expected (like my old code did b.t.w.). [1] [2]
>
> Still my test [3] breaks (both for ProjectRoles and ProgramRoles. I am
> afraid I overlook something in the test but I cannot discover it.
>
>
>
>
>
> [1]
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/dom/src/main/java/org/estatio/dom/project/ProgramRoles.java#L152
>
> [2]
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/dom/src/main/java/org/estatio/dom/project/ProjectRoles.java#L158
>
> [3]
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/integtests/src/test/java/org/estatio/integtests/projects/ProjectRolesTest.java#L193
>
>
>
>
>         java.lang.NullPointerException
>
>         at org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:151)
>
>         at
> org.estatio.integtests.projects.ProjectRolesTest$OnPartyRemove.invalidBecauseNoReplacement(ProjectRolesTest.java:193)
>
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
>         at java.lang.reflect.Method.invoke(Method.java:601)
>
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>
>         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>
>         at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>
>         at
> org.apache.isis.core.integtestsupport.IntegrationTestAbstract$IsisTransactionRule$1.evaluate(IntegrationTestAbstract.java:199)
>
>         at
> org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2$1.evaluate(JUnitRuleMockery2.java:146)
>
>         at
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
>
>         at
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
>
>         at org.junit.rules.RunRules.evaluate(RunRules.java:20)
>
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
>
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>
>         at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>
>         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)
>
>
>
>         java.lang.NullPointerException
>
>         at org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:151)
>
>         at
> org.estatio.integtests.projects.ProjectRolesTest$OnPartyRemove.invalidBecauseNoReplacement(ProjectRolesTest.java:193)
>
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
>         at java.lang.reflect.Method.invoke(Method.java:601)
>
>         at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>
>         at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>
>         at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>
>         at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>
>         at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>
>         at
> org.apache.isis.core.integtestsupport.IntegrationTestAbstract$IsisTransactionRule$1.evaluate(IntegrationTestAbstract.java:199)
>
>         at
> org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2$1.evaluate(JUnitRuleMockery2.java:146)
>
>         at
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
>
>         at
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
>
>         at org.junit.rules.RunRules.evaluate(RunRules.java:20)
>
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
>
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
>
>         at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
>
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>
>         at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>
>         at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
>
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>
>         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 don't think the NPE is in the test code, it seems to be in the prod code,
> ie ProjectRoles.
>
> Looking at line 148 of ProjectRoles [1], actually I think your problem is
> because we recently removed the reuse of the domain event from the validate
> to the executing phase; it turned out to be problematic to support (for
> reasons I won't go into).
>
> So instead the Scratchpad service should be used to pass info from the
> validate to executing phases.
>
> The Estatio code has been refactored, but I guess you'll need to make a
> similar change in your new "project" module.
>
> Compare [2] (your fork of AgreementRole) vs [3] (the refactored version)
>
> HTH
> Dan
>
>
> [1]
>
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/dom/src/main/java/org/estatio/dom/project/ProgramRoles.java#L148
> [2]
>
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/dom/src/main/java/org/estatio/dom/agreement/AgreementRoles.java#L146
> [3]
>
> https://github.com/estatio/estatio/blob/master/estatioapp/dom/src/main/java/org/estatio/dom/agreement/AgreementRoles.java#L149
>
>
>
>
> On 30 March 2015 at 10:00,  wrote:
>
> >
> >
> > Hi,
> >
> >
> >
> > I am writing an integrationtest in Estatio - testing a RemoveEvent on the
> > eventbus.
> >
> >
> >
> > Can anybody explain the nullPointer exception I get at [1]
> >
> > The same constuction seems to work at [2]
> >
> > What am I missing?
> >
> >
> >
> > grtz Johan
> >
> >
> >
> > [1]
> >
> >
> >
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/integtests/src/test/java/org/estatio/integtests/projects/ProgramRolesTest.java#L208
> >
> >
> > [2]
> >
> https://github.com/johandoornenbal/estatio/blob/projects/estatioapp/integtests/src/test/java/org/estatio/integtests/agreement/AgreementRolesTest.java#L192
> >
> >
> >
> >
> >         java.lang.NullPointerException
> >
> >         at org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:147)
> >
> >         at
> >
> org.estatio.integtests.projects.ProjectRolesTest$OnPartyRemove.invalidBecauseNoReplacement(ProjectRolesTest.java:193)
> >
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >
> >         at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> >
> >         at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >
> >         at java.lang.reflect.Method.invoke(Method.java:601)
> >
> >         at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> >
> >         at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >
> >         at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> >
> >         at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >
> >         at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >         at
> >
> org.apache.isis.core.integtestsupport.IntegrationTestAbstract$IsisTransactionRule$1.evaluate(IntegrationTestAbstract.java:199)
> >
> >         at
> >
> org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2$1.evaluate(JUnitRuleMockery2.java:146)
> >
> >         at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >         at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >         at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> >
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> >
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> >
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> >
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> >
> >         at
> org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> >
> >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> >
> >         at
> org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> >
> >         at
> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> >
> >         at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> >
> >         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)
> >
> >
> >
> >
> >                 java.lang.NullPointerException
> >
> >                 at
> > org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:147)
> >
> >                 at
> >
> org.estatio.integtests.projects.ProjectRolesTest$OnPartyRemove.invalidBecauseNoReplacement(ProjectRolesTest.java:193)
> >
> >                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> > Method)
> >
> >                 at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> >
> >                 at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >
> >                 at java.lang.reflect.Method.invoke(Method.java:601)
> >
> >                 at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> >
> >                 at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >
> >                 at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> >
> >                 at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >
> >                 at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >                 at
> >
> org.apache.isis.core.integtestsupport.IntegrationTestAbstract$IsisTransactionRule$1.evaluate(IntegrationTestAbstract.java:199)
> >
> >                 at
> >
> org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2$1.evaluate(JUnitRuleMockery2.java:146)
> >
> >                 at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >                 at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >                 at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> >
> >                 at
> > org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> >
> >                 at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> >
> >                 at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> >
> >                 at
> > org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> >
> >                 at
> > org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> >
> >                 at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> >
> >                 at
> > org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> >
> >                 at
> > org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> >
> >                 at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >                 at
> > org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> >
> >                 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)
> >
> >
> >         ava.lang.NullPointerException
> >
> >         at org.estatio.dom.project.ProjectRoles.on(ProjectRoles.java:147)
> >
> >         at
> >
> org.estatio.integtests.projects.ProjectRolesTest$OnPartyRemove.invalidBecauseNoReplacement(ProjectRolesTest.java:193)
> >
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >
> >         at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> >
> >         at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >
> >         at java.lang.reflect.Method.invoke(Method.java:601)
> >
> >         at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
> >
> >         at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> >
> >         at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
> >
> >         at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> >
> >         at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >         at
> >
> org.apache.isis.core.integtestsupport.IntegrationTestAbstract$IsisTransactionRule$1.evaluate(IntegrationTestAbstract.java:199)
> >
> >         at
> >
> org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2$1.evaluate(JUnitRuleMockery2.java:146)
> >
> >         at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >         at
> >
> org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
> >
> >         at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> >
> >         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
> >
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> >
> >         at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> >
> >         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> >
> >         at
> org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> >
> >         at
> > org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> >
> >         at
> org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> >
> >         at
> org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> >
> >         at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> >
> >         at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> >
> >         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)
> >
> >
> >
> >
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message