KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.test.j2ee.multiview;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.regex.Matcher JavaDoc;
25 import java.util.regex.Pattern JavaDoc;
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JCheckBox JavaDoc;
28 import javax.swing.JLabel JavaDoc;
29 import javax.swing.JPanel JavaDoc;
30 import javax.swing.JRadioButton JavaDoc;
31 import javax.swing.JTextArea JavaDoc;
32 import javax.swing.JTextField JavaDoc;
33 import javax.swing.SwingUtilities JavaDoc;
34 import javax.swing.text.Document JavaDoc;
35 import junit.framework.AssertionFailedError;
36 import junit.framework.Test;
37 import junit.textui.TestRunner;
38 import org.netbeans.api.project.Project;
39 import org.netbeans.jellytools.JellyTestCase;
40 import org.netbeans.junit.AssertionFailedErrorException;
41 import org.netbeans.junit.NbTestSuite;
42 import org.netbeans.modules.j2ee.dd.api.common.*;
43 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean;
44 import org.netbeans.modules.j2ee.dd.api.common.InitParam;
45 import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
46 import org.netbeans.modules.j2ee.dd.api.web.Filter;
47 import org.netbeans.modules.j2ee.dd.api.web.FilterMapping;
48 import org.netbeans.modules.j2ee.dd.api.web.Listener;
49 import org.netbeans.modules.j2ee.dd.api.web.Servlet;
50 import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
51 import org.netbeans.modules.j2ee.dd.api.web.SessionConfig;
52 import org.netbeans.modules.j2ee.dd.api.web.WebApp;
53 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject;
54 import org.netbeans.modules.j2ee.ddloaders.web.multiview.ContextParamsTablePanel;
55 import org.netbeans.modules.j2ee.ddloaders.web.multiview.DDBeanTableModel;
56 import org.netbeans.modules.j2ee.ddloaders.web.multiview.FilterMappingsTablePanel;
57 import org.netbeans.modules.j2ee.ddloaders.web.multiview.FilterParamsPanel;
58 import org.netbeans.modules.j2ee.ddloaders.web.multiview.InitParamsPanel;
59 import org.netbeans.modules.j2ee.ddloaders.web.multiview.ListenersTablePanel;
60 import org.netbeans.modules.web.project.WebProject;
61 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement;
62 import org.netbeans.modules.xml.multiview.XmlMultiViewEditorSupport;
63 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel;
64 import org.netbeans.modules.xml.multiview.ui.LinkButton;
65 import org.netbeans.modules.xml.multiview.ui.SectionPanel;
66 import org.netbeans.modules.xml.multiview.ui.SectionView;
67 import org.netbeans.test.j2ee.lib.J2eeProjectSupport;
68 import org.openide.cookies.EditCookie;
69 import org.openide.cookies.EditorCookie;
70 import org.openide.cookies.SaveCookie;
71 import org.openide.filesystems.FileObject;
72 import org.openide.loaders.DataObject;
73 import org.openide.nodes.Children;
74 import org.openide.nodes.Node;
75 /**
76  *
77  * @author jp159440
78  */

