KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > PageActionTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import java.io.*;
24 import java.util.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.aikp.*;
30 import com.methodhead.test.*;
31 import com.methodhead.auth.*;
32 import com.methodhead.tree.*;
33 import com.methodhead.sitecontext.*;
34 import com.methodhead.*;
35 import com.methodhead.util.*;
36 import servletunit.struts.*;
37 import org.apache.cactus.*;
38 import org.apache.struts.util.*;
39 import org.apache.struts.action.*;
40 import javax.swing.tree.*;
41
42 public class PageActionTest extends CactusStrutsTestCase {
43
44   static {
45     TestUtils.initLogger();
46     TestUtils.initDb();
47   }
48
49   private SiteMap siteMap = null;
50   private Link link = null;
51   private Link sublink = null;
52   private Page page = null;
53   private SiteMapTree tree = null;
54   private DefaultMutableTreeNode node = null;
55   private DefaultMutableTreeNode subnode = null;
56   private FoldingTreeNode foldingNode = null;
57   private DynaActionForm form = null;
58   private List list = null;
59   private LabelValueBean bean = null;
60   private Panel panel = null;
61   private TextModule textModule = null;
62   private Module module = null;
63
64   private Page page1_ = null;
65   private Page page2_ = null;
66   private Page page3_ = null;
67   private Page page4_ = null;
68   private Page page5_ = null;
69
70   private Link link1_ = null;
71   private Link link2_ = null;
72   private Link link3_ = null;
73   private Link link4_ = null;
74   private Link link5_ = null;
75
76   private void createData() {
77     Panel panel = null;
78
79     panel = new Panel();
80     panel.setName( "body" );
81     panel.setModuleClass( "com.methodhead.shim.MockModule" );
82
83     page1_ = new Page();
84     page1_.set( "title", "Page1" );
85     page1_.set( "alttitle", "altPage1" );
86     page1_.set( "aliasname", "page1" );
87     page1_.setBoolean( "hidden", false );
88     page1_.setString( "template", "template.jsp" );
89     page1_.set( "metadescription", "metadescription" );
90     page1_.set( "metakeywords", "metakeywords" );
91     page1_.addPanel( panel );
92     page1_.setSiteContext( SiteContext.getDefaultContext() );
93     page1_.saveNew();
94
95     page2_ = new Page();
96     page2_.set( "title", "Page2" );
97     page2_.set( "aliasname", "page2" );
98     page2_.setBoolean( "hidden", true );
99     page2_.setString( "template", "template.jsp" );
100     page2_.addPanel( panel );
101     page2_.setSiteContext( SiteContext.getDefaultContext() );
102     page2_.saveNew();
103
104     page3_ = new Page();
105     page3_.set( "title", "Page3" );
106     page3_.set( "aliasname", "page3" );
107     page3_.setBoolean( "hidden", false );
108     page3_.setString( "template", "template.jsp" );
109     page3_.addPanel( panel );
110     page3_.setSiteContext( SiteContext.getDefaultContext() );
111     page3_.saveNew();
112
113     page4_ = new Page();
114     page4_.set( "title", "Page4" );
115     page4_.set( "aliasname", "page4" );
116     page4_.setBoolean( "hidden", false );
117     page4_.setString( "template", "template.jsp" );
118     page4_.addPanel( panel );
119     page4_.setSiteContext( SiteContext.getDefaultContext() );
120     page4_.saveNew();
121
122     page5_ = new Page();
123     page5_.set( "title", "Page5" );
124     page5_.set( "aliasname", "page5" );
125     page5_.setBoolean( "hidden", false );
126     page5_.setString( "template", "template.jsp" );
127     page5_.addPanel( panel );
128     page5_.setSiteContext( SiteContext.getDefaultContext() );
129     page5_.saveNew();
130   }
131
132   private void createSiteMap() {
133
134     link1_ = new Link();
135     link1_.setPageId( 1 );
136     link1_.setTitle( "Page1" );
137     link1_.setAlias( "page1" );
138
139     link2_ = new Link();
140     link2_.setPageId( 2 );
141     link2_.setTitle( "Page2" );
142     link2_.setAlias( "page2" );
143
144     link3_ = new Link();
145     link3_.setPageId( 3 );
146     link3_.setTitle( "Page3" );
147     link3_.setAlias( "page3" );
148
149     link4_ = new Link();
150     link4_.setPageId( 4 );
151     link4_.setTitle( "Page4" );
152     link4_.setAlias( "page4" );
153
154     link5_ = new Link();
155     link5_.setPageId( 5 );
156     link5_.setTitle( "Page5" );
157     link5_.setAlias( "page5" );
158
159     link1_.add( link2_ );
160     link2_.add( link3_ );
161     link1_.add( link4_ );
162     link1_.add( link5_ );
163
164     SiteMap siteMap = ShimUtils.getSiteMap( request );
165     siteMap.setRoot( link1_ );
166     siteMap.save();
167
168     SiteMapTree tree = ( SiteMapTree )getSession().getAttribute( ShimGlobals.SITEMAPTREE_KEY );
169     tree.build( siteMap );
170   }
171
172   public PageActionTest( String JavaDoc name ) {
173     super( name );
174   }
175
176   public void setUp()
177   throws
178     Exception JavaDoc {
179
180     TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) );
181
182     //setLogLevel( Level.DEBUG );
183
try {
184       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
185
186       super.setUp();
187
188       //
189
// login an admin
190
//
191
TestData.createUsers();
192       AuthUtil.setUser( getRequest(), TestData.user1 );
193
194       //
195
// use the default site context
196
//
197
getSession().setAttribute( SiteContext.SITECONTEXT_KEY, SiteContext.getDefaultContext() );
198
199       getSession().removeAttribute( ShimGlobals.SITEMAPTREE_KEY );
200       getSession().getServletContext().removeAttribute( ShimGlobals.SITEMAPMAP_KEY );
201
202       //
203
// set up the tree
204
//
205
tree = new SiteMapTree();
206       tree.build( ShimUtils.getSiteMap( request ) );
207       getSession().setAttribute( ShimGlobals.SITEMAPTREE_KEY, new SiteMapTree() );
208     }
209     catch ( Exception JavaDoc e ) {
210       fail( e.getMessage() );
211     }
212   }
213
214   public void tearDown()
215   throws
216     Exception JavaDoc {
217
218     super.tearDown();
219   }
220
221   public void testDoNewPageForm() throws Exception JavaDoc {
222     PageForm form = null;
223     List l = null;
224     LabelValueBean option = null;
225
226     //
227
// without site map destination
228
//
229
setRequestPathInfo( "/newPageForm" );
230     actionPerform();
231
232     verifyForward( "form" );
233
234     form = ( PageForm )getActionForm();
235     l = ( List )form.get( "templates" );
236
237     assertEquals( "", form.get( "destid" ) );
238     assertEquals( "", form.get( "position" ) );
239
240     assertEquals( 5, l.size() );
241
242     option = ( LabelValueBean )l.get( 0 );
243
244     assertEquals( "", option.getValue() );
245     assertEquals( "Select...", option.getLabel() );
246
247     option = ( LabelValueBean )l.get( 1 );
248
249     assertEquals( "template.jsp", option.getValue() );
250     assertEquals( "Template", option.getLabel() );
251   }
252
253   public void testDoNewPageFormWithSiteMapDest() throws Exception JavaDoc {
254     PageForm form = null;
255     List l = null;
256     LabelValueBean option = null;
257
258     //
259
// with site map destination
260
//
261
setRequestPathInfo( "/newPageForm" );
262     addRequestParameter( "destid", "666" );
263     addRequestParameter( "position", "under" );
264     actionPerform();
265
266     verifyForward( "form" );
267
268     form = ( PageForm )getActionForm();
269     l = ( List )form.get( "templates" );
270
271     assertEquals( "666", form.get( "destid" ) );
272     assertEquals( "under", form.get( "position" ) );
273
274     assertEquals( 5, l.size() );
275
276     option = ( LabelValueBean )l.get( 0 );
277
278     assertEquals( "", option.getValue() );
279     assertEquals( "Select...", option.getLabel() );
280
281     option = ( LabelValueBean )l.get( 1 );
282
283     assertEquals( "template.jsp", option.getValue() );
284     assertEquals( "Template", option.getLabel() );
285   }
286
287   public void testDoConfigurePageForm() throws Exception JavaDoc {
288     createData();
289
290     addRequestParameter( "id", "" + page1_.getInt( "id" ) );
291     setRequestPathInfo( "/configurePageForm" );
292     actionPerform();
293
294     verifyForward( "form" );
295
296     //
297
// form initialization tested in testDoNewPageForm()
298
//
299
form = ( PageForm )getActionForm();
300     assertEquals( page1_.getString( "title" ), form.get( "title" ) );
301     assertEquals( page1_.getString( "aliasname" ), form.get( "alias" ) );
302     assertEquals( page1_.getString( "template" ), form.get( "template" ) );
303     assertEquals( "altPage1", form.get( "alttitle" ) );
304     assertEquals( "metadescription", form.get( "metadescription" ) );
305     assertEquals( "metakeywords", form.get( "metakeywords" ) );
306   }
307
308   public void testDoConfigurePageFormHiddenPage() throws Exception JavaDoc {
309     createData();
310
311     //
312
// a page with hidden set to true
313
//
314
addRequestParameter( "id", "" + page2_.getInt( "id" ) );
315     setRequestPathInfo( "/configurePageForm" );
316     actionPerform();
317
318     verifyForward( "form" );
319
320     //
321
// form initialization tested in testDoNewPageForm()
322
//
323
form = ( PageForm )getActionForm();
324     assertEquals( "yes", form.get( "hidden" ) );
325   }
326
327   public void testDoConfigurePageNewCancel() {
328     try {
329       //
330
// cancelling
331
//
332
setRequestPathInfo( "/configurePage" );
333       addRequestParameter( "cancel", "Cancel" );
334       actionPerform();
335
336       verifyForwardPath( "/home.do" );
337     }
338     catch ( Exception JavaDoc e ) {
339       e.printStackTrace();
340       fail();
341     }
342   }
343
344   public void testDoConfigurePageNew() {
345     try {
346       //
347
// no dest with an empty site map
348
//
349
clearRequestParameters();
350       setRequestPathInfo( "/configurePage" );
351       addRequestParameter( "title", "Page1" );
352       addRequestParameter( "alias", "page1" );
353       addRequestParameter( "hidden", "" );
354       addRequestParameter( "template", "template.jsp" );
355       addRequestParameter( "alttitle", "alttitle" );
356       addRequestParameter( "metadescription", "metadescription" );
357       addRequestParameter( "metakeywords", "metakeywords" );
358       actionPerform();
359
360       verifyForwardPath( "/editPage.do?id=1" );
361
362       page = new Page();
363       page.setSiteContext( SiteContext.getDefaultContext() );
364       page.load( new IntKey( 1 ) );
365
366       assertEquals( "Page1", page.getString( "title" ) );
367       assertEquals( "page1", page.getString( "aliasname" ) );
368       assertEquals( false, page.getBoolean( "hidden" ) );
369       assertEquals( "template.jsp", page.getString( "template" ) );
370       assertEquals( "alttitle", page.getString( "alttitle" ) );
371       assertEquals( "metadescription", page.getString( "metadescription" ) );
372       assertEquals( "metakeywords", page.getString( "metakeywords" ) );
373
374       assertNotNull( page.getPanels() );
375       assertEquals( 1, page.getPanels().size() );
376
377       panel = ( Panel )page.getPanels().get( "body" );
378
379       assertEquals( "body", panel.getName() );
380       assertEquals( ShimGlobals.DEFAULT_MODULE, panel.getModuleClass() );
381
382       textModule = new TextModule();
383       textModule.load( "page_id=1 AND panel='body'" );
384       assertEquals( "Insert your text here...", textModule.getString( "value" ) );
385
386       siteMap = ShimUtils.getSiteMap( request );
387       link = ( Link )siteMap.getRoot();
388       assertNotNull( link );
389       assertEquals( "Page1", link.getTitle() );
390       assertEquals( "page1", link.getAlias() );
391       assertEquals( false, link.getHidden() );
392       assertEquals( 1, link.getPageId() );
393       assertEquals( 0, link.getChildCount() );
394
395       siteMap = new SiteMap();
396       siteMap.setSiteContext( SiteContext.getDefaultContext() );
397       siteMap.load();
398       link = ( Link )siteMap.getRoot();
399       assertNotNull( link );
400       assertEquals( "Page1", link.getTitle() );
401       assertEquals( "page1", link.getAlias() );
402       assertEquals( false, link.getHidden() );
403       assertEquals( 1, link.getPageId() );
404       assertEquals( 0, link.getChildCount() );
405
406       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
407
408       assertNotNull( tree );
409
410       foldingNode = ( FoldingTreeNode )tree.getRoot();
411
412       assertNotNull( tree );
413       assertEquals( "Page1", foldingNode.getLabel() );
414       assertEquals( new Integer JavaDoc( 1 ), foldingNode.getUserObject() );
415       assertEquals( "editPage.do?id=1", foldingNode.getUrl() );
416       assertEquals( "PAGE", foldingNode.getIconHint() );
417       assertEquals( 0, foldingNode.getChildCount() );
418     }
419     catch ( Exception JavaDoc e ) {
420       e.printStackTrace();
421       fail();
422     }
423   }
424
425   public void testDoConfigurePage_NewAutoAlias() {
426     try {
427
428       //
429
// new page with out alias; alias should be automatically be generated
430
//
431
setRequestPathInfo( "/configurePage" );
432       addRequestParameter( "id", "" );
433       addRequestParameter( "title", "Page1" );
434       addRequestParameter( "alias", "" );
435       addRequestParameter( "template", "template.jsp" );
436       actionPerform();
437
438       verifyForwardPath( "/editPage.do?id=1" );
439
440       page = new Page();
441       page.setSiteContext( SiteContext.getDefaultContext() );
442       page.load( new IntKey( 1 ) );
443
444       assertEquals( "Page1", page.getString( "title" ) );
445       assertEquals( "page1", page.getString( "aliasname" ) );
446       assertEquals( "template.jsp", page.getString( "template" ) );
447     }
448     catch ( Exception JavaDoc e ) {
449       e.printStackTrace();
450       fail();
451     }
452   }
453
454   public void testDoConfigurePage_NewByCopy() {
455     try {
456       createData();
457       createSiteMap();
458
459       MockModule.setCopied( false );
460
461       setRequestPathInfo( "/configurePage" );
462       addRequestParameter( "id", "" );
463       addRequestParameter( "title", "Page6" );
464       addRequestParameter( "alias", "" );
465       addRequestParameter( "template", "" );
466       addRequestParameter( "copyfrom", "1" );
467       actionPerform();
468
469       verifyForwardPath( "/editPage.do?id=6" );
470
471       page = new Page();
472       page.setSiteContext( SiteContext.getDefaultContext() );
473       page.load( new IntKey( 6 ) );
474
475       assertEquals( "Page6", page.getString( "title" ) );
476       assertEquals( "", page.getString( "alttitle" ) );
477       assertEquals( "page6", page.getString( "aliasname" ) );
478       assertEquals( "template.jsp", page.getString( "template" ) );
479       assertEquals( "metadescription", page.getString( "metadescription" ) );
480       assertEquals( "metakeywords", page.getString( "metakeywords" ) );
481
482       panel = ( Panel )page.getPanels().get( "body" );
483       assertEquals( "body", panel.getName() );
484       assertEquals( "com.methodhead.shim.MockModule", panel.getModuleClass() );
485       assertEquals( true, MockModule.isCopied() );
486     }
487     catch ( Exception JavaDoc e ) {
488       e.printStackTrace();
489       fail();
490     }
491   }
492
493   public void testDoConfigurePageNewAutoAliasExisting() {
494     try {
495       createData();
496
497       //
498
// alias should be automatically generated and incremented
499
//
500
setRequestPathInfo( "/configurePage" );
501       addRequestParameter( "title", "Page1" );
502       addRequestParameter( "alias", "" );
503       addRequestParameter( "template", "template.jsp" );
504       actionPerform();
505
506       verifyForwardPath( "/editPage.do?id=6" );
507
508       page = new Page();
509       page.setSiteContext( SiteContext.getDefaultContext() );
510       page.load( new IntKey( 6 ) );
511
512       assertEquals( "Page1", page.getString( "title" ) );
513       assertEquals( "page12", page.getString( "aliasname" ) );
514       assertEquals( "template.jsp", page.getString( "template" ) );
515     }
516     catch ( Exception JavaDoc e ) {
517       e.printStackTrace();
518       fail();
519     }
520   }
521
522   public void testDoConfigurePageNewUnderRoot() {
523     try {
524       Page page = null;
525       Panel panel = null;
526       TextModule textModule = null;
527       DynaActionForm form = null;
528       SiteMap siteMap = null;
529       Link link = null;
530       SiteMapTree tree = null;
531       FoldingTreeNode node = null;
532
533       createData();
534       createSiteMap();
535       setRequestPathInfo( "/configurePage" );
536       addRequestParameter( "title", "Page6" );
537       addRequestParameter( "alias", "page6" );
538       addRequestParameter( "template", "template.jsp" );
539       actionPerform();
540
541       verifyForwardPath( "/editPage.do?id=6" );
542
543       //
544
// just check the site map
545
//
546
siteMap = ShimUtils.getSiteMap( request );
547
548       link = ( Link )siteMap.getRoot();
549       assertNotNull( link );
550       assertEquals( "Page1", link.getTitle() );
551       assertEquals( "page1", link.getAlias() );
552       assertEquals( false, link.getHidden() );
553       assertEquals( 1, link.getPageId() );
554       assertEquals( 4, link.getChildCount() );
555
556       link = ( Link )link.getChildAt( 3 );
557       assertNotNull( link );
558       assertEquals( "Page6", link.getTitle() );
559       assertEquals( "page6", link.getAlias() );
560       assertEquals( false, link.getHidden() );
561       assertEquals( 6, link.getPageId() );
562       assertEquals( 0, link.getChildCount() );
563
564       siteMap = new SiteMap();
565       siteMap.setSiteContext( SiteContext.getDefaultContext() );
566       siteMap.load();
567       link = ( Link )siteMap.getRoot();
568
569       assertNotNull( link );
570       assertEquals( "Page1", link.getTitle() );
571       assertEquals( "page1", link.getAlias() );
572       assertEquals( false, link.getHidden() );
573       assertEquals( 1, link.getPageId() );
574       assertEquals( 4, link.getChildCount() );
575
576       link = ( Link )link.getChildAt( 3 );
577
578       assertNotNull( link );
579       assertEquals( "Page6", link.getTitle() );
580       assertEquals( "page6", link.getAlias() );
581       assertEquals( false, link.getHidden() );
582       assertEquals( 6, link.getPageId() );
583       assertEquals( 0, link.getChildCount() );
584
585       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
586
587       assertNotNull( tree );
588
589       node = ( FoldingTreeNode )tree.getRoot();
590
591       assertNotNull( node );
592       assertEquals( "Page1", node.getLabel() );
593       assertEquals( new Integer JavaDoc( 1 ), node.getUserObject() );
594       assertEquals( "editPage.do?id=1", node.getUrl() );
595       assertEquals( "PAGE", node.getIconHint() );
596       assertEquals( 4, node.getChildCount() );
597
598       node = ( FoldingTreeNode )node.getChildAt( 3 );
599
600       assertNotNull( node );
601       assertEquals( "Page6", node.getLabel() );
602       assertEquals( new Integer JavaDoc( 6 ), node.getUserObject() );
603       assertEquals( "editPage.do?id=6", node.getUrl() );
604       assertEquals( "PAGE", node.getIconHint() );
605       assertEquals( 0, node.getChildCount() );
606     }
607     catch ( Exception JavaDoc e ) {
608       e.printStackTrace();
609       fail();
610     }
611   }
612
613   public void testDoConfigurePageNewWithDestUnder() {
614     try {
615       SiteMap siteMap = null;
616       Link link = null;
617       SiteMapTree tree = null;
618       FoldingTreeNode node = null;
619
620       //
621
// no dest with the root set
622
//
623
createData();
624       createSiteMap();
625
626       setRequestPathInfo( "/configurePage" );
627       addRequestParameter( "title", "Page6" );
628       addRequestParameter( "alias", "page6" );
629       addRequestParameter( "template", "template.jsp" );
630       addRequestParameter( "destid", "2" );
631       addRequestParameter( "position", "under" );
632       actionPerform();
633
634       verifyForwardPath( "/editPage.do?id=6" );
635
636       //
637
// just check the site map
638
//
639
siteMap = ShimUtils.getSiteMap( request );
640
641       link = ( Link )siteMap.find( 2 );
642       assertNotNull( link );
643       assertEquals( 2, link.getChildCount() );
644
645       link = ( Link )link.getChildAt( 1 );
646       assertNotNull( link );
647       assertEquals( "Page6", link.getTitle() );
648       assertEquals( "page6", link.getAlias() );
649       assertEquals( false, link.getHidden() );
650       assertEquals( 6, link.getPageId() );
651       assertEquals( 0, link.getChildCount() );
652
653       siteMap = new SiteMap();
654       siteMap.setSiteContext( SiteContext.getDefaultContext() );
655       siteMap.load();
656       link = ( Link )siteMap.find( 2 );
657
658       assertNotNull( link );
659       assertEquals( 2, link.getChildCount() );
660
661       link = ( Link )link.getChildAt( 1 );
662
663       assertNotNull( link );
664       assertEquals( "Page6", link.getTitle() );
665       assertEquals( "page6", link.getAlias() );
666       assertEquals( false, link.getHidden() );
667       assertEquals( 6, link.getPageId() );
668       assertEquals( 0, link.getChildCount() );
669
670       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
671
672       assertNotNull( tree );
673
674       node = ( FoldingTreeNode )tree.find( 2 );
675
676       assertNotNull( node );
677       assertEquals( 2, node.getChildCount() );
678
679       node = ( FoldingTreeNode )node.getChildAt( 1 );
680
681       assertNotNull( node );
682       assertEquals( "Page6", node.getLabel() );
683       assertEquals( new Integer JavaDoc( 6 ), node.getUserObject() );
684       assertEquals( "editPage.do?id=6", node.getUrl() );
685       assertEquals( "PAGE", node.getIconHint() );
686       assertEquals( 0, node.getChildCount() );
687     }
688     catch ( Exception JavaDoc e ) {
689       e.printStackTrace();
690       fail();
691     }
692   }
693
694   public void testDoConfigurePageNewWithDestBefore() {
695     try {
696       //
697
// no dest with the root set
698
//
699
createData();
700       createSiteMap();
701
702       setRequestPathInfo( "/configurePage" );
703       addRequestParameter( "title", "Page6" );
704       addRequestParameter( "alias", "page6" );
705       addRequestParameter( "template", "template.jsp" );
706       addRequestParameter( "destid", "2" );
707       addRequestParameter( "position", "before" );
708       actionPerform();
709
710       verifyForwardPath( "/editPage.do?id=6" );
711
712       //
713
// just check the site map
714
//
715
siteMap = ShimUtils.getSiteMap( request );
716
717       link = ( Link )siteMap.find( 1 );
718       assertNotNull( link );
719       assertEquals( 4, link.getChildCount() );
720
721       link = ( Link )link.getChildAt( 0 );
722       assertNotNull( link );
723       assertEquals( "Page6", link.getTitle() );
724       assertEquals( "page6", link.getAlias() );
725       assertEquals( false, link.getHidden() );
726       assertEquals( 6, link.getPageId() );
727       assertEquals( 0, link.getChildCount() );
728
729       siteMap = new SiteMap();
730       siteMap.setSiteContext( SiteContext.getDefaultContext() );
731       siteMap.load();
732       link = ( Link )siteMap.find( 1 );
733
734       assertNotNull( link );
735       assertEquals( 4, link.getChildCount() );
736
737       link = ( Link )link.getChildAt( 0 );
738
739       assertNotNull( link );
740       assertEquals( "Page6", link.getTitle() );
741       assertEquals( "page6", link.getAlias() );
742       assertEquals( false, link.getHidden() );
743       assertEquals( 6, link.getPageId() );
744       assertEquals( 0, link.getChildCount() );
745
746       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
747
748       assertNotNull( tree );
749
750       foldingNode = ( FoldingTreeNode )tree.find( 1 );
751
752       assertNotNull( foldingNode );
753       assertEquals( 4, foldingNode.getChildCount() );
754
755       foldingNode = ( FoldingTreeNode )foldingNode.getChildAt( 0 );
756
757       assertNotNull( foldingNode );
758       assertEquals( "Page6", foldingNode.getLabel() );
759       assertEquals( new Integer JavaDoc( 6 ), foldingNode.getUserObject() );
760       assertEquals( "editPage.do?id=6", foldingNode.getUrl() );
761       assertEquals( "PAGE", foldingNode.getIconHint() );
762       assertEquals( 0, foldingNode.getChildCount() );
763     }
764     catch ( Exception JavaDoc e ) {
765       e.printStackTrace();
766       fail();
767     }
768   }
769
770   public void testDoConfigurePageNewWithDestAfter() {
771     try {
772       SiteMap siteMap = null;
773       Link link = null;
774       SiteMapTree tree = null;
775       FoldingTreeNode node = null;
776
777       //
778
// no dest with the root set
779
//
780
createData();
781       createSiteMap();
782
783       setRequestPathInfo( "/configurePage" );
784       addRequestParameter( "title", "Page6" );
785       addRequestParameter( "template", "template.jsp" );
786       addRequestParameter( "destid", "2" );
787       addRequestParameter( "position", "after" );
788       actionPerform();
789
790       verifyForwardPath( "/editPage.do?id=6" );
791
792       //
793
// just check the site map
794
//
795
siteMap = ShimUtils.getSiteMap( request );
796
797       link = ( Link )siteMap.find( 1 );
798       assertNotNull( link );
799       assertEquals( 4, link.getChildCount() );
800
801       link = ( Link )link.getChildAt( 1 );
802       assertNotNull( link );
803       assertEquals( "Page6", link.getTitle() );
804       assertEquals( "page6", link.getAlias() );
805       assertEquals( false, link.getHidden() );
806       assertEquals( 6, link.getPageId() );
807       assertEquals( 0, link.getChildCount() );
808
809       siteMap = new SiteMap();
810       siteMap.setSiteContext( SiteContext.getDefaultContext() );
811       siteMap.load();
812       link = ( Link )siteMap.find( 1 );
813
814       assertNotNull( link );
815       assertEquals( 4, link.getChildCount() );
816
817       link = ( Link )link.getChildAt( 1 );
818
819       assertNotNull( link );
820       assertEquals( "Page6", link.getTitle() );
821       assertEquals( "page6", link.getAlias() );
822       assertEquals( false, link.getHidden() );
823       assertEquals( 6, link.getPageId() );
824       assertEquals( 0, link.getChildCount() );
825
826       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
827
828       assertNotNull( tree );
829
830       node = ( FoldingTreeNode )tree.find( 1 );
831
832       assertNotNull( node );
833       assertEquals( 4, node.getChildCount() );
834
835       node = ( FoldingTreeNode )node.getChildAt( 1 );
836
837       assertNotNull( node );
838       assertEquals( "Page6", node.getLabel() );
839       assertEquals( "page6", link.getAlias() );
840       assertEquals( false, link.getHidden() );
841       assertEquals( new Integer JavaDoc( 6 ), node.getUserObject() );
842       assertEquals( "editPage.do?id=6", node.getUrl() );
843       assertEquals( "PAGE", node.getIconHint() );
844       assertEquals( 0, node.getChildCount() );
845     }
846     catch ( Exception JavaDoc e ) {
847       e.printStackTrace();
848       fail();
849     }
850   }
851
852   public void testDoConfigurePageCancel() {
853     try {
854       setRequestPathInfo( "/configurePage" );
855       addRequestParameter( "cancel", "Cancel" );
856       addRequestParameter( "id", "1" );
857       actionPerform();
858
859       verifyForwardPath( "/editPage.do?id=1" );
860     }
861     catch ( Exception JavaDoc e ) {
862       e.printStackTrace();
863       fail();
864     }
865   }
866
867   public void testDoConfigurePage() {
868     try {
869       Page page = null;
870       Panel panel = null;
871       TextModule textModule = null;
872       DynaActionForm form = null;
873       SiteMap siteMap = null;
874       Link link = null;
875       SiteMapTree tree = null;
876       FoldingTreeNode node = null;
877
878       createData();
879       createSiteMap();
880       setRequestPathInfo( "/configurePage" );
881       addRequestParameter( "id", "" + page1_.getInt( "id" ) );
882       addRequestParameter( "title", "Page1 Updated" );
883       addRequestParameter( "alias", "page1updated" );
884       addRequestParameter( "hidden", "yes" );
885       addRequestParameter( "template", "Template2.jsp" );
886       addRequestParameter( "alttitle", "alttitle" );
887       addRequestParameter( "metadescription", "metadescription" );
888       addRequestParameter( "metakeywords", "metakeywords" );
889       actionPerform();
890
891       verifyForwardPath( "/editPage.do?id=1" );
892
893       page = new Page();
894       page.setSiteContext( SiteContext.getDefaultContext() );
895       page.load( page1_.getKey() );
896
897       assertEquals( "Page1 Updated", page.getString( "title" ) );
898       assertEquals( "page1updated", page.getString( "aliasname" ) );
899       assertEquals( true, page.getBoolean( "hidden" ) );
900       assertEquals( "Template2.jsp", page.getString( "template" ) );
901
902       assertNotNull( page.getPanels() );
903       assertEquals( 2, page.getPanels().size() );
904
905       panel = ( Panel )page.getPanels().get( "body" );
906
907       assertEquals( "body", panel.getName() );
908       assertEquals( "com.methodhead.shim.MockModule", panel.getModuleClass() );
909
910       siteMap = ShimUtils.getSiteMap( request );
911       link = ( Link )siteMap.find( 1 );
912       assertNotNull( link );
913       assertEquals( "Page1 Updated", link.getTitle() );
914       assertEquals( "page1updated", link.getAlias() );
915       assertEquals( true, link.getHidden() );
916
917       siteMap = new SiteMap();
918       siteMap.setSiteContext( SiteContext.getDefaultContext() );
919       siteMap.load();
920       assertNotNull( link );
921       assertEquals( "Page1 Updated", link.getTitle() );
922       assertEquals( "page1updated", link.getAlias() );
923       assertEquals( true, link.getHidden() );
924
925       tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
926
927       assertNotNull( tree );
928
929       node = ( FoldingTreeNode )tree.find( 1 );
930
931       assertNotNull( node );
932       assertEquals( "Page1 Updated", node.getLabel() );
933     }
934     catch ( Exception JavaDoc e ) {
935       e.printStackTrace();
936       fail();
937     }
938   }
939
940   public void testDoEditPage() {
941     try {
942       createData();
943       MockModule.setConfigurable( true );
944       MockModule.setEditable( false );
945       setRequestPathInfo( "/editPage" );
946       addRequestParameter( "id", "" + page1_.getInt( "id" ) );
947       actionPerform();
948
949       verifyForward( null );
950     }
951     catch ( Exception JavaDoc e ) {
952       e.printStackTrace();
953       fail();
954     }
955   }
956
957   public void endDoEditPage( WebResponse response ) {
958     assertEquals("\n<a HREF=\"configurePanelForm.do?pageid=1&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" SRC=\"approot/images/panel_module.gif\"></a> <a HREF=\"configureModule.do?pageid=1&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" SRC=\"approot/images/panel_configure.gif\"></a>\nHello from MockModule.display().\n\n\n", response.getText() );
959   }
960
961   public void testDoEditPageByAlias() {
962     try {
963       createData();
964       MockModule.setConfigurable( true );
965       MockModule.setEditable( false );
966       setRequestPathInfo( "/editPage" );
967       addRequestParameter( "alias", "page1" );
968       actionPerform();
969
970       verifyForward( null );
971     }
972     catch ( Exception JavaDoc e ) {
973       e.printStackTrace();
974       fail();
975     }
976   }
977
978   public void endDoEditPageByAlias( WebResponse response ) {
979     assertEquals("\n<a HREF=\"configurePanelForm.do?pageid=1&panel=body\"><img title=\"Select Module\" border=0 align=\"middle\" SRC=\"approot/images/panel_module.gif\"></a> <a HREF=\"configureModule.do?pageid=1&panel=body\"><img title=\"Configure\" border=0 align=\"middle\" SRC=\"approot/images/panel_configure.gif\"></a>\nHello from MockModule.display().\n\n\n", response.getText() );
980   }
981
982   public void testDoEditPageByAliasPageNotFound() {
983     createData();
984
985     MockModule.setConfigurable( true );
986     MockModule.setEditable( false );
987
988     setRequestPathInfo( "/editPage" );
989     addRequestParameter( "alias", "invalidalias" );
990     actionPerform();
991
992     verifyForward( "pageNotFound" );
993   }
994
995   public void testDoEditPageByAliasPageNotFoundWithPage() throws Exception JavaDoc {
996     TestData.createPageNotFoundPage();
997     TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) );
998
999     setRequestPathInfo( "/editPage" );
1000    addRequestParameter( "alias", "invalidalias" );
1001    actionPerform();
1002  }
1003
1004  public void endDoEditPageByAliasPageNotFoundWithPage( WebResponse webResponse ) {
1005    assertEquals( "This is a template.\n", webResponse.getText() );
1006  }
1007
1008  public void testDoConfigureModule() {
1009    try {
1010      Page page = null;
1011      Panel panel = null;
1012
1013      panel = new Panel();
1014      panel.setName( "body" );
1015      panel.setModuleClass( "com.methodhead.shim.MockModule" );
1016      page = new Page();
1017      page.setString( "template", "template.jsp" );
1018      page.addPanel( panel );
1019      page.setSiteContext( SiteContext.getDefaultContext() );
1020      page.saveNew();
1021      setRequestPathInfo( "/configureModule" );
1022      addRequestParameter( "pageid", "" + page.getInt( "id" ) );
1023      addRequestParameter( "panel", "body" );
1024      actionPerform();
1025
1026      verifyForward( "accessDenied" ); // this is what MockModule returns
1027
}
1028    catch ( Exception JavaDoc e ) {
1029      e.printStackTrace();
1030      fail();
1031    }
1032  }
1033
1034  public void testDoEditPanel() {
1035    try {
1036      Page page = null;
1037      Panel panel = null;
1038
1039      panel = new Panel();
1040      panel.setName( "body" );
1041      panel.setModuleClass( "com.methodhead.shim.MockModule" );
1042      page = new Page();
1043      page.setString( "title", "Page1" );
1044      page.setString( "template", "template.jsp" );
1045      page.addPanel( panel );
1046      page.setSiteContext( SiteContext.getDefaultContext() );
1047      page.saveNew();
1048      setRequestPathInfo( "/editPanel" );
1049      addRequestParameter( "pageid", "" + page.getInt( "id" ) );
1050      addRequestParameter( "panel", "body" );
1051      actionPerform();
1052
1053      verifyForward( "editor" );
1054
1055      DynaActionForm form = ( DynaActionForm )getActionForm();
1056
1057      assertEquals( "Page1", form.get( "title" ) );
1058    }
1059    catch ( Exception JavaDoc e ) {
1060      e.printStackTrace();
1061      fail();
1062    }
1063  }
1064
1065  public void testDoEditPanelToolbar() {
1066    try {
1067      Page page = null;
1068      Panel panel = null;
1069
1070      panel = new Panel();
1071      panel.setName( "body" );
1072      panel.setModuleClass( "com.methodhead.shim.MockModule" );
1073      page = new Page();
1074      page.setString( "template", "template.jsp" );
1075      page.addPanel( panel );
1076      page.setSiteContext( SiteContext.getDefaultContext() );
1077      page.saveNew();
1078      setRequestPathInfo( "/editPanel" );
1079      addRequestParameter( "pageid", "" + page.getInt( "id" ) );
1080      addRequestParameter( "panel", "body" );
1081      addRequestParameter( "toolbar", "yes" );
1082      actionPerform();
1083
1084      verifyForward( "toolbar" );
1085    }
1086    catch ( Exception JavaDoc e ) {
1087      e.printStackTrace();
1088      fail();
1089    }
1090  }
1091
1092  public void testDoEditPanelEditWin() {
1093    try {
1094      Page page = null;
1095      Panel panel = null;
1096
1097      panel = new Panel();
1098      panel.setName( "body" );
1099      panel.setModuleClass( "com.methodhead.shim.MockModule" );
1100      page = new Page();
1101      page.setString( "template", "template.jsp" );
1102      page.addPanel( panel );
1103      page.setSiteContext( SiteContext.getDefaultContext() );
1104      page.saveNew();
1105      setRequestPathInfo( "/editPanel" );
1106      addRequestParameter( "pageid", "" + page.getInt( "id" ) );
1107      addRequestParameter( "panel", "body" );
1108      addRequestParameter( "editWin", "yes" );
1109      actionPerform();
1110
1111      assertEquals( ShimGlobals.MODE_RICHEDIT, request.getAttribute( ShimGlobals.MODE_KEY ) );
1112      verifyForward( null );
1113    }
1114    catch ( Exception JavaDoc e ) {
1115      e.printStackTrace();
1116      fail();
1117    }
1118  }
1119
1120  public void testDoSavePanel() {
1121    try {
1122      Page page = null;
1123      Panel panel = null;
1124
1125      panel = new Panel();
1126      panel.setName( "body" );
1127      panel.setModuleClass( "com.methodhead.shim.MockModule" );
1128      page = new Page();
1129      page.setString( "template", "template.jsp" );
1130      page.addPanel( panel );
1131      page.setSiteContext( SiteContext.getDefaultContext() );
1132      page.saveNew();
1133      setRequestPathInfo( "/savePanel" );
1134      addRequestParameter( "pageid", "" + page.getInt( "id" ) );
1135      addRequestParameter( "panel", "body" );
1136      addRequestParameter( "text", "Test text." );
1137      actionPerform();
1138
1139      assertEquals( "Test text.", MockModule.getText() );
1140      verifyForwardPath( "/editPage.do?id=" + page.getInt( "id" ) );
1141    }
1142    catch ( Exception JavaDoc e ) {
1143      e.printStackTrace();
1144      fail();
1145    }
1146  }
1147
1148  public void testApplyTemplate() {
1149    try {
1150      Page page = null;
1151      Panel panel = null;
1152      Panel panelConfig = null;
1153      Template template = null;
1154      TextModule textModule = null;
1155
1156      //
1157
// apply a template to a page with no panels
1158
//
1159
page = new Page();
1160      page.setSiteContext( SiteContext.getDefaultContext() );
1161      page.saveNew();
1162      template = new Template();
1163      template.setSiteContext( SiteContext.getDefaultContext() );
1164      template.load( request, "Template2.jsp" );
1165
1166      PageAction.applyTemplate( page, template );
1167      page.save();
1168
1169      assertEquals( 2, page.getPanels().keySet().size() );
1170
1171      panel = ( Panel )page.getPanels().get( "body" );
1172
1173      assertEquals( "com.methodhead.shim.TextModule", panel.getModuleClass() );
1174
1175      module = panel.getModule();
1176
1177      assertNotNull( module );
1178      assertEquals( TextModule.class, module.getClass() );
1179
1180      textModule = new TextModule();
1181      textModule.init( page, "body" );
1182      textModule.load();
1183
1184      assertEquals( "Insert your text here...", textModule.getString( "value" ) );
1185
1186      textModule.init( page, "body" );
1187      textModule.load();
1188
1189      assertEquals( "Insert your text here...", textModule.getString( "value" ) );
1190
1191      //
1192
// update the body text so we can verify that it didn't get changed on
1193
// the next applyTemplate()
1194
//
1195
textModule.setString( "value", "Updated text." );
1196      textModule.save();
1197
1198      //
1199
// apply a template without the footer panel
1200
//
1201
page.loadFull( page.getKey() );
1202      template = new Template();
1203      template.setSiteContext( SiteContext.getDefaultContext() );
1204      template.load( request, "template.jsp" );
1205
1206      PageAction.applyTemplate( page, template );
1207
1208      assertEquals( 1, page.getPanels().keySet().size() );
1209
1210      panel = ( Panel )page.getPanels().get( "body" );
1211
1212      assertEquals( "com.methodhead.shim.TextModule", panel.getModuleClass() );
1213
1214      textModule = new TextModule();
1215      textModule.init( page, "body" );
1216      textModule.load();
1217
1218      assertEquals( "Updated text.", textModule.getString( "value" ) );
1219
1220      try {
1221        textModule = new TextModule();
1222        textModule.load( "page_id=" + page.getInt( "id" ) + " AND panel='footer'" );
1223        fail( "Text module still in the database." );
1224      }
1225      catch ( Exception JavaDoc e ) {
1226        // success
1227
}
1228    }
1229    catch ( Exception JavaDoc e ) {
1230      e.printStackTrace();
1231      fail();
1232    }
1233  }
1234
1235  public void testDoDeletePageForm() {
1236    try {
1237      DynaActionForm form = null;
1238
1239      createData();
1240      createSiteMap();
1241      setRequestPathInfo( "/deletePageForm" );
1242      addRequestParameter( "id", "" + page1_.getInt( "id" ) );
1243      actionPerform();
1244
1245      verifyForward( "form" );
1246
1247      form = ( DynaActionForm )getActionForm();
1248
1249      assertEquals( "Page1", form.get( "title" ) );
1250      assertEquals( "1", form.get( "id" ) );
1251      assertEquals( "promote", form.get( "delOption" ) );
1252    }
1253    catch ( Exception JavaDoc e ) {
1254      e.printStackTrace();
1255      fail();
1256    }
1257  }
1258
1259  public void testDoDeletePageWithChildren() {
1260    try {
1261      createData();
1262      createSiteMap();
1263
1264      //
1265
// page with child pages
1266
//
1267
setRequestPathInfo( "/deletePage" );
1268      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1269      actionPerform();
1270
1271      verifyForwardPath( "/deletePageForm.do?id=" + page2_.getInt( "id" ) );
1272    }
1273    catch ( Exception JavaDoc e ) {
1274      e.printStackTrace();
1275      fail();
1276    }
1277  }
1278
1279  public void testDoDeletePageCancel() {
1280    try {
1281      createData();
1282      createSiteMap();
1283
1284      //
1285
// cancel
1286
//
1287
setRequestPathInfo( "/deletePage" );
1288      addRequestParameter( "cancel", "Cancel" );
1289      addRequestParameter( "id", "" + page1_.getInt( "id" ) );
1290      actionPerform();
1291
1292      verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1293    }
1294    catch ( Exception JavaDoc e ) {
1295      e.printStackTrace();
1296      fail();
1297    }
1298  }
1299
1300  public void testDoDeletePageLeaf() {
1301    try {
1302      SiteMap siteMap = null;
1303      Link link = null;
1304      Page page = null;
1305      SiteMapTree tree = null;
1306
1307      createData();
1308      createSiteMap();
1309      MockModule.setDestroyed( false );
1310      setRequestPathInfo( "/deletePage" );
1311      addRequestParameter( "confirm", "Confirm" );
1312      addRequestParameter( "id", "" + page4_.getInt( "id" ) );
1313      actionPerform();
1314
1315      verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1316
1317      try {
1318        page = new Page();
1319        page.setSiteContext( SiteContext.getDefaultContext() );
1320        page.load( page4_.getKey() );
1321        fail( "Page still in database." );
1322      }
1323      catch ( Exception JavaDoc e ) {
1324        // success
1325
}
1326
1327      assertTrue( MockModule.isDestroyed() );
1328
1329      siteMap = new SiteMap();
1330      siteMap.setSiteContext( SiteContext.getDefaultContext() );
1331      siteMap.load();
1332
1333      assertNull( siteMap.find( page4_.getInt( "id" ) ) );
1334
1335      tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
1336
1337      assertNull( tree.find( page4_.getInt( "id" ) ) );
1338    }
1339    catch ( Exception JavaDoc e ) {
1340      e.printStackTrace();
1341      fail();
1342    }
1343  }
1344
1345  public void testDoDeletePagePromoteChildren() {
1346    try {
1347      SiteMap siteMap = null;
1348      Link link = null;
1349      Page page = null;
1350      SiteMapTree tree = null;
1351      DefaultMutableTreeNode node = null;
1352
1353      createData();
1354      createSiteMap();
1355      MockModule.setDestroyed( false );
1356      setRequestPathInfo( "/deletePage" );
1357      addRequestParameter( "confirm", "Confirm" );
1358      addRequestParameter( "delOption", "promote" );
1359      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1360      actionPerform();
1361
1362      verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1363
1364      try {
1365        page = new Page();
1366        page.setSiteContext( SiteContext.getDefaultContext() );
1367        page.load( page2_.getKey() );
1368        fail( "Page still in database." );
1369      }
1370      catch ( Exception JavaDoc e ) {
1371        // success
1372
}
1373
1374      assertTrue( MockModule.isDestroyed() );
1375
1376      siteMap = new SiteMap();
1377      siteMap.setSiteContext( SiteContext.getDefaultContext() );
1378      siteMap.load();
1379
1380      assertNull( siteMap.find( page2_.getInt( "id" ) ) );
1381
1382      link = ( Link )siteMap.getRoot();
1383
1384      assertEquals( 3, link.getChildCount() );
1385
1386      link = ( Link )link.getChildAt( 2 );
1387
1388      assertEquals( 3, link.getPageId() );
1389
1390      tree = ( SiteMapTree )session.getAttribute( ShimGlobals.SITEMAPTREE_KEY );
1391
1392      assertNull( tree.find( page2_.getInt( "id" ) ) );
1393
1394      node = ( DefaultMutableTreeNode )tree.getRoot();
1395
1396      assertEquals( 3, node.getChildCount() );
1397
1398      node = ( DefaultMutableTreeNode )node.getChildAt( 2 );
1399
1400      assertEquals( 3, link.getPageId() );
1401    }
1402    catch ( Exception JavaDoc e ) {
1403      e.printStackTrace();
1404      fail();
1405    }
1406  }
1407
1408  public void testDoDeletePageDeleteChildren() {
1409    try {
1410      SiteMap siteMap = null;
1411      Link link = null;
1412      Page page = null;
1413
1414      createData();
1415      createSiteMap();
1416      MockModule.setDestroyed( false );
1417      setRequestPathInfo( "/deletePage" );
1418      addRequestParameter( "confirm", "Confirm" );
1419      addRequestParameter( "delOption", "delete" );
1420      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1421      actionPerform();
1422
1423      verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1424
1425      try {
1426        page = new Page();
1427        page.setSiteContext( SiteContext.getDefaultContext() );
1428        page.load( page2_.getKey() );
1429        fail( "Page still in database." );
1430      }
1431      catch ( Exception JavaDoc e ) {
1432        // success
1433
}
1434
1435      assertTrue( MockModule.isDestroyed() );
1436
1437      siteMap = new SiteMap();
1438      siteMap.setSiteContext( SiteContext.getDefaultContext() );
1439      siteMap.load();
1440
1441      assertNull( siteMap.find( page3_.getInt( "id" ) ) );
1442
1443      link = ( Link )siteMap.getRoot();
1444
1445      assertEquals( 2, link.getChildCount() );
1446
1447      link = ( Link )link.getChildAt( 0 );
1448
1449      assertEquals( 4, link.getPageId() );
1450    }
1451    catch ( Exception JavaDoc e ) {
1452      e.printStackTrace();
1453      fail();
1454    }
1455  }
1456
1457  public void testDoMovePageForm() {
1458    try {
1459      createData();
1460      createSiteMap();
1461      setRequestPathInfo( "/movePageForm" );
1462      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1463      actionPerform();
1464
1465      verifyForward( "form" );
1466
1467      form = ( DynaActionForm )getActionForm();
1468
1469      assertEquals( "" + page2_.getInt( "id" ), form.get( "id" ) );
1470      assertEquals( "before", form.get( "position" ) );
1471
1472      list = ( List )form.get( "pages" );
1473
1474      assertEquals( 6, list.size() );
1475
1476      bean = ( LabelValueBean )list.get( 0 );
1477
1478      assertEquals( "", bean.getValue() );
1479      assertEquals( "Select...", bean.getLabel() );
1480
1481      bean = ( LabelValueBean )list.get( 1 );
1482
1483      assertEquals( "1", bean.getValue() );
1484      assertEquals( "Page1", bean.getLabel() );
1485
1486      bean = ( LabelValueBean )list.get( 2 );
1487
1488      assertEquals( "2", bean.getValue() );
1489      assertEquals( "Page2", bean.getLabel() );
1490
1491      bean = ( LabelValueBean )list.get( 3 );
1492
1493      assertEquals( "3", bean.getValue() );
1494      assertEquals( "Page3", bean.getLabel() );
1495
1496      bean = ( LabelValueBean )list.get( 4 );
1497
1498      assertEquals( "4", bean.getValue() );
1499      assertEquals( "Page4", bean.getLabel() );
1500
1501      bean = ( LabelValueBean )list.get( 5 );
1502
1503      assertEquals( "5", bean.getValue() );
1504      assertEquals( "Page5", bean.getLabel() );
1505    }
1506    catch ( Exception JavaDoc e ) {
1507      e.printStackTrace();
1508      fail();
1509    }
1510  }
1511
1512  public void testDoMovePageValidationMissingDest() throws Exception JavaDoc {
1513    createData();
1514    createSiteMap();
1515    setRequestPathInfo( "/movePage" );
1516    addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1517    addRequestParameter( "position", "under" );
1518    actionPerform();
1519
1520    verifyInputForward();
1521    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.missingDest" } );
1522  }
1523
1524  public void testDoMovePageValidationCannotMoveRoot() throws Exception JavaDoc {
1525    createData();
1526    createSiteMap();
1527    setRequestPathInfo( "/movePage" );
1528    addRequestParameter( "id", "" + page1_.getInt( "id" ) );
1529    addRequestParameter( "position", "under" );
1530    addRequestParameter( "destid", "" + page2_.getInt( "id" ) );
1531    actionPerform();
1532
1533    verifyInputForward();
1534    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.cannotMoveRoot" } );
1535  }
1536
1537  public void testDoMovePageValidationCannotMoveNearSelf() throws Exception JavaDoc {
1538    createData();
1539    createSiteMap();
1540    setRequestPathInfo( "/movePage" );
1541    addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1542    addRequestParameter( "position", "under" );
1543    addRequestParameter( "destid", "" + page2_.getInt( "id" ) );
1544    actionPerform();
1545
1546    verifyInputForward();
1547    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.cannotMoveNearSelf" } );
1548  }
1549
1550  public void testDoMovePageValidationCannotMoveUnderSelf() throws Exception JavaDoc {
1551    createData();
1552    createSiteMap();
1553    setRequestPathInfo( "/movePage" );
1554    addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1555    addRequestParameter( "position", "under" );
1556    addRequestParameter( "destid", "" + page3_.getInt( "id" ) );
1557    actionPerform();
1558
1559    verifyInputForward();
1560    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.cannotMoveUnderSelf" } );
1561  }
1562
1563  public void testDoMovePageValidationCannotMoveAfterRoot() throws Exception JavaDoc {
1564    createData();
1565    createSiteMap();
1566    setRequestPathInfo( "/movePage" );
1567    addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1568    addRequestParameter( "position", "after" );
1569    addRequestParameter( "destid", "" + page1_.getInt( "id" ) );
1570    actionPerform();
1571
1572    verifyInputForward();
1573    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.cannotMoveAfterRoot" } );
1574  }
1575
1576  public void testDoMovePageValidationCannotMoveBeforeRoot() throws Exception JavaDoc {
1577    createData();
1578    createSiteMap();
1579    setRequestPathInfo( "/movePage" );
1580    addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1581    addRequestParameter( "position", "before" );
1582    addRequestParameter( "destid", "" + page1_.getInt( "id" ) );
1583    actionPerform();
1584
1585    verifyInputForward();
1586    verifyActionErrors( new String JavaDoc[] { "shim.movePageForm.cannotMoveBeforeRoot" } );
1587  }
1588
1589  public void testDoMovePageCancel() {
1590    try {
1591      createData();
1592      createSiteMap();
1593      setRequestPathInfo( "/movePage" );
1594      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1595      addRequestParameter( "position", "under" );
1596      addRequestParameter( "cancel", "Cancel" );
1597      actionPerform();
1598
1599      verifyForwardPath( "/editPage.do?id=" + page2_.getInt( "id" ) );
1600    }
1601    catch ( Exception JavaDoc e ) {
1602      e.printStackTrace();
1603      fail();
1604    }
1605  }
1606
1607  public void testDoMovePage() {
1608    try {
1609      createData();
1610      createSiteMap();
1611      setRequestPathInfo( "/movePage" );
1612      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1613      addRequestParameter( "destid", "" + page4_.getInt( "id" ) );
1614      addRequestParameter( "position", "under" );
1615      actionPerform();
1616
1617      verifyForwardPath( "/editPage.do?id=" + page4_.getInt( "id" ) );
1618
1619      siteMap = new SiteMap();
1620      siteMap.setSiteContext( SiteContext.getDefaultContext() );
1621      siteMap.load();
1622      link = ( Link )siteMap.getRoot();
1623
1624      assertNotNull( link );
1625      assertEquals( 2, link.getChildCount() );
1626
1627      link = ( Link )link.getChildAt( 0 );
1628
1629      assertEquals( page4_.getInt( "id" ), link.getPageId() );
1630
1631      link = ( Link )link.getChildAt( 0 );
1632
1633      assertEquals( page2_.getInt( "id" ), link.getPageId() );
1634      assertEquals( 1, link.getChildCount() );
1635
1636      tree = ShimUtils.getSiteMapTree( request );
1637      node = tree.getRoot();
1638
1639      assertNotNull( node );
1640      assertEquals( 2, node.getChildCount() );
1641
1642      node = ( DefaultMutableTreeNode )node.getChildAt( 0 );
1643
1644      assertEquals( page4_.get( "id" ), node.getUserObject() );
1645
1646      node = ( DefaultMutableTreeNode )node.getChildAt( 0 );
1647
1648      assertEquals( page2_.get( "id" ), node.getUserObject() );
1649      assertEquals( 1, node.getChildCount() );
1650
1651      createSiteMap();
1652      clearRequestParameters();
1653      setRequestPathInfo( "/movePage" );
1654      addRequestParameter( "id", "" + page2_.getInt( "id" ) );
1655      addRequestParameter( "destid", "" + page4_.getInt( "id" ) );
1656      addRequestParameter( "position", "after" );
1657      actionPerform();
1658
1659      verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1660
1661      siteMap = new SiteMap();
1662      siteMap.setSiteContext( SiteContext.getDefaultContext() );
1663      siteMap.load();
1664      link = ( Link )siteMap.getRoot();
1665
1666      assertNotNull( link );
1667      assertEquals( 3, link.getChildCount() );
1668
1669      sublink = ( Link )link.getChildAt( 0 );
1670
1671      assertEquals( page4_.getInt( "id" ), sublink.getPageId() );
1672
1673      sublink = ( Link )link.getChildAt( 1 );
1674
1675      assertEquals( page2_.getInt( "id" ), sublink.getPageId() );
1676      assertEquals( 1, sublink.getChildCount() );
1677
1678      tree = ShimUtils.getSiteMapTree( request );
1679      node = tree.getRoot();
1680
1681      assertNotNull( node );
1682      assertEquals( 3, node.getChildCount() );
1683
1684      subnode = ( DefaultMutableTreeNode )node.getChildAt( 0 );
1685
1686      assertEquals( page4_.get( "id" ), subnode.getUserObject() );
1687
1688      subnode = ( DefaultMutableTreeNode )node.getChildAt( 1 );
1689
1690      assertEquals( page2_.get( "id" ), subnode.getUserObject() );
1691      assertEquals( 1, subnode.getChildCount() );
1692    }
1693    catch ( Exception JavaDoc e ) {
1694      e.printStackTrace();
1695      fail();
1696    }
1697  }
1698
1699  public void testDoConfigurePanelForm() {
1700    try {
1701      createData();
1702      createSiteMap();
1703      setRequestPathInfo( "/configurePanelForm" );
1704      addRequestParameter( "pageid", "" + page1_.getInt( "id" ) );
1705      addRequestParameter( "panel", "body" );
1706      actionPerform();
1707
1708      verifyForward( "form" );
1709
1710      form = ( DynaActionForm )getActionForm();
1711      list = ( List )form.get( "modules" );
1712
1713      assertNotNull( list );
1714      assertTrue( list.size() > 0 );
1715      assertEquals( "com.methodhead.shim.MockModule", form.get( "module" ) );
1716    }
1717    catch ( Exception JavaDoc e ) {
1718      e.printStackTrace();
1719      fail();
1720    }
1721  }
1722
1723  public void testDoConfigurePanel() throws Exception JavaDoc {
1724    //
1725
// cancel
1726
//
1727
createData();
1728    createSiteMap();
1729    MockModule.setDestroyed( false );
1730    setRequestPathInfo( "/configurePanel" );
1731    addRequestParameter( "pageid", "" + page1_.getInt( "id" ) );
1732    addRequestParameter( "panel", "body" );
1733    addRequestParameter( "module", "com.methodhead.shim.TextModule" );
1734    addRequestParameter( "cancel", "Cancel" );
1735    actionPerform();
1736
1737    verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1738  }
1739
1740  public void testDoConfigurePanelSameModule() throws Exception JavaDoc {
1741    //
1742
// same module
1743
//
1744
createData();
1745    createSiteMap();
1746    MockModule.setDestroyed( false );
1747    setRequestPathInfo( "/configurePanel" );
1748    addRequestParameter( "pageid", "" + page1_.getInt( "id" ) );
1749    addRequestParameter( "panel", "body" );
1750    addRequestParameter( "module", "com.methodhead.shim.MockModule" );
1751    addRequestParameter( "cancel", "" );
1752    addRequestParameter( "submit", "Submit" );
1753    actionPerform();
1754
1755    verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1756
1757    assertTrue( !MockModule.isDestroyed() );
1758  }
1759
1760  public void testDoConfigurePanelDifferentModule() throws Exception JavaDoc {
1761    //
1762
// different module
1763
//
1764
createData();
1765    createSiteMap();
1766    MockModule.setDestroyed( false );
1767    setRequestPathInfo( "/configurePanel" );
1768    addRequestParameter( "pageid", "" + page1_.getInt( "id" ) );
1769    addRequestParameter( "panel", "body" );
1770    addRequestParameter( "module", "com.methodhead.shim.TextModule" );
1771    addRequestParameter( "cancel", "" );
1772    addRequestParameter( "submit", "Submit" );
1773    actionPerform();
1774
1775    verifyForwardPath( "/editPage.do?id=" + page1_.getInt( "id" ) );
1776
1777    assertTrue( MockModule.isDestroyed() );
1778
1779    page = new Page();
1780    page.setSiteContext( SiteContext.getDefaultContext() );
1781    page.load( page1_.getKey() );
1782    panel = ( Panel )page.getPanels().get( "body" );
1783
1784    assertEquals( "com.methodhead.shim.TextModule", panel.getModuleClass() );
1785
1786    textModule = new TextModule();
1787    textModule.init( page, "body" );
1788    textModule.load();
1789
1790    assertEquals( "Insert your text here...", textModule.getString( "value" ) );
1791  }
1792}
1793
Popular Tags