KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > menu > TreeNavigationControllerTest


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.web.controller.menu;
21
22 import junit.framework.TestCase;
23 import org.apache.log4j.Logger;
24 import org.openi.test.Util;
25 import org.springframework.context.ApplicationContext;
26 import org.springframework.context.support.FileSystemXmlApplicationContext;
27 import org.springframework.mock.web.*;
28 import org.springframework.web.servlet.ModelAndView;
29 import java.io.IOException JavaDoc;
30 import java.util.Map JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35
36 /**
37  * @author Uddhab Pant <br>
38  * @version $Revision: 1.5 $ $Date: 2006/04/12 00:39:12 $ <br>
39  *
40  * Test case for tree navigation controller.
41  *
42  *
43  */

44 public class TreeNavigationControllerTest extends TestCase {
45     private static Logger logger = Logger.getLogger(TreeNavigationControllerTest.class);
46     private ApplicationContext appContext;
47     private TreeNavigationController tc;
48     private MockHttpServletRequest request;
49     private HttpServletResponse JavaDoc response;
50     private ModelAndView mv;
51
52     public void setUp() throws IOException JavaDoc {
53         String JavaDoc dirName = Util.findTestDirectory() + "/"
54             + (this.getClass().getPackage().getName()).replace('.', '/');
55
56         appContext = new FileSystemXmlApplicationContext(dirName
57                 + "/../WEB-INF/springapp-servlet.xml");
58
59         tc = (TreeNavigationController) appContext.getBean(
60                 "treeNavigationController");
61
62         request = new MockHttpServletRequest("POST", "/treenavigation.htm");
63
64         response = new MockHttpServletResponse();
65     }
66
67     public void testHandleRequestInternal() {
68         Map JavaDoc model;
69
70         try {
71             mv = tc.handleRequestInternal(request, new MockHttpServletResponse());
72         } catch (Exception JavaDoc e) {
73             fail();
74         }
75
76         model = mv.getModel();
77
78         assertEquals("treeNavigationView", mv.getViewName());
79         assertEquals("WEB-INF/menu/menu.xsl", tc.getXslFileName());
80         assertEquals(true, tc.isRequireSession());
81         assertTrue(model.containsKey("htmlMenu"));
82         assertTrue(model.containsKey("poweredByLogoName"));
83         assertTrue(model.containsKey("logoUrl"));
84     }
85
86     protected void tearDown() {
87         tc = null;
88         appContext = null;
89     }
90 }
91
Popular Tags