79 public class WebProjectDDTest extends JellyTestCase{
80     
81     /** Creates a new instance of WebProjectDDTest */
82     public WebProjectDDTest(String JavaDoc testName) {
83         super(testName);
84     }
85     
86     protected void tearDown() throws Exception JavaDoc {
87         super.tearDown();
88     }
89     
90     protected void setUp() throws Exception JavaDoc {
91         super.setUp();
92     }
93     
94     public static final String JavaDoc WEB_PROJECT_NAME = "TestWebApp";
95     public static final String JavaDoc WEB_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + WEB_PROJECT_NAME;
96     
97     private static Project project;
98     private static FileObject ddFo;
99     private static WebApp webapp;
100     private static DDDataObject ddObj;
101     private static DDTestUtils utils;
102     
103     public static Test suite() {
104         NbTestSuite suite = new NbTestSuite();
105         suite.addTest(new WebProjectDDTest("testOpenProject"));
106         suite.addTest(new WebProjectDDTest("testValuesInOverview"));
107         suite.addTest(new WebProjectDDTest("testModificationByApi"));
108         suite.addTest(new WebProjectDDTest("testModificationInDesign"));
109         suite.addTest(new WebProjectDDTest("testExistingContextParameters"));
110         suite.addTest(new WebProjectDDTest("testAddContextParameters"));
111         suite.addTest(new WebProjectDDTest("testModifyContextParameter"));
112         suite.addTest(new WebProjectDDTest("testDelContextParameter"));
113         suite.addTest(new WebProjectDDTest("testExistingListeners"));
114         suite.addTest(new WebProjectDDTest("testAddListener"));
115         suite.addTest(new WebProjectDDTest("testModifyListener"));
116         suite.addTest(new WebProjectDDTest("testDelListener"));
117         suite.addTest(new WebProjectDDTest("testExistingServlets"));
118         suite.addTest(new WebProjectDDTest("testModifyServlet"));
119         suite.addTest(new WebProjectDDTest("testAddServletParam"));
120         suite.addTest(new WebProjectDDTest("testModifyServletParam"));
121         suite.addTest(new WebProjectDDTest("testDelServletParam"));
122         suite.addTest(new WebProjectDDTest("testExistingFilters"));
123         suite.addTest(new WebProjectDDTest("testModifyFilter"));
124         suite.addTest(new WebProjectDDTest("testAddFilterParam"));
125         suite.addTest(new WebProjectDDTest("testModifyFilterParam"));
126         suite.addTest(new WebProjectDDTest("testDelFilterParam"));
127         suite.addTest(new WebProjectDDTest("testExistingFilterMappings"));
128         suite.addTest(new WebProjectDDTest("testAddFilterMapping"));
129         suite.addTest(new WebProjectDDTest("testFilterNameChangePropagation"));
130         suite.addTest(new WebProjectDDTest("testServletNameChangePropagation"));
131         suite.addTest(new WebProjectDDTest("testModifyFilterMapping"));
132         suite.addTest(new WebProjectDDTest("testDelFilterMapping"));
133         
134         suite.addTest(new PagesAndReferencesDDTest("testOpenProject"));
135         suite.addTest(new PagesAndReferencesDDTest("testExistingWelcomePages"));
136         suite.addTest(new PagesAndReferencesDDTest("testAddWelcomePage"));
137         suite.addTest(new PagesAndReferencesDDTest("testDelWelcomePage"));
138         suite.addTest(new PagesAndReferencesDDTest("testExistingErrorPages"));
139         suite.addTest(new PagesAndReferencesDDTest("testAddErrorPage"));
140         suite.addTest(new PagesAndReferencesDDTest("testModifyErrorPage"));
141         suite.addTest(new PagesAndReferencesDDTest("testDelErrorPage"));
142         suite.addTest(new PagesAndReferencesDDTest("testExistingProperyGroups"));
143         suite.addTest(new PagesAndReferencesDDTest("testModifyProperyGroup"));
144         suite.addTest(new PagesAndReferencesDDTest("testDelPropertyGroup"));
145         suite.addTest(new PagesAndReferencesDDTest("testExistingEnvEntries"));
146         suite.addTest(new PagesAndReferencesDDTest("testAddEnvEntry"));
147         suite.addTest(new PagesAndReferencesDDTest("testModifyEnvEntry"));
148         suite.addTest(new PagesAndReferencesDDTest("testDelEnvEntry"));
149         suite.addTest(new PagesAndReferencesDDTest("testExistingResReferences"));
150         suite.addTest(new PagesAndReferencesDDTest("testAddResReference"));
151         suite.addTest(new PagesAndReferencesDDTest("testModifyResReference"));
152         suite.addTest(new PagesAndReferencesDDTest("testDelResReference"));
153         suite.addTest(new PagesAndReferencesDDTest("testExistingResEnvReferences"));
154         suite.addTest(new PagesAndReferencesDDTest("testAddResEnvReference"));
155         suite.addTest(new PagesAndReferencesDDTest("testModifyResEnvReference"));
156         suite.addTest(new PagesAndReferencesDDTest("testDelResEnvReference"));
157         suite.addTest(new PagesAndReferencesDDTest("testExistingEJBReferences"));
158         suite.addTest(new PagesAndReferencesDDTest("testAddLocalEJBReference"));
159         suite.addTest(new PagesAndReferencesDDTest("testModifyLocalEJBReference"));
160         suite.addTest(new PagesAndReferencesDDTest("testDelLocalEJBReference"));
161         suite.addTest(new PagesAndReferencesDDTest("testAddRemoteEJBReference"));
162         suite.addTest(new PagesAndReferencesDDTest("testModifyRemoteEJBReference"));
163         suite.addTest(new PagesAndReferencesDDTest("testDelRemoteEJBReference"));
164         suite.addTest(new PagesAndReferencesDDTest("testExistingMsgDstReferences"));
165         suite.addTest(new PagesAndReferencesDDTest("testAddMsgDstReference"));
166         suite.addTest(new PagesAndReferencesDDTest("testModifyMsgDstReference"));
167         suite.addTest(new PagesAndReferencesDDTest("testDelMsgDstReference"));
168
169         suite.addTest(new SecurityDDTest("testOpenProject"));
170         suite.addTest(new SecurityDDTest("testExistingLoginConfiguration"));
171         suite.addTest(new SecurityDDTest("testExistingSecurityRoles"));
172         suite.addTest(new SecurityDDTest("testExistingSecurityConstraint"));
173         suite.addTest(new SecurityDDTest("testAddSecurityRole"));
174         suite.addTest(new SecurityDDTest("testEditSecurityRole"));
175         suite.addTest(new SecurityDDTest("testDelSecurityRole"));
176                                                                 
177         return suite;
178     }
179     
180     /** Use for execution inside IDE */
181     public static void main(java.lang.String JavaDoc[] args) {
182         // run only selected test case
183
TestRunner.run(suite());
184     }
185     
186     public void testOpenProject() throws Exception JavaDoc{
187         File JavaDoc projectDir = new File JavaDoc(WEB_PROJECT_PATH);
188         Project project = (Project)J2eeProjectSupport.openProject(projectDir);
189         assertNotNull("Project is null.", project);
190         WebProject webproj = (WebProject)project;
191         assertNotNull("Project is not webproject",webproj);
192         ddFo = webproj.getAPIWebModule().getDeploymentDescriptor();
193         assertNotNull("Can't get deploy descriptor file object",ddFo);
194         webapp = DDProvider.getDefault().getDDRoot(ddFo);
195         ddObj = (DDDataObject)DataObject.find(ddFo);
196         assertNotNull("Multiview is null",ddObj);
197         ddObj.openView(0);
198         utils = new DDTestUtils(ddObj,this);
199         Utils.waitForAWTDispatchThread();
200     }
201     public void testValuesInOverview() throws Exception JavaDoc {
202         //test general panel
203
assertEquals("Default display name does not match","DisplayName",webapp.getDefaultDisplayName());
204         assertEquals("Default description does not match","Description",webapp.getDefaultDescription());
205         assertEquals("Distributable not set",true,webapp.isDistributable());
206         utils.checkInDDXML(".*<distributable/>.*");
207         utils.checkInDDXML(".*<session-timeout>\\s*30\\s*</session-timeout>.*");
208     }
209     
210     public void testModificationByApi() throws Exception JavaDoc {
211         //test modify general panel
212
webapp.setDisplayName("ModifiedDisplayName");
213         ddObj.modelUpdatedFromUI();
214         Thread.sleep(2000);
215         utils.checkInDDXML(".*<display-name>ModifiedDisplayName</display-name>.*");
216         
217         webapp.setDescription("Modified Description");
218         ddObj.modelUpdatedFromUI();
219         Thread.sleep(2000);
220         utils.checkInDDXML(".*<description>Modified Description</description>.*");
221         
222         webapp.setDistributable(false);
223         ddObj.modelUpdatedFromUI();
224         Thread.sleep(2000);
225         utils.checkNotInDDXML(".*<distributable/>.*");
226         
227         SessionConfig sessionConf = webapp.getSingleSessionConfig();
228         sessionConf.setSessionTimeout(new java.math.BigInteger JavaDoc("25"));
229         ddObj.modelUpdatedFromUI();
230         Thread.sleep(2000);
231         utils.checkInDDXML(".*<session-timeout>\\s*25\\s*</session-timeout>.*");
232     }
233     
234     public void testModificationInDesign() throws Exception JavaDoc {
235         JPanel JavaDoc panel = utils.getInnerSectionPanel("overview");
236         Component JavaDoc[] comp = panel.getComponents();
237         panel.requestFocus();
238         utils.waitForDispatchThread();
239         utils.setText(((JTextField JavaDoc)comp[2]),"dispname");
240         ((JTextField JavaDoc)comp[7]).requestFocus();
241         new StepIterator() {
242             public boolean step() throws Exception JavaDoc {
243                 return utils.contains(".*<display-name>dispname</display-name>.*");
244             }
245             public void finalCheck() {
246                 assertEquals("Display name not set","dispname",webapp.getDefaultDisplayName());
247                 utils.checkInDDXML(".*<display-name>dispname</display-name>.*");
248             }
249         };
250         utils.setText((JTextArea JavaDoc)comp[4],"descript");
251         ((JCheckBox JavaDoc)comp[5]).requestFocus();
252         new StepIterator() {
253             public boolean step() throws Exception JavaDoc {
254                 return utils.contains(".*<description>descript</description>.*");
255             }
256             public void finalCheck() {
257                 assertEquals("Description not set","descript",webapp.getDefaultDescription());
258                 utils.checkInDDXML(".*<description>descript</description>.*");
259             }
260         };
261         ((JCheckBox JavaDoc)comp[5]).setSelected(true);
262         ddObj.modelUpdatedFromUI();
263         ((JTextField JavaDoc)comp[7]).requestFocus();
264         new StepIterator() {
265             public boolean step() throws Exception JavaDoc {
266                 return utils.contains(".*<distributable/>.*");
267             }
268             public void finalCheck() {
269                 assertTrue("Distributable not set to true",webapp.isDistributable());
270                 utils.checkInDDXML(".*<distributable/>.*");
271             }
272         };
273         utils.setText((JTextField JavaDoc)comp[7],"26");
274         ((JTextField JavaDoc)comp[2]).requestFocus();
275         new StepIterator() {
276             public boolean step() throws Exception JavaDoc {
277                 return utils.contains(".*<session-timeout>\\s*26\\s*</session-timeout>.*");
278             }
279             public void finalCheck() {
280                 assertEquals("Session timeout not set",new java.math.BigInteger JavaDoc("26"),webapp.getSingleSessionConfig().getSessionTimeout());
281                 utils.checkInDDXML(".*<session-timeout>\\s*26\\s*</session-timeout>.*");
282             }
283         };
284         utils.save();
285     }
286     
287     public void testExistingContextParameters() throws Exception JavaDoc {
288         JPanel JavaDoc panel = utils.getInnerSectionPanel("context_params");
289         InitParam[] params = webapp.getContextParam();
290         assertEquals("Wrong parameters count in model",1,params.length);
291         InitParam param = params[0];
292         utils.testProperties(param,new String JavaDoc[]{"ParamName","ParamValue"},new Object JavaDoc[]{"contextparamname","contextparamvalue"});
293         assertEquals("Unexpected parameter description","contextparamdesc",param.getDefaultDescription());
294         //table model
295
Component JavaDoc[] comp = panel.getComponents();
296         ContextParamsTablePanel contextPanel = (ContextParamsTablePanel)comp[1];
297         DDBeanTableModel model = (DDBeanTableModel)contextPanel.getModel();
298         assertEquals("Wrong parameters count in table model",1,model.getRowCount());
299         utils.testTableRow(model,0,new String JavaDoc[]{"contextparamname","contextparamvalue","contextparamdesc"});
300         //test XML
301
utils.checkInDDXML(".*<context-param>\\s*<description>contextparamdesc</description>\\s*<param-name>contextparamname</param-name>\\s*<param-value>contextparamvalue</param-value>\\s*</context-param>.*");
302     }
303     
304     
305     public void testAddContextParameters() throws Exception JavaDoc {
306         JPanel JavaDoc panel = utils.getInnerSectionPanel("context_params");
307         Component JavaDoc[] comp = panel.getComponents();
308         ContextParamsTablePanel contextPanel = (ContextParamsTablePanel)comp[1];
309         DDBeanTableModel model = (DDBeanTableModel)contextPanel.getModel();
310         model.addRow(new String JavaDoc[]{"newname","newval","newdes"});
311         ddObj.modelUpdatedFromUI();
312         //table model
313
int i=0;
314         for(i=0;i<model.getRowCount();i++) {
315             if(model.getValueAt(i,0).equals("newname")) break;
316         }
317         assertFalse("Parameter not added to table model",i==model.getRowCount());
318         assertEquals("Unexpected parameter value","newval",model.getValueAt(i,1));
319         assertEquals("Unexpected parameter description","newdes",model.getValueAt(i,2));
320         //xml
321
Thread.sleep(2000);
322         utils.checkInDDXML(".*<context-param>\\s*<description>newdes</description>\\s*<param-name>newname</param-name>\\s*<param-value>newval</param-value>\\s*</context-param>.*");
323         utils.save();
324     }
325     
326     public void testModifyContextParameter() throws Exception JavaDoc {
327         JPanel JavaDoc panel = utils.getInnerSectionPanel("context_params");
328         Component JavaDoc[] comp = panel.getComponents();
329         ContextParamsTablePanel contextPanel = (ContextParamsTablePanel)comp[1];
330         DDBeanTableModel model = (DDBeanTableModel)contextPanel.getModel();
331         int i;
332         for(i=0;i<model.getRowCount();i++) {
333             if(model.getValueAt(i,0).equals("newname")) break;
334         }
335         assertFalse("Parameter not found in table model",i==model.getRowCount());
336         model.setValueAt("newparamname",i,0);
337         ddObj.modelUpdatedFromUI();
338         assertEquals("Parameter name not updated in table model","newparamname",model.getValueAt(i,0));
339         
340         model.setValueAt("newparamvalue",i,1);
341         ddObj.modelUpdatedFromUI();
342         assertEquals("Parameter value not updated in table model","newparamvalue",model.getValueAt(i,1));
343         
344         model.setValueAt("newparamdesc",i,2);
345         ddObj.modelUpdatedFromUI();
346         assertEquals("Parameter description not updated in table model","newparamdesc",model.getValueAt(i,2));
347         Thread.sleep(2000);
348         utils.checkInDDXML(".*<context-param>\\s*<description>newparamdesc</description>\\s*<param-name>newparamname</param-name>\\s*<param-value>newparamvalue</param-value>\\s*</context-param>.*");
349         utils.save();
350     }
351     
352     public void testDelContextParameter() throws Exception JavaDoc {
353         JPanel JavaDoc panel = utils.getInnerSectionPanel("context_params");
354         Component JavaDoc[] comp = panel.getComponents();
355         ContextParamsTablePanel contextPanel = (ContextParamsTablePanel)comp[1];
356         DDBeanTableModel model = (DDBeanTableModel)contextPanel.getModel();
357         int i;
358         for(i=0;i<model.getRowCount();i++) {
359             if(model.getValueAt(i,0).equals("newparamname")) break;
360         }
361         assertFalse("Parameter not found in table model",i==model.getRowCount());
362         model.removeRow(i);
363         ddObj.modelUpdatedFromUI();
364         for(i=0;i<model.getRowCount();i++) {
365             if(model.getValueAt(i,0).equals("newparamname")) break;
366         }
367         assertTrue("Parameter not deleted from in table model",i==model.getRowCount());
368         Thread.sleep(2000);
369         utils.checkNotInDDXML(".*<context-param>.*<param-name>newparamname</param-name>.*</context-param>.*");
370         utils.save();
371     }
372     
373     public void testExistingListeners() throws Exception JavaDoc {
374         JPanel JavaDoc panel = utils.getInnerSectionPanel("listeners");
375         Listener[] list = webapp.getListener();
376         assertEquals("Wrong listeners count in model",1,list.length);
377         Listener listener = list[0];
378         assertEquals("Unexpected listener class","listenerclass",listener.getListenerClass());
379         assertEquals("Unexpected listener description","listenerdescription",listener.getDefaultDescription());
380         //table model
381
Component JavaDoc[] comp = panel.getComponents();
382         ListenersTablePanel listPanel = (ListenersTablePanel)comp[1];
383         DDBeanTableModel model = (DDBeanTableModel)listPanel.getModel();
384         assertEquals("Wrong listeners count in table model",1,model.getRowCount());
385         utils.testTableRow(model,0,new String JavaDoc[] {"listenerclass","listenerdescription"});
386         //test XML
387
utils.checkInDDXML(".* <listener>\\s*<description>listenerdescription</description>\\s*<listener-class>listenerclass</listener-class>\\s*</listener>.*");
388     }
389     
390     public void testAddListener() throws Exception JavaDoc {
391         JPanel JavaDoc panel = utils.getInnerSectionPanel("listeners");
392         Component JavaDoc[] comp = panel.getComponents();
393         ListenersTablePanel listPanel = (ListenersTablePanel)comp[1];
394         DDBeanTableModel model = (DDBeanTableModel)listPanel.getModel();
395         model.addRow(new String JavaDoc[]{"newlist","newlistdesc"});
396         ddObj.modelUpdatedFromUI();
397         Listener[] list = webapp.getListener();
398         int i;
399         for (i = 0; i < list.length; i++) {
400             if(list[i].getListenerClass().equals("newlist")) break;
401         }
402         assertFalse("New listener not added",i == list.length);
403         assertEquals("Listener class does not match","newlist",list[i].getListenerClass());
404         assertEquals("Listener description does not match","newlistdesc",list[i].getDefaultDescription());
405         Thread.sleep(2000);
406         utils.checkInDDXML(".*<listener>\\s*<description>newlistdesc</description>\\s*<listener-class>newlist</listener-class>\\s*</listener>.*");
407     }
408     
409     public void testModifyListener() throws Exception JavaDoc {
410         JPanel JavaDoc panel = utils.getInnerSectionPanel("listeners");
411         Component JavaDoc[] comp = panel.getComponents();
412         ListenersTablePanel listPanel = (ListenersTablePanel)comp[1];
413         DDBeanTableModel model = (DDBeanTableModel)listPanel.getModel();
414         int i;
415         for (i = 0; i < model.getRowCount(); i++) {
416             if(model.getValueAt(i,0).equals("newlist")) break;
417         }
418         assertFalse("Listener not found",i == model.getRowCount());
419         model.setValueAt("newlistmod",i,0);
420         model.setValueAt("newlistdescmod",i,1);
421         ddObj.modelUpdatedFromUI();
422         Listener[] list = webapp.getListener();
423         for (i = 0; i < list.length; i++) {
424             if(list[i].getListenerClass().equals("newlistmod")) break;
425         }
426         assertFalse("Listener not modified",i == list.length);
427         assertEquals("Description not changed","newlistdescmod",list[i].getDefaultDescription());
428         Thread.sleep(2000);
429         utils.checkInDDXML(".*<listener>\\s*<description>newlistdescmod</description>\\s*<listener-class>newlistmod</listener-class>\\s*</listener>.*");
430     }
431     
432     public void testDelListener() throws Exception JavaDoc {
433         JPanel JavaDoc panel = utils.getInnerSectionPanel("listeners");
434         Component JavaDoc[] comp = panel.getComponents();
435         ListenersTablePanel listPanel = (ListenersTablePanel)comp[1];
436         DDBeanTableModel model = (DDBeanTableModel)listPanel.getModel();
437         int i;
438         for (i = 0; i < model.getRowCount(); i++) {
439             if(model.getValueAt(i,0).equals("newlistmod")) break;
440         }
441         assertFalse("Listener not found",i == model.getRowCount());
442         model.removeRow(i);
443         ddObj.modelUpdatedFromUI();
444         for(i=0;i<model.getRowCount();i++) {
445             if(model.getValueAt(i,0).equals("newlistmod")) break;
446         }
447         assertTrue("Listener not deleted from in table model",i==model.getRowCount());
448         Thread.sleep(2000);
449         utils.checkNotInDDXML(".* <listener>\\s*<description>newlistdescmod</description>\\s*<listener-class>mewlistmod</listener-class>\\s*</listener>.*");
450         utils.save();
451     }
452     
453     public void testExistingServlets() throws Exception JavaDoc {
454         ddObj.openView(1);
455         Utils.waitForAWTDispatchThread();
456         Servlet[] servlets = webapp.getServlet();
457         assertEquals("Wrong count of servlets",1,servlets.length);
458         JPanel JavaDoc panel = utils.getInnerSectionPanel(servlets[0]);
459         Component JavaDoc[] comp = panel.getComponents();
460         assertEquals("Wrong servlet name","ServletName",((JTextField JavaDoc)comp[1]).getText());
461         assertEquals("Wrong startup order","",((JTextField JavaDoc)comp[3]).getText());
462         assertEquals("Wrong servlet description","ServletDescription",((JTextArea JavaDoc)comp[5]).getText());
463         assertEquals("Wrong servlet source type",true,((JRadioButton JavaDoc)comp[6]).isSelected());
464         assertEquals("Wrong servlet class","ServletClass",((JTextField JavaDoc)comp[7]).getText());
465         assertEquals("Wrong servlet source type",false,((JRadioButton JavaDoc)comp[9]).isSelected());
466         assertEquals("Wrong servlet pattern","*",((JTextField JavaDoc)comp[13]).getText());
467         InitParamsPanel tablePanel = ((InitParamsPanel)comp[17]);
468         DDBeanTableModel model = (DDBeanTableModel) tablePanel.getTable().getModel();
469         assertEquals("Wrong count of init parameters",1,model.getRowCount());
470         utils.testTableRow(model,0,new String JavaDoc[]{"ServletParam","ServletParamVal","ServletParamDesc"});
471         
472         Servlet servlet = servlets[0];
473         utils.testProperties(servlet,new String JavaDoc[]{"ServletName","LoadOnStartup","ServletClass"},new Object JavaDoc[]{"ServletName",null,"ServletClass"});
474         ServletMapping[] mappings = webapp.getServletMapping();
475         assertEquals("Wrong servlet mapping",1,mappings.length);
476         utils.testProperties(mappings[0],new String JavaDoc[]{"ServletName","UrlPattern"},new Object JavaDoc[]{"ServletName","*"});
477         assertEquals("Description does not match","ServletDescription",servlet.getDefaultDescription());
478         InitParam[] params = servlet.getInitParam();
479         assertEquals("Wrong number of init params",1,params.length);
480         utils.testProperties(params[0],new String JavaDoc[] {"ParamName","ParamValue"},new Object JavaDoc[]{"ServletParam","ServletParamVal"});
481         assertEquals("Description does not match","ServletParamDesc",params[0].getDefaultDescription());
482     }
483     
484     public void testModifyServlet() throws Exception JavaDoc {
485         Servlet[] servlets = webapp.getServlet();
486         assertEquals("Wrong count of servlets",1,servlets.length);
487         JPanel JavaDoc panel = utils.getInnerSectionPanel(servlets[0]);
488         Component JavaDoc[] comp = panel.getComponents();
489         utils.setText((JTextField JavaDoc)comp[1],"ServletNameMod");
490         comp[3].requestFocus();
491         new StepIterator() {
492             public boolean step() throws Exception JavaDoc {
493                 return utils.contains(".*<servlet>.*<servlet-name>ServletNameMod</servlet-name>.*</servlet>.*");
494             }
495
496             public void finalCheck() {
497                 utils.checkInDDXML(".*<servlet>.*<servlet-name>ServletNameMod</servlet-name>.*</servlet>.*");
498             }
499             
500         };
501         utils.setText((JTextField JavaDoc)comp[3],"1");
502         comp[5].requestFocus();
503         new StepIterator() {
504             public boolean step() throws Exception JavaDoc {
505                 return utils.contains(".*<servlet>.*<load-on-startup>1</load-on-startup>.*</servlet>.*");
506             }
507
508             public void finalCheck() {
509                utils.checkInDDXML(".*<servlet>.*<load-on-startup>1</load-on-startup>.*</servlet>.*");
510             }
511         };
512         utils.setText((JTextArea JavaDoc)comp[5],"ServletDescriptionMod");
513         comp[9].requestFocus();
514         new StepIterator() {
515             public boolean step() throws Exception JavaDoc {
516                 return utils.contains(".*<servlet>\\s*<description>ServletDescriptionMod</description>.*</servlet>.*");
517             }
518
519             public void finalCheck() {
520                 utils.checkInDDXML(".*<servlet>\\s*<description>ServletDescriptionMod</description>.*</servlet>.*");
521             }
522         };
523         ((JRadioButton JavaDoc)comp[9]).setSelected(true);
524         comp[10].requestFocus();
525         ddObj.modelUpdatedFromUI();
526         Thread.sleep(2000);
527         utils.setText((JTextField JavaDoc)comp[10],"JSPFile.jsp");
528         comp[13].requestFocus();
529         new StepIterator() {
530             public boolean step() throws Exception JavaDoc {
531                 return utils.contains(".*<servlet>.*<jsp-file>JSPFile.jsp</jsp-file>.*</servlet>.*");
532             }
533
534             public void finalCheck() {
535                 utils.checkInDDXML(".*<servlet>.*<jsp-file>JSPFile.jsp</jsp-file>.*</servlet>.*");
536             }
537         };
538         utils.setText((JTextField JavaDoc)comp[13],"/*");
539         comp[1].requestFocus();
540         new StepIterator() {
541             public boolean step() throws Exception JavaDoc {
542                 return utils.contains(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
543             }
544
545             public void finalCheck() {
546                 utils.checkInDDXML(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
547             }
548         };
549         Servlet servlet = servlets[0];
550         utils.testProperties(servlet,new String JavaDoc[]{"ServletName","LoadOnStartup","JspFile"},new Object JavaDoc[]{"ServletNameMod",new java.math.BigInteger JavaDoc("1"),"JSPFile.jsp"});
551         ServletMapping[] mappings = webapp.getServletMapping();
552         assertEquals("Wrong servlet mapping",1,mappings.length);
553         utils.testProperties(mappings[0],new String JavaDoc[]{"ServletName","UrlPattern"},new Object JavaDoc[]{"ServletNameMod","/*"});
554         utils.checkInDDXML(".*<servlet>\\s*<description>ServletDescriptionMod</description>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<jsp-file>JSPFile.jsp</jsp-file>.*<load-on-startup>1</load-on-startup>\\s*</servlet>.*");
555         utils.checkInDDXML(".*<servlet-mapping>\\s*<servlet-name>ServletNameMod</servlet-name>\\s*<url-pattern>/\\*</url-pattern>\\s*</servlet-mapping>.*");
556         utils.save();
557     }
558     
559     public void testAddServletParam() throws Exception JavaDoc {
560         Servlet[] servlets = webapp.getServlet();
561         DDBeanTableModel model = utils.getServletInitParamsTableModel();
562         model.addRow(new String JavaDoc[] {"newparam","newval","newdesc"});
563         ddObj.modelUpdatedFromUI();
564         Thread.sleep(2000);
565         InitParam[] params = servlets[0].getInitParam();
566         int i;
567         for (i = 0; i < model.getRowCount(); i++) {
568             if(model.getValueAt(i,0).equals("newparam")) break;
569         }
570         assertFalse("New parameter is not added",i==model.getRowCount());
571         utils.testTableRow(model,i,new String JavaDoc[]{"newparam","newval","newdesc"});
572         for (i = 0; i < params.length; i++) {
573             if(params[i].getParamName().equals("newparam")) break;
574         }
575         assertFalse("New parameter is not added",i==params.length);
576         utils.testProperties(params[i],new String JavaDoc[] {"ParamName","ParamValue"},new Object JavaDoc[]{"newparam","newval"});
577         assertEquals("Description does not match","newdesc",params[i].getDefaultDescription());
578         utils.checkInDDXML(".*<servlet>.*<init-param>\\s*<description>newdesc</description>\\s*<param-name>newparam</param-name>\\s*<param-value>newval</param-value>\\s*</init-param>.*</servlet>.*");
579         utils.save();
580     }
581     
582     public void testModifyServletParam() throws Exception JavaDoc {
583         Servlet[] servlets = webapp.getServlet();
584         DDBeanTableModel model = utils.getServletInitParamsTableModel();
585         int i;
586         for (i = 0; i < model.getRowCount(); i++) {
587             if(model.getValueAt(i,0).equals("newparam")) break;
588         }
589         assertFalse("Parameter is not found",i==model.getRowCount());
590         model.setValueAt("newparammod",i,0);
591         model.setValueAt("newvalmod",i,1);
592         model.setValueAt("newdescmod",i,2);
593         ddObj.modelUpdatedFromUI();
594         Thread.sleep(2000);
595         for (i = 0; i < model.getRowCount(); i++) {
596             if(model.getValueAt(i,0).equals("newparammod")) break;
597         }
598         assertFalse("Parameter is not modified",i==model.getRowCount());
599         utils.testTableRow(model,i,new String JavaDoc[]{"newparammod","newvalmod","newdescmod"});
600         InitParam[] params = servlets[0].getInitParam();
601         for (i = 0; i < params.length; i++) {
602             if(params[i].getParamName().equals("newparammod")) break;
603         }
604         assertFalse("Parameter is not modified",i==params.length);
605         utils.testProperties(params[i],new String JavaDoc[] {"ParamName","ParamValue"},new Object JavaDoc[]{"newparammod","newvalmod"});
606         assertEquals("Description does not match","newdescmod",params[i].getDefaultDescription());
607         utils.checkInDDXML(".*<servlet>.*<init-param>\\s*<description>newdescmod</description>\\s*<param-name>newparammod</param-name>\\s*<param-value>newvalmod</param-value>\\s*</init-param>.*</servlet>.*");
608         utils.save();
609     }
610     
611     public void testDelServletParam() throws Exception JavaDoc {
612         Servlet[] servlets = webapp.getServlet();
613         DDBeanTableModel model = utils.getServletInitParamsTableModel();
614         int i;
615         for (i = 0; i < model.getRowCount(); i++) {
616             if(model.getValueAt(i,0).equals("newparammod")) break;
617         }
618         assertFalse("Parameter is not found",i==model.getRowCount());
619         model.removeRow(i);
620         ddObj.modelUpdatedFromUI();
621         Thread.sleep(2000);
622         for (i = 0; i < model.getRowCount(); i++) {
623             if(model.getValueAt(i,0).equals("newparammod")) break;
624         }
625         assertTrue("Parameter is not deleted",i==model.getRowCount());
626         InitParam[] params = servlets[0].getInitParam();
627         for (i = 0; i < params.length; i++) {
628             if(params[i].getParamName().equals("newparammod")) break;
629         }
630         assertTrue("Parameter is not deleted",i==params.length);
631         utils.checkNotInDDXML(".*<servlet>.*<init-param>\\s*<description>newdescmod</description>\\s*<param-name>newparammod</param-name>\\s*<param-value>newvalmod</param-value>\\s*</init-param>.*</servlet>.*");
632         utils.save();
633     }
634             
635     public void testExistingFilters() throws Exception JavaDoc {
636         ddObj.openView(2);
637         Utils.waitForAWTDispatchThread();
638         Filter[] filters = webapp.getFilter();
639         assertEquals("Unexpected filter count",1,filters.length);
640         Filter filter = filters[0];
641         ddObj.showElement(filter);
642         JPanel JavaDoc panel = utils.getInnerSectionPanel(filter);
643         Component JavaDoc[] comp = panel.getComponents();
644         assertEquals("Filter name does not match","FilterName",((JTextField JavaDoc)comp[1]).getText());
645         assertEquals("Filter description does not match","FilterDescription",((JTextArea JavaDoc)comp[3]).getText());
646         assertEquals("Filter class does not match","FilterClass",((JTextField JavaDoc)comp[5]).getText());
647         DDBeanTableModel model = (DDBeanTableModel)((FilterParamsPanel)comp[9]).getModel();
648         assertEquals("Unexpected filter params count",1,model.getRowCount());
649         utils.testTableRow(model,0,new String JavaDoc[]{"FilterParamName","FilterParamValue","FilterParamDescription"});
650         utils.testProperties(filter,new String JavaDoc[]{"FilterName","FilterClass"},new Object JavaDoc[]{"FilterName","FilterClass"});
651         assertEquals("Description does not match","FilterDescription",filter.getDefaultDescription());
652         assertEquals("Unexpected conut of filter init params",1,filter.getInitParam().length);
653         utils.testProperties(filter.getInitParam(0),new String JavaDoc[]{"ParamName","ParamValue"},new Object JavaDoc[]{"FilterParamName","FilterParamValue"} );
654         assertEquals("Filter param description does not match.","FilterParamDescription",filter.getInitParam(0).getDefaultDescription());
655     }
656     
657     public void testModifyFilter() throws Exception JavaDoc {
658         Filter[] filters = webapp.getFilter();
659         assertEquals("Unexpected filter count",1,filters.length);
660         Filter filter = filters[0];
661         ddObj.showElement(filter);
662         JPanel JavaDoc panel = utils.getInnerSectionPanel(filter);
663         Component JavaDoc[] comp = panel.getComponents();
664         utils.setText((JTextField JavaDoc)comp[1],"FilterNameMod");
665         comp[3].requestFocus();
666         new StepIterator() {
667             public boolean step() throws Exception JavaDoc {
668                 return utils.contains(".*<filter-name>FilterNameMod</filter-name>.*");
669             }
670         };
671         utils.setText((JTextArea JavaDoc)comp[3],"FilterDescriptionMod");
672         comp[5].requestFocus();
673         new StepIterator() {
674             public boolean step() throws Exception JavaDoc {
675                 return utils.contains(".*<description>FilterDescriptionMod</description>.*");
676             }
677         };
678         utils.setText((JTextField JavaDoc)comp[5],"FilterClassMod");
679         comp[1].requestFocus();
680         new StepIterator() {
681             public boolean step() throws Exception JavaDoc {
682                 return utils.contains(".*<filter-class>FilterClassMod</filter-class>.*");
683             }
684         };
685         filter = webapp.getFilter(0);
686         utils.testProperties(filter,new String JavaDoc[]{"FilterName","FilterClass"},new Object JavaDoc[]{"FilterNameMod","FilterClassMod"});
687         assertEquals("Description not updated.","FilterDescriptionMod",filter.getDefaultDescription());
688         utils.checkInDDXML(".*<description>FilterDescriptionMod</description>\\s*<filter-name>FilterNameMod</filter-name>\\s*<filter-class>FilterClassMod</filter-class>.*");
689         utils.save();
690     }
691     
692     public void testAddFilterParam() throws Exception JavaDoc {
693         Filter[] filters = webapp.getFilter();
694         DDBeanTableModel model = utils.getFilterInitParamsTableModel();
695         model.addRow(new String JavaDoc[]{"newfilterparam","newfilterparamval","newfilterparamdesc"});
696         ddObj.modelUpdatedFromUI();
697         Thread.sleep(2000);
698         InitParam[] params = filters[0].getInitParam();
699         int i;
700         for (i = 0; i < model.getRowCount(); i++) {
701             if(model.getValueAt(i,0).equals("newfilterparam")) break;
702         }
703         assertFalse("New parameter is not added",i==model.getRowCount());
704         utils.testTableRow(model,i,new String JavaDoc[]{"newfilterparam","newfilterparamval","newfilterparamdesc"});
705         for (i = 0; i < params.length; i++) {
706             if(params[i].getParamName().equals("newfilterparam")) break;
707         }
708         assertFalse("New parameter is not added",i==params.length);
709         utils.testProperties(params[i],new String JavaDoc[] {"ParamName","ParamValue"},new Object JavaDoc[]{"newfilterparam","newfilterparamval"});
710         assertEquals("Description does not match","newfilterparamdesc",params[i].getDefaultDescription());
711         utils.checkInDDXML(".*<filter>.*<init-param>\\s*<description>newfilterparamdesc</description>\\s*<param-name>newfilterparam</param-name>\\s*<param-value>newfilterparamval</param-value>\\s*</init-param>.*</filter>.*");
712         utils.save();
713     }
714     
715     public void testModifyFilterParam() throws Exception JavaDoc {
716         Filter[] filters = webapp.getFilter();
717         DDBeanTableModel model = utils.getFilterInitParamsTableModel();
718         int i;
719         for (i = 0; i < model.getRowCount(); i++) {
720             if(model.getValueAt(i,0).equals("newfilterparam")) break;
721         }
722         assertFalse("Parameter not found",i==model.getRowCount());
723         utils.setTableRow(model,i,new Object JavaDoc[]{"newfilterparammod","newfilterparamvalmod","newfilterparamdescmod"});
724         ddObj.modelUpdatedFromUI();
725         Thread.sleep(2000);
726         InitParam[] params = filters[0].getInitParam();
727         for (i = 0; i < params.length; i++) {
728             if(params[i].getParamName().equals("newfilterparammod")) break;
729         }
730         assertFalse("Parameter not modified",i==params.length);
731         utils.testProperties(params[i],new String JavaDoc[]{"ParamName","ParamValue"},new Object JavaDoc[]{"newfilterparammod","newfilterparamvalmod"});
732         assertEquals("Filter param description not modified","newfilterparamdescmod",params[i].getDefaultDescription());
733         utils.checkInDDXML(".*<filter>.*<init-param>\\s*<description>newfilterparamdescmod</description>\\s*<param-name>newfilterparammod</param-name>\\s*<param-value>newfilterparamvalmod</param-value>\\s*</init-param>.*</filter>.*");
734         utils.save();
735     }
736     
737     public void testDelFilterParam() throws Exception JavaDoc {
738         Filter[] filters = webapp.getFilter();
739         DDBeanTableModel model = utils.getFilterInitParamsTableModel();
740         int i;
741         for (i = 0; i < model.getRowCount(); i++) {
742             if(model.getValueAt(i,0).equals("newfilterparammod")) break;
743         }
744         assertFalse("Parameter not found",i==model.getRowCount());
745         model.removeRow(i);
746         ddObj.modelUpdatedFromUI();
747         Thread.sleep(2000);
748         InitParam[] params = filters[0].getInitParam();
749         for (i = 0; i < params.length; i++) {
750             if(params[i].getParamName().equals("newfilterparammod")) break;
751         }
752         assertTrue("Parameter not deleted",i==params.length);
753         utils.checkNotInDDXML(".*<filter>.*<init-param>\\s*<description>newfilterparamdescmod</description>\\s*<param-name>newfilterparammod</param-name>\\s*<param-value>newfilterparamvalmod</param-value>\\s*</init-param>.*</filter>.*");
754         utils.save();
755     }
756     
757     public void testExistingFilterMappings() throws Exception JavaDoc {
758         FilterMapping[] mappings = webapp.getFilterMapping();
759         assertTrue("Wrong number of filter mappings",mappings.length==1);
760         JPanel JavaDoc panel = utils.getInnerSectionPanel("filter_mappings");
761         utils.testProperties(mappings[0],new String JavaDoc[]{"FilterName","UrlPattern","ServletName"},new Object JavaDoc[]{"MappedFilterName","/*",null});
762         String JavaDoc[] exDisp = {"REQUEST","FORWARD","INCLUDE","ERROR"};
763         String JavaDoc[] actDisp = mappings[0].getDispatcher();
764         assertEquals("Wrong count of dispatchers types",exDisp.length,actDisp.length);
765         for (int i = 0; i < exDisp.length; i++) {
766             assertEquals("Wrong dispatcher type.",exDisp[i],actDisp[i]);
767         }
768         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
769         assertEquals("Wrong filter mapping count.",1,model.getRowCount());
770         utils.testTableRow(model,0,new String JavaDoc[]{"MappedFilterName","/* (URL)","REQUEST, FORWARD, INCLUDE, ERROR"});
771     }
772     
773     public void testAddFilterMapping() throws Exception JavaDoc {
774         JPanel JavaDoc panel = utils.getInnerSectionPanel("filter_mappings");
775         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
776         String JavaDoc filterName = webapp.getFilter(0).getFilterName();
777         String JavaDoc servletName = webapp.getServlet(0).getServletName();
778         model.addRow(new Object JavaDoc[]{filterName,null,servletName,new String JavaDoc[]{"REQUEST","ERROR"}});
779         ddObj.modelUpdatedFromUI();
780         Thread.sleep(2000);
781         //check table model
782
int i;
783         assertEquals("Mapping was not added",2,model.getRowCount());
784         for (i = 0; i < model.getRowCount(); i++) {
785             if(model.getValueAt(i,0).equals(filterName)) break;
786         }
787         assertTrue("Mapping was not found",i<model.getRowCount());
788         utils.testTableRow(model,i,new String JavaDoc[]{filterName,servletName+" (Servlet)","REQUEST, ERROR"});
789         //check model
790
FilterMapping[] mappings = webapp.getFilterMapping();
791         for (i = 0; i < mappings.length; i++) {
792             if(mappings[i].getFilterName().equals(filterName)) break;
793         }
794         assertTrue("Mapping was not found",i<mappings.length);
795         utils.testProperties(mappings[i],new String JavaDoc[]{"FilterName","ServletName","UrlPattern"},new Object JavaDoc[] {filterName,servletName,null});
796         String JavaDoc[] exDisp = {"REQUEST","ERROR"};
797         String JavaDoc[] actDisp = mappings[i].getDispatcher();
798         assertEquals("Wrong count of dispatchers types",exDisp.length,actDisp.length);
799         for (i = 0; i < exDisp.length; i++) assertEquals("Wrong dispatcher type.",exDisp[i],actDisp[i]);
800         //check XML
801
utils.checkInDDXML(".*<filter-mapping>\\s*<filter-name>"+filterName+"</filter-name>\\s*<servlet-name>"+servletName+"</servlet-name>\\s*<dispatcher>REQUEST</dispatcher>\\s*<dispatcher>ERROR</dispatcher>\\s*</filter-mapping>.*");
802         utils.save();
803     }
804     
805     
806     public void testFilterNameChangePropagation() throws Exception JavaDoc {
807         final String JavaDoc filterName = "changedfilter";
808         String JavaDoc servletName = webapp.getServlet(0).getServletName();
809         Filter[] filters = webapp.getFilter();
810         Filter filter = filters[0];
811         ddObj.showElement(filter);
812         JPanel JavaDoc panel = utils.getInnerSectionPanel(filter);
813         Component JavaDoc[] comp = panel.getComponents();
814         comp[1].requestFocus();
815         utils.setText((JTextField JavaDoc)comp[1],filterName);
816         comp[3].requestFocus();
817         new StepIterator() {
818             public boolean step() throws Exception JavaDoc {
819                 return utils.contains(".*<filter-name>"+filterName+"</filter-name>.*");
820             }
821         };
822         //testing propagation of the changes
823
panel = utils.getInnerSectionPanel("filter_mappings");
824         ddObj.showElement(webapp.getFilterMapping(0));
825         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
826         //check table model
827
int i;
828         for (i = 0; i < model.getRowCount(); i++) {
829             if(model.getValueAt(i,0).equals(filterName)) break;
830         }
831         assertTrue("Mapping was not changed",i<model.getRowCount());
832         utils.testTableRow(model,i,new String JavaDoc[]{filterName,servletName+" (Servlet)","REQUEST, ERROR"});
833         //check model
834
FilterMapping[] mappings = webapp.getFilterMapping();
835         for (i = 0; i < mappings.length; i++) {
836             if(mappings[i].getFilterName().equals(filterName)) break;
837         }
838         assertTrue("Mapping was not found",i<mappings.length);
839         utils.testProperties(mappings[i],new String JavaDoc[]{"FilterName","ServletName","UrlPattern"},new Object JavaDoc[] {filterName,servletName,null});
840         String JavaDoc[] exDisp = {"REQUEST","ERROR"};
841         String JavaDoc[] actDisp = mappings[i].getDispatcher();
842         assertEquals("Wrong count of dispatchers types",exDisp.length,actDisp.length);
843         for (i = 0; i < exDisp.length; i++) assertEquals("Wrong dispatcher type.",exDisp[i],actDisp[i]);
844         //check XML
845
utils.checkInDDXML(".*<filter-mapping>\\s*<filter-name>"+filterName+"</filter-name>\\s*<servlet-name>"+servletName+"</servlet-name>\\s*<dispatcher>REQUEST</dispatcher>\\s*<dispatcher>ERROR</dispatcher>\\s*</filter-mapping>.*");
846         utils.save();
847     }
848     
849     public void testServletNameChangePropagation() throws Exception JavaDoc {
850         final String JavaDoc filterName = webapp.getFilter(0).getFilterName();
851         final String JavaDoc servletName = "changedS";
852         Servlet[] servlets = webapp.getServlet();
853         Servlet servlet = servlets[0];
854         ddObj.openView(1);
855         Utils.waitForAWTDispatchThread();
856         ddObj.showElement(servlet);
857         JPanel JavaDoc panel = utils.getInnerSectionPanel(servlet);
858         Component JavaDoc[] comp = panel.getComponents();
859         comp[1].requestFocus();
860         utils.setText((JTextField JavaDoc)comp[1],servletName);
861         comp[3].requestFocus();
862         new StepIterator() {
863             public boolean step() throws Exception JavaDoc {
864                 return utils.contains(".*<servlet>.*<servlet-name>"+servletName+"</servlet-name>.*</servlet>.*");
865             }
866         };
867         ddObj.openView(2);
868         Utils.waitForAWTDispatchThread();
869         panel = utils.getInnerSectionPanel("filter_mappings");
870         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
871         //check table model
872
int i;
873         for (i = 0; i < model.getRowCount(); i++) {
874             if(((String JavaDoc)model.getValueAt(i,1)).startsWith(servletName)) break;
875         }
876         assertTrue("Mapping was not changed",i<model.getRowCount());
877         utils.testTableRow(model,i,new String JavaDoc[]{filterName,servletName+" (Servlet)","REQUEST, ERROR"});
878         //check model
879
FilterMapping[] mappings = webapp.getFilterMapping();
880         for (i = 0; i < mappings.length; i++) {
881             if(mappings[i].getFilterName().equals(filterName)) break;
882         }
883         assertTrue("Mapping was not found",i<mappings.length);
884         utils.testProperties(mappings[i],new String JavaDoc[]{"FilterName","ServletName","UrlPattern"},new Object JavaDoc[] {filterName,servletName,null});
885         String JavaDoc[] exDisp = {"REQUEST","ERROR"};
886         String JavaDoc[] actDisp = mappings[i].getDispatcher();
887         assertEquals("Wrong count of dispatchers types",exDisp.length,actDisp.length);
888         for (i = 0; i < exDisp.length; i++) assertEquals("Wrong dispatcher type.",exDisp[i],actDisp[i]);
889         //check XML
890
utils.checkInDDXML(".*<filter-mapping>\\s*<filter-name>"+filterName+"</filter-name>\\s*<servlet-name>"+servletName+"</servlet-name>\\s*<dispatcher>REQUEST</dispatcher>\\s*<dispatcher>ERROR</dispatcher>\\s*</filter-mapping>.*");
891         utils.save();
892     }
893     public void testModifyFilterMapping() throws Exception JavaDoc {
894         JPanel JavaDoc panel = utils.getInnerSectionPanel("filter_mappings");
895         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
896         model.editRow(0,new Object JavaDoc[]{"FilterNameMod","*",null,new String JavaDoc[]{"FORWARD","INCLUDE"}});
897         ddObj.modelUpdatedFromUI();
898         Thread.sleep(2000);
899         //check table model
900
utils.testTableRow(model,0,new String JavaDoc[]{"FilterNameMod","* (URL)","FORWARD, INCLUDE"});
901         //check model
902
FilterMapping[] mappings = webapp.getFilterMapping();
903         utils.testProperties(mappings[0],new String JavaDoc[]{"FilterName","ServletName","UrlPattern"},new Object JavaDoc[] {"FilterNameMod",null,"*"});
904         String JavaDoc[] exDisp = {"FORWARD","INCLUDE"};
905         String JavaDoc[] actDisp = mappings[0].getDispatcher();
906         assertEquals("Wrong count of dispatchers types",exDisp.length,actDisp.length);
907         for (int i = 0; i < exDisp.length; i++) assertEquals("Wrong dispatcher type.",exDisp[i],actDisp[i]);
908         //check XML
909
utils.checkInDDXML(".*<filter-mapping>\\s*<filter-name>FilterNameMod</filter-name>\\s*<url-pattern>\\*</url-pattern>\\s*<dispatcher>FORWARD</dispatcher>\\s*<dispatcher>INCLUDE</dispatcher>\\s*</filter-mapping>.*");
910     }
911     
912     public void testDelFilterMapping() throws Exception JavaDoc {
913         JPanel JavaDoc panel = utils.getInnerSectionPanel("filter_mappings");
914         DDBeanTableModel model = (DDBeanTableModel) ((FilterMappingsTablePanel)panel.getComponent(1)).getTable().getModel();
915         final String JavaDoc mappingName = (String JavaDoc) model.getValueAt(0,0);
916         model.removeRow(0);
917         ddObj.modelUpdatedFromUI();
918         Thread.sleep(2000);
919         int i;
920         for (i= 0; i < model.getRowCount(); i++) {
921             assertFalse("Mapping was not deleted.",model.getValueAt(i,0).equals(mappingName));
922         }
923         FilterMapping[] mappings = webapp.getFilterMapping();
924         for (i= 0; i < mappings.length; i++) {
925             assertFalse("Mapping was not deleted.",mappings[i].getFilterName().equals(mappingName));
926         }
927         utils.checkNotInDDXML(".*<filter-mapping>\\s*<filter-name>"+mappingName+"</filter-name>.*</filter-mapping>.*");
928         utils.save();
929     }
930     // TODO tests for pages
931
// TODO tests for references
932
}
933
Popular Tags