1 20 21 package org.netbeans.test.j2ee.multiview; 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.io.Writer ; 27 import java.util.List ; 28 import java.util.Map ; 29 import javax.swing.text.JTextComponent ; 30 import java.awt.Component ; 31 import java.io.File ; 32 import javax.swing.JButton ; 33 import javax.swing.JCheckBox ; 34 import javax.swing.JLabel ; 35 import javax.swing.JPanel ; 36 import javax.swing.JRadioButton ; 37 import javax.swing.JTextArea ; 38 import javax.swing.JTextField ; 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.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 ; 65 69 public class SecurityDDTest extends JellyTestCase { 70 71 private static DDTestUtils utils; 72 73 74 public SecurityDDTest(String testName) { 75 super(testName); 76 } 77 78 protected void tearDown() throws Exception { 79 super.tearDown(); 80 } 81 82 protected void setUp() throws Exception { 83 super.setUp(); 84 } 85 86 public static final String WEB_PROJECT_NAME = "TestWebApp"; 87 public static final String WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + WEB_PROJECT_NAME; 88 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 107 public static void main(java.lang.String [] args) { 108 TestRunner.run(suite()); 110 } 111 112 113 public void testOpenProject() throws Exception { 114 File projectDir = new File (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); utils = new DDTestUtils(ddObj,this); 126 Utils.waitForAWTDispatchThread(); 127 } 128 public void testExistingLoginConfiguration() throws Exception { 129 JPanel panel = utils.getInnerSectionPanel("login_config"); 130 Component [] comp = panel.getComponents(); 131 137 assertEquals("Login authentication isn't set to form","Form",((JRadioButton )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 { 144 JPanel panel = utils.getInnerSectionPanel("security_roles"); 145 Component [] 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 { 156 JPanel panel = utils.getInnerSectionPanel("security_roles"); 157 Component [] comp = panel.getComponents(); 158 SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel(); 159 model.addRow(new Object []{"user1","user1desc"}); 160 ddObj.modelUpdatedFromUI(); 161 utils.waitForDispatchThread(); 162 utils.save(); 163 assertEquals("Role not added",3,model.getRowCount()); 164 ((Component )comp[0]).requestFocus(); 165 new StepIterator() { 166 public boolean step() throws Exception { 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 { 175 JPanel panel = utils.getInnerSectionPanel("security_roles"); 176 Component [] comp = panel.getComponents(); 177 SecurityRoleTableModel model = (SecurityRoleTableModel) ((DefaultTablePanel) comp[0]).getModel(); 178 model.editRow(2,new Object []{"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 )comp[0]).requestFocus(); 185 new StepIterator() { 186 public boolean step() throws Exception { 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 { 196 JPanel panel = utils.getInnerSectionPanel("security_roles"); 197 Component [] 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 { 209 } 213 } 214 | Popular Tags |