KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > menu > MenuBuilderTest


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.menu;
21
22 import junit.framework.TestCase;
23 import org.apache.log4j.PropertyConfigurator;
24 import org.openi.project.Project;
25 import org.openi.project.ProjectContext;
26 import org.openi.test.Util;
27 import org.openi.xml.BeanStorage;
28 import java.io.FileNotFoundException JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.OutputStreamWriter JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.List JavaDoc;
33
34
35 /**
36  * @author plucas
37  *
38  * TODO To change the template for this generated type comment go to
39  * Window - Preferences - Java - Code Style - Code Templates
40  */

41 public class MenuBuilderTest extends TestCase {
42     private BeanStorage storage;
43     private MenuBuilder builder;
44     private String JavaDoc username;
45     private String JavaDoc baseDir;
46     private Project project;
47
48     /**
49      * Constructor for MenuBuilderTest.
50      * @param arg0
51      */

52     public MenuBuilderTest(String JavaDoc arg0) {
53         super(arg0);
54     }
55
56     public static void main(String JavaDoc[] args) {
57     }
58
59     /*
60      * @see TestCase#setUp()
61      */

62     protected void setUp() throws Exception JavaDoc {
63         super.setUp();
64         this.storage = new BeanStorage();
65         builder = new MenuBuilder();
66         this.username = "mouser";
67         this.baseDir = Util.findTestDirectory() + "/projects/standard";
68         this.project = createProject();
69         PropertyConfigurator.configure(Util.findTestDirectory()
70             + "/log4jtest.properties");
71     }
72
73     private Project createProject() {
74         String JavaDoc projName = "standard";
75         Project proj = new Project();
76         proj.setCssName(projName + ".css");
77         proj.setExternalUrl("http://www." + projName + ".com");
78         proj.setProjectId(projName);
79         proj.setProjectName(projName);
80
81         return proj;
82     }
83
84     /*
85      * @see TestCase#tearDown()
86      */

87     protected void tearDown() throws Exception JavaDoc {
88         super.tearDown();
89     }
90
91     public void testBuild() throws Exception JavaDoc {
92         System.out.println(baseDir);
93         System.out.println(username);
94
95         // add analysis modules, in display order
96
// TODO: needs to be configurable
97
List JavaDoc menuSubDirs = new LinkedList JavaDoc();
98         menuSubDirs.add("/public/Segments");
99         menuSubDirs.add("/public/Attrition_And_Migration");
100         menuSubDirs.add("/public/Value_And_Growth");
101         menuSubDirs.add("/" + username);
102
103         Menu root = builder.build(this.baseDir, menuSubDirs);
104
105         // System.out.println(storage.toXmlString(root));
106
}
107
108     public void testBadBaseDir() throws IOException JavaDoc {
109         try {
110             Menu root = builder.build("/bad$#@baseDir", new LinkedList JavaDoc());
111             System.out.println(storage.toXmlString(root));
112         } catch (IOException JavaDoc e) {
113             // should throw IOException, this is OK
114
return;
115         } catch (Exception JavaDoc e) {
116             e.printStackTrace();
117         }
118
119         fail("expected an IOException for bad basedir");
120     }
121
122     /**
123      * TODO: What's best way to handle null configurations?
124      *
125      * @throws Exception
126      */

127     public void testNullInput() throws Exception JavaDoc {
128         // Menu root = builder.build(null, "mouser", this.project);
129
}
130     
131     public void testRecurse() throws IOException JavaDoc{
132         // logger.debug("here");
133
ProjectContext context = Util.createTestProjectContext("projectUser");
134         
135         Menu menu = context.buildMenu();
136         // logger.debug("child nodes: " + menu.getChildNodes().size());
137
// Collection children = menu.getChildNodes();
138
AnalysisCollectionMenuVisitor visitor = new AnalysisCollectionMenuVisitor(context);
139         menu.accept(visitor);
140         assertTrue(visitor.getAnalyses().size()>0);
141         // logger.debug(visitor.getAnalyses());
142
}
143     
144     public void testGetSubMenu() throws IOException JavaDoc{
145         ProjectContext context = Util.createTestProjectContext("projectUser");
146         Menu menu = context.buildMenu();
147         Menu subMenu = menu.getSubMenu("Sales");
148         System.out.println(subMenu.toString());
149     }
150     
151     public void testMenuNames() throws Exception JavaDoc{
152         ProjectContext context = Util.createTestProjectContext("projectUser");
153         List JavaDoc menuNames = context.getAutoGeneratedMenuNames();
154         System.out.println(menuNames);
155     }
156 }
157
Popular Tags