[MGNLFORUM-220] fix DefaultForumManagerTest Created: 15/Jan/14  Updated: 19/Feb/14  Resolved: 17/Feb/14

Status: Closed
Project: Forum (closed)
Component/s: persistence, security
Affects Version/s: None
Fix Version/s: 3.3

Type: Bug Priority: Neutral
Reporter: Christoph Meier Assignee: Christoph Meier
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
causality
caused by MGNLFORUM-230 Allow dependency to 5.2.2 (main and UI) Closed
Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

fix DefaultForumManagerTest#testCreatingForumShouldUseUniqueCleanUpNameAndAddTitleProperty
and #testCreatingForumShouldCleanUpNameAddTitlePropertyAndCreateAdhocRoles.
These 2 methods fail with Unexpected method call getWorkspace(); see stackTrace

java.lang.AssertionError:
Unexpected method call getWorkspace():
isExist("/mon-forum"): expected: 1, actual: 0
getRoot(): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:32)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:61)
at com.sun.proxy.$Proxy5.getWorkspace(Unknown Source)
at info.magnolia.cms.core.Path.getUniqueLabel(Path.java:148)
at info.magnolia.module.forum.DefaultForumManager.createForum(DefaultForumManager.java:133)
at info.magnolia.module.forum.DefaultForumManager.createForum(DefaultForumManager.java:126)
at info.magnolia.module.forum.DefaultForumManagerTest.testCreatingForumShouldCleanUpNameAddTitlePropertyAndCreateAdhocRoles(DefaultForumManagerTest.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

java.lang.AssertionError:
Unexpected method call getWorkspace():
isExist("/mon-forum"): expected: 1, actual: 0
isExist("/mon-forum0"): expected: 1, actual: 0
getRoot(): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:32)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:61)
at com.sun.proxy.$Proxy2.getWorkspace(Unknown Source)
at info.magnolia.cms.core.Path.getUniqueLabel(Path.java:148)
at info.magnolia.module.forum.DefaultForumManager.createForum(DefaultForumManager.java:133)
at info.magnolia.module.forum.DefaultForumManager.createForum(DefaultForumManager.java:126)
at info.magnolia.module.forum.DefaultForumManagerTest.testCreatingForumShouldUseUniqueCleanUpNameAndAddTitleProperty(DefaultForumManagerTest.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.junit.runner.JUnitCore.run(JUnitCore.java:130)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)



 Comments   
Comment by Christoph Meier [ 23/Jan/14 ]

As long as this forum depends on magnolia-core 5.2, but not higher, the test works fine.

Comment by Christoph Meier [ 05/Feb/14 ]

since we want to have dependecy to 5.2.2, this must be "fixed", therefore reopenend.

Comment by Jan Haderka [ 13/Feb/14 ]

While the use of deprecated API in the test might be forced by code under the test that was not updated yet, there is no reason for not replacing EasyMock with Mockito for the tests that are being modified.

Comment by Christoph Meier [ 17/Feb/14 ]

Changing from Easymock- to Mockito-Framework was not completely trivial; many of the test would must have been changed significant.
Hence i decided to rewrite the test-class using a RepositoryTestCase which made it easier and allowed much more meaningful „black box testing“; at the same time could get rid of usage of „old content-API“.

Comment by Daniel Lipp [ 17/Feb/14 ]

DefaultForumManagerTest

  • remove unused logger, accessManager + mgnlContext
  • use our import conventions
  • static imports before non-static ones
  • use .* for more than one static import to the same package
    -> import static org.junit.Assert.*;
    import static org.mockito.Mockito.*;

AbstractForumRepositoryTestCase

  • should not catch + log RepositoryException but leave it untreated (declared with throws Exception)
    -> that would guarantee that the test fails right in setup in case of probs with repo
    -> remove logger that's then no longer used

(btw: unless there's more subclasses of AbstractForumRepositoryTestCase coming soon, I'd merge that code into DefaultForumManagerTest

Generated at Mon Feb 12 02:01:51 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.