3333 */
3434package info .magnolia .cms .beans .config ;
3535
36- import static org .easymock .EasyMock .*;
37-
38- import javax .jcr .PropertyType ;
39-
40- import info .magnolia .cms .core .SystemProperty ;
41- import info .magnolia .objectfactory .Components ;
42- import info .magnolia .test .TestMagnoliaConfigurationProperties ;
43- import junit .framework .TestCase ;
44-
36+ import static org .junit .Assert .assertEquals ;
37+ import static org .junit .Assert .assertTrue ;
38+ import static org .mockito .Mockito .mock ;
39+ import static org .mockito .Mockito .when ;
4540import info .magnolia .cms .core .Content ;
4641import info .magnolia .cms .core .HierarchyManager ;
4742import info .magnolia .cms .core .NodeData ;
48- import info .magnolia .test . ComponentsTestUtil ;
43+ import info .magnolia .cms . core . SystemProperty ;
4944import info .magnolia .context .Context ;
5045import info .magnolia .context .MgnlContext ;
5146import info .magnolia .context .WebContext ;
47+ import info .magnolia .objectfactory .Components ;
48+ import info .magnolia .test .ComponentsTestUtil ;
49+ import info .magnolia .test .TestMagnoliaConfigurationProperties ;
5250import info .magnolia .test .mock .MockRepositoryAcquiringStrategy ;
5351
52+ import javax .jcr .PropertyType ;
53+
54+ import org .junit .After ;
55+ import org .junit .Before ;
56+ import org .junit .Test ;
57+
5458/**
55- * @author had
56- * @version $Id:$
59+ * @version $Id$
5760 */
58- public class URI2RepositoryMappingTest extends TestCase {
61+ public class URI2RepositoryMappingTest {
5962
60- @ Override
61- protected void tearDown () throws Exception {
63+ @ After
64+ public void tearDown () throws Exception {
6265 MgnlContext .setInstance (null );
6366 ComponentsTestUtil .clear ();
64- super .tearDown ();
6567 }
6668
67- @ Override
68- protected void setUp () throws Exception {
69- super .setUp ();
69+ @ Before
70+ public void setUp () throws Exception {
7071 // some tests do not cleanup properly so we need to cleanup here before starting to be sure.
7172 MgnlContext .setInstance (null );
7273 ComponentsTestUtil .clear ();
7374 SystemProperty .setMagnoliaConfigurationProperties (new TestMagnoliaConfigurationProperties ());
7475 }
7576
77+ @ Test
7678 public void testGetUri () throws Exception {
7779 ComponentsTestUtil .setInstance (ServerConfiguration .class , new ServerConfiguration ());
7880 ServerConfiguration .getInstance ().setDefaultExtension ("bla" );
7981 URI2RepositoryMapping mapping = new URI2RepositoryMapping ();
8082 mapping .setRepository ("dummy-repo" );
8183 mapping .setURIPrefix ("/blabla/" );
8284 // instance is set only in constructor ...
83- final Context context = createStrictMock (Context .class );
84- final HierarchyManager hm = createStrictMock (HierarchyManager .class );
85- final Content cnt = createStrictMock (Content .class );
86- final Content root = createStrictMock (Content .class );
87- final NodeData docu = createStrictMock (NodeData .class );
88- expect (context .getHierarchyManager ("dummy-repo" )).andReturn (hm );
89- expect (hm .isExist ("/Test/image" )).andReturn (Boolean .TRUE );
90- expect (hm .isNodeData ("/Test/image" )).andReturn (Boolean .TRUE );
91- expect (hm .isNodeData ("/Test" )).andReturn (Boolean .FALSE );
92- expect (hm .isNodeData ("/Test/image" )).andReturn (Boolean .TRUE );
93- expect (hm .getContent ("/Test" )).andReturn (cnt );
94- expect (cnt .getNodeData ("image" )).andReturn (docu );
95- expect (hm .getName ()).andReturn ("dummy-repo" );
96- expect (cnt .getHierarchyManager ()).andReturn (hm );
97- expect (cnt .isNodeType ("mix:referenceable" )).andReturn (true );
98- expect (cnt .getUUID ()).andReturn ("uu-something-real" );
85+ final Context context = mock (Context .class );
86+ final HierarchyManager hm = mock (HierarchyManager .class );
87+ final Content cnt = mock (Content .class );
88+ final NodeData docu = mock (NodeData .class );
89+ when (context .getHierarchyManager ("dummy-repo" )).thenReturn (hm );
90+ when (hm .isNodeData ("/Test" )).thenReturn (Boolean .FALSE );
91+ when (hm .isNodeData ("/Test/image" )).thenReturn (Boolean .TRUE );
92+ when (hm .getContent ("/Test" )).thenReturn (cnt );
93+ when (cnt .getNodeData ("image" )).thenReturn (docu );
94+ when (cnt .getHierarchyManager ()).thenReturn (hm );
9995
100- expect (docu .getType ()).andReturn (PropertyType .BINARY );
101- expect (docu .getAttribute ("nodeDataTemplate" )).andReturn ("" );
102- expect (docu .getAttribute ("extension" )).andReturn ("jpg" );
103- expect (docu .getAttribute ("fileName" )).andReturn ("blah" );
104- expect (docu .getAttribute ("contentType" )).andReturn ("mgnl:resource" );
105- expect (docu .getAttribute ("size" )).andReturn ("1234" );
106- expect (docu .getType ()).andReturn (PropertyType .BINARY );
107- expect (docu .getAttribute ("nodeDataTemplate" )).andReturn ("" );
108- expect (docu .getAttribute ("extension" )).andReturn ("jpg" );
109- expect (docu .getAttribute ("fileName" )).andReturn ("blah" );
110- expect (docu .getAttribute ("contentType" )).andReturn ("mgnl:resource" );
111- expect (docu .getAttribute ("size" )).andReturn ("1234" );
112- replay (context , hm , cnt , root , docu );
96+ when (docu .getType ()).thenReturn (PropertyType .BINARY );
97+ when (docu .getAttribute ("extension" )).thenReturn ("jpg" );
98+ when (docu .getAttribute ("fileName" )).thenReturn ("blah" );
11399 MgnlContext .setInstance (context );
114100 String uri = mapping .getURI ("/Test/image" );
115101 assertEquals ("Detected double slash in generated link path." ,-1 , uri .indexOf ("//" ));
116102 assertTrue ("Incorrect file name generated." ,uri .endsWith ("/blah.jpg" ));
117- verify (context , hm , cnt , root , docu );
118103 }
119104
105+ @ Test
120106 public void testGetHandleStripsExtensionInclTheDot () throws Exception {
121- WebContext context = createNiceMock (WebContext .class );
122- HierarchyManager hm = createNiceMock (HierarchyManager .class );
107+ WebContext context = mock (WebContext .class );
108+ HierarchyManager hm = mock (HierarchyManager .class );
123109 MgnlContext .setInstance (context );
124110 MockRepositoryAcquiringStrategy strategy = Components .getSingleton (MockRepositoryAcquiringStrategy .class );
125111 strategy .addHierarchyManager ("config" , hm );
@@ -128,13 +114,11 @@ public void testGetHandleStripsExtensionInclTheDot() throws Exception {
128114 ServerConfiguration .getInstance ().setDefaultExtension ("ext" );
129115 ComponentsTestUtil .setInstance (URI2RepositoryManager .class , new URI2RepositoryManager ());
130116 Object [] objs = new Object [] {context , hm };
131- replay (objs );
132117 String handle = URI2RepositoryManager .getInstance ().getHandle ("/blah.ext" );
133118 assertEquals ("/blah" , handle );
134119 handle = URI2RepositoryManager .getInstance ().getHandle ("/b.l/ah.ext" );
135120 assertEquals ("/b.l/ah" , handle );
136121 handle = URI2RepositoryManager .getInstance ().getHandle ("/bl.ah.ext" );
137122 assertEquals ("/bl.ah" , handle );
138- verify (objs );
139123 }
140124}
0 commit comments