KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > multiview > SecurityDDTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  *
19  */

20
21 package org.netbeans.test.j2ee.multiview;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.OutputStream JavaDoc;
26 import java.io.Writer JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.swing.text.JTextComponent JavaDoc;
30 import java.awt.Component JavaDoc;
31 import java.io.File JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JCheckBox JavaDoc;
34 import javax.swing.JLabel JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JRadioButton JavaDoc;
37 import javax.swing.JTextArea JavaDoc;
38 import javax.swing.JTextField JavaDoc;
39 import junit.framework.Test;
40 import junit.textui.TestRunner;
41 import org.netbeans.api.project.Project;
42 import org.netbeans.jellytools.JellyTestCase;
43 import org.netbeans.junit.NbTestSuite;
44 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
45 import org.netbeans.modules.j2ee.dd.api.common.ResourceRef;
46 import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
47 import org.netbeans.modules.j2ee.dd.api.web.ErrorPage;
48 import org.netbeans.modules.j2ee.dd.api.web.JspConfig;
49 import org.netbeans.modules.j2ee.dd.api.web.JspPropertyGroup;
50 import org.netbeans.modules.j2ee.dd.api.web.*;
51 import org.netbeans.modules.j2ee.dd.api.web.SecurityConstraint;
52 //import org.netbeans.modules.j2ee.dd.impl.web.model_2_5.SecurityConstraint;
53
import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
54 import org.netbeans.modules.j2ee.ddloaders.web.multiview.DDBeanTableModel;
55 import org.netbeans.modules.j2ee.ddloaders.web.multiview.ErrorPagesTablePanel;
56 import org.netbeans.modules.j2ee.ddloaders.web.multiview.SecurityRoleTableModel;
57 import org.netbeans.modules.j2ee.deployment.impl.gen.nbd.CommonBean;
58 import org.netbeans.modules.web.project.WebProject;
59 import org.netbeans.modules.xml.multiview.ui.LinkButton;
60 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
61 import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
62 import org.openide.filesystems.FileObject;
63 import org.openide.loaders.DataObject;
64 import org.w3c.dom.Node JavaDoc;
65 /**
66  *
67  * @author kolard
68  */

69 public class SecurityDDTest extends JellyTestCase {
70     
71     private static DDTestUtils utils;
72     
73     /** Creates a new instance of SecurityDDTest */
74     public SecurityDDTest(String JavaDoc testName) {
75         super(testName);
76     }
77     
78         protected void tearDown() throws Exception JavaDoc {
79         super.tearDown();
80     }
81     
82     protected void setUp() throws Exception JavaDoc {
83         super.setUp();
84     }
85     
86     public static final String JavaDoc WEB_PROJECT_NAME = "TestWebApp";
87     public static final String JavaDoc WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + WEB_PROJECT_NAME;
88     //public static final String WEB_PROJECT_PATH = "E:\\Netbeans\\Sources_stablenowww_release55\\j2ee\\build\\test\\qa-functional\\data\\projects\\TestWebApp";
89
private static Project project;
90     private static FileObject ddFo;
91     private static WebApp webapp;
92     private static DDDataObject ddObj;
93     
94     public static Test suite() {
95         NbTestSuite suite = new NbTestSuite();
96         suite.addTest(new SecurityDDTest("testOpenProject"));
97         suite.addTest(new SecurityDDTest("testExistingLoginConfiguration"));
98         suite.addTest(new SecurityDDTest("testExistingSecurityRoles"));
99         suite.addTest(new SecurityDDTest("testExistingSecurityConstraint"));
100         suite.addTest(new SecurityDDTest("testAddSecurityRole"));
101         suite.addTest(new SecurityDDTest("testEditSecurityRole"));
102         suite.addTest(new SecurityDDTest("testDelSecurityRole"));
103         return suite;
104     }
105     
106     /** Use for execution inside IDE */
107     public static void main(java.lang.String JavaDoc[] args) {
108         // run only selected test case
109
TestRunner.run(suite());
110     }
111     
112     
113     public void testOpenProject() throws Exception JavaDoc{
114         File JavaDoc projectDir = new File JavaDoc(WEB_PROJECT_PATH);
115         Project project = (Project)J2eeProjectSupport.openProject(projectDir);
116         assertNotNull("Project is null.", project);
117         WebProject webproj = (WebProject)project;
118         assertNotNull("Project is not webproject",webproj);
119         ddFo = webproj.getAPIWebModule().getDeploymentDescriptor();
120         assertNotNull("Can't get deploy descriptor file object",ddFo);
121         webapp = DDProvider.getDefault().getDDRoot(ddFo);
122         ddObj = (DDDataObject)DataObject.find(ddFo);
123         assertNotNull("Multiview is null",ddObj);
124         ddObj.openView(5);//lets open security view
125
utils = new DDTestUtils(ddObj,this);
126         Utils.waitForAWTDispatchThread();
127     }
128     public void testExistingLoginConfiguration() throws Exception JavaDoc {
129         JPanel JavaDoc panel = utils.getInnerSectionPanel("login_config");
130         Component JavaDoc[] comp = panel.getComponents();
131         /*
132         for(int i=0;i<comp.length;i++)
133         {
134             System.err.println("comp:" + (comp[i]));
135         }
136         */

137         assertEquals("Login authentication isn't set to form","Form",((JRadioButton JavaDoc)comp[12]).getText());
138         assertEquals("Undefined login page","/login.jsp",webapp.getSingleLoginConfig().getFormLoginConfig().getFormLoginPage());
139         assertEquals("Undefined error page","/loginError.jsp",webapp.getSingleLoginConfig().getFormLoginConfig().getFormErrorPage());
140         
141     }
142     
143     public void testExistingSecurityRoles() throws Exception JavaDoc {
144         JPanel JavaDoc panel = utils.getInnerSectionPanel("security_roles");
145         Component JavaDoc[] comp = panel.getComponents();
146         SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
147         assertEquals("Wrong number of roles",2,model.getRowCount());
148         assertEquals("Wrong role name","admin",model.getValueAt(0,0));
149         assertEquals("Wrong role description","administrator",model.getValueAt(0,1));
150         assertEquals("Wrong role name","user",model.getValueAt(1,0));
151         assertEquals("Wrong role description","testuser",model.getValueAt(1,1));
152          
153     }
154
155      public void testAddSecurityRole() throws Exception JavaDoc {
156         JPanel JavaDoc panel = utils.getInnerSectionPanel("security_roles");
157         Component JavaDoc[] comp = panel.getComponents();
158         SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
159         model.addRow(new Object JavaDoc[]{"user1","user1desc"});
160         ddObj.modelUpdatedFromUI();
161         utils.waitForDispatchThread();
162         utils.save();
163         assertEquals("Role not added",3,model.getRowCount());
164         ((Component JavaDoc)comp[0]).requestFocus();
165         new StepIterator() {
166             public boolean step() throws Exception JavaDoc {
167                 return utils.contains(".*<security-role>\\s*<description>user1desc</description>\\s*<role-name>user1</role-name>\\s*</security-role>.*");
168             }
169             public void finalCheck() {
170                 utils.checkInDDXML(".*<security-role>\\s*<description>user1desc</description>\\s*<role-name>user1</role-name>\\s*</security-role>.*");
171             }
172         };
173     }
174      public void testEditSecurityRole() throws Exception JavaDoc {
175         JPanel JavaDoc panel = utils.getInnerSectionPanel("security_roles");
176         Component JavaDoc[] comp = panel.getComponents();
177         SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
178         model.editRow(2,new Object JavaDoc[]{"user2","user2desc"});
179         ddObj.modelUpdatedFromUI();
180         utils.waitForDispatchThread();
181         utils.save();
182         assertEquals("Role not changed","user2",model.getValueAt(2,0));
183         assertEquals("Role description not changed","user2desc",model.getValueAt(2,1));
184         ((Component JavaDoc)comp[0]).requestFocus();
185         new StepIterator() {
186             public boolean step() throws Exception JavaDoc {
187                 return utils.contains(".*<security-role>\\s*<description>user2desc</description>\\s*<role-name>user2</role-name>\\s*</security-role>.*");
188             }
189             public void finalCheck() {
190                 utils.checkInDDXML(".*<security-role>\\s*<description>user2desc</description>\\s*<role-name>user2</role-name>\\s*</security-role>.*");
191             }
192         };
193     }
194
195      public void testDelSecurityRole() throws Exception JavaDoc {
196         JPanel JavaDoc panel = utils.getInnerSectionPanel("security_roles");
197         Component JavaDoc[] comp = panel.getComponents();
198         SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel();
199         model.removeRow(2);
200         ddObj.modelUpdatedFromUI();
201         utils.waitForDispatchThread();
202         utils.save();
203         assertEquals("Role not deleted",2,model.getRowCount());
204         utils.checkNotInDDXML(".*<security-role>\\s*<description>user2desc</description>\\s*<role-name>user2</role-name>\\s*</security-role>.*");
205         
206     }
207     
208     public void testExistingSecurityConstraint() throws Exception JavaDoc {
209         //empty yet...
210
//SecurityConstraint constraint = webapp.getSecurityConstraint(0);
211
//org.netbeans.modules.j2ee.ddloaders.web.multiview.SecurityRoleTablePanel pan = new org.netbeans.modules.j2ee.ddloaders.web.multiview.SecurityRoleTablePanel();
212
}
213 }
214
Popular Tags