View Javadoc

1   /*
2    * $Id: FormTagTest.java 805237 2009-08-18 00:36:15Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Set;
29  
30  import org.apache.struts2.StrutsConstants;
31  import org.apache.struts2.TestAction;
32  import org.apache.struts2.TestConfigurationProvider;
33  import org.apache.struts2.components.Form;
34  import org.apache.struts2.views.jsp.AbstractUITagTest;
35  import org.apache.struts2.views.jsp.ActionTag;
36  import org.easymock.EasyMock;
37  
38  import com.opensymphony.xwork2.*;
39  import com.opensymphony.xwork2.config.RuntimeConfiguration;
40  import com.opensymphony.xwork2.config.entities.ActionConfig;
41  import com.opensymphony.xwork2.config.entities.InterceptorMapping;
42  import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
43  import com.opensymphony.xwork2.inject.Container;
44  import com.opensymphony.xwork2.inject.Scope.Strategy;
45  import com.opensymphony.xwork2.validator.ValidationInterceptor;
46  
47  
48  /***
49   * FormTagTest
50   */
51  public class FormTagTest extends AbstractUITagTest {
52  
53      public void testFormWithActionAttributeContainingBothActionAndMethod() throws Exception {
54          FormTag tag = new FormTag();
55          tag.setPageContext(pageContext);
56          tag.setName("myForm");
57          tag.setMethod("post");
58          tag.setAcceptcharset("UTF-8");
59          tag.setAction("testAction");
60          tag.setEnctype("myEncType");
61          tag.setTitle("mytitle");
62          tag.setOnsubmit("submitMe()");
63          tag.doStartTag();
64          tag.doEndTag();
65  
66          verify(FormTag.class.getResource("Formtag-9.txt"));
67      }
68      
69      public void testFormWithActionAttributeContainingBothActionAndDMIMethod() throws Exception {
70          FormTag tag = new FormTag();
71          tag.setPageContext(pageContext);
72          tag.setName("myForm");
73          tag.setMethod("post");
74          tag.setAcceptcharset("UTF-8");
75          tag.setAction("testAction!testMethod");
76          tag.setEnctype("myEncType");
77          tag.setTitle("mytitle");
78          tag.setOnsubmit("submitMe()");
79          tag.doStartTag();
80          tag.doEndTag();
81  
82          verify(FormTag.class.getResource("Formtag-23.txt"));
83      }    
84  
85      public void testFormWithFocusElement() throws Exception {
86          FormTag tag = new FormTag();
87          tag.setTheme("xhtml");
88          tag.setPageContext(pageContext);
89          tag.setAction("testAction");
90          tag.setFocusElement("felement");
91          tag.doStartTag();
92          tag.doEndTag();
93  
94          verify(FormTag.class.getResource("Formtag-12.txt"));
95      }
96  
97      public void testFormWithActionAttributeContainingBothActionAndMethodAndNamespace() throws Exception {
98          FormTag tag = new FormTag();
99          tag.setPageContext(pageContext);
100         tag.setName("myForm");
101         tag.setNamespace("/testNamespace");
102         tag.setMethod("post");
103         tag.setAcceptcharset("UTF-8");
104         tag.setAction("testNamespaceAction");
105         tag.setEnctype("myEncType");
106         tag.setTitle("mytitle");
107         tag.setOnsubmit("submitMe()");
108 
109         tag.doStartTag();
110         tag.doEndTag();
111 
112         verify(FormTag.class.getResource("Formtag-10.txt"));
113     }
114 
115 
116     public void testForm() throws Exception {
117 
118         request.setupGetServletPath("/testAction");
119 
120         TestAction testAction = (TestAction) action;
121         testAction.setFoo("bar");
122 
123         FormTag tag = new FormTag();
124         tag.setPageContext(pageContext);
125         tag.setName("myForm");
126         tag.setMethod("post");
127         tag.setAcceptcharset("UTF-8");
128         tag.setAction("myAction");
129         tag.setEnctype("myEncType");
130         tag.setTitle("mytitle");
131         tag.setOnsubmit("submitMe()");
132         tag.setId("myid");
133 
134         tag.doStartTag();
135         tag.doEndTag();
136 
137         verify(FormTag.class.getResource("Formtag-1.txt"));
138     }
139 
140      public void testFormNoNameOrId() throws Exception {
141 
142         request.setupGetServletPath("/testAction");
143 
144         TestAction testAction = (TestAction) action;
145         testAction.setFoo("bar");
146 
147         FormTag tag = new FormTag();
148         tag.setPageContext(pageContext);
149         tag.setMethod("post");
150         tag.setAcceptcharset("UTF-8");
151         tag.setAction("myAction");
152         tag.setEnctype("myEncType");
153         tag.setTitle("mytitle");
154         tag.setOnsubmit("submitMe()");
155 
156         tag.doStartTag();
157         tag.doEndTag();
158 
159         verify(FormTag.class.getResource("Formtag-25.txt"));
160     }
161 
162     /***
163      * This test with form tag validation enabled. Js validation script will appear
164      * cause action submited by the form is intercepted by validation interceptor which
165      * "include" all methods.
166      */
167     public void testFormWithCustomOnsubmitEnabledWithValidateEnabled1() throws Exception {
168 
169         final Container cont = container;
170         // used to determined if the form action needs js validation
171         configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
172             private DefaultConfiguration self = this;
173             public Container getContainer() {
174                 return new Container() {
175                     public <T> T inject(Class<T> implementation) {return null;}
176                     public void removeScopeStrategy() {}
177                     public void setScopeStrategy(Strategy scopeStrategy) {}
178                     public <T> T getInstance(Class<T> type, String name) {return null;}
179                     public <T> T getInstance(Class<T> type) {return null;}
180                     public Set<String> getInstanceNames(Class<?> type) {return null;}
181 
182                     public void inject(Object o) {
183                         cont.inject(o);
184                         if (o instanceof Form) {
185                             ((Form)o).setConfiguration(self);
186                         }
187                     }
188                 };
189             }
190             public RuntimeConfiguration getRuntimeConfiguration() {
191                 return new RuntimeConfiguration() {
192                     public ActionConfig getActionConfig(String namespace, String name) {
193                         ActionConfig actionConfig = new ActionConfig("", name, "") {
194                             public List getInterceptors() {
195                                 List interceptors = new ArrayList();
196 
197                                 ValidationInterceptor validationInterceptor = new ValidationInterceptor();
198                                 validationInterceptor.setIncludeMethods("*");
199 
200                                 InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
201                                 interceptors.add(interceptorMapping);
202 
203                                 return interceptors;
204                             }
205                             public String getClassName() {
206                                 return ActionSupport.class.getName();
207                             }
208                         };
209                         return actionConfig;
210                     }
211 
212                     public Map getActionConfigs() {
213                         return null;
214                     }
215                 };
216             }
217         });
218 
219         FormTag tag = new FormTag();
220         tag.setPageContext(pageContext);
221         tag.setName("myForm");
222         tag.setMethod("post");
223         tag.setAction("myAction");
224         tag.setAcceptcharset("UTF-8");
225         tag.setEnctype("myEncType");
226         tag.setTitle("mytitle");
227         tag.setOnsubmit("submitMe()");
228         tag.setValidate("true");
229         tag.setNamespace("");
230 
231         UpDownSelectTag t = new UpDownSelectTag();
232         t.setPageContext(pageContext);
233         t.setName("myUpDownSelectTag");
234         t.setList("{}");
235 
236         tag.doStartTag();
237         t.doStartTag();
238         t.doEndTag();
239         tag.doEndTag();
240 
241         verify(FormTag.class.getResource("Formtag-2.txt"));
242     }
243 
244 
245     /***
246      * This test with form tag validation enabled. Js validation script will not appear
247      * cause action submited by the form is intercepted by validation interceptor which
248      * "excludes" all methods.
249      */
250     public void testFormWithCustomOnsubmitEnabledWithValidateEnabled2() throws Exception {
251 
252         com.opensymphony.xwork2.config.Configuration originalConfiguration = configurationManager.getConfiguration();
253         ObjectFactory originalObjectFactory = ObjectFactory.getObjectFactory();
254 
255         final Container cont = container;
256         try {
257             // used to determined if the form action needs js validation
258             configurationManager.setConfiguration(new DefaultConfiguration() {
259                 private DefaultConfiguration self = this;
260                 public Container getContainer() {
261                     return new Container() {
262                         public <T> T inject(Class<T> implementation) {return null;}
263                         public void removeScopeStrategy() {}
264                         public void setScopeStrategy(Strategy scopeStrategy) {}
265                         public <T> T getInstance(Class<T> type, String name) {return null;}
266                         public <T> T getInstance(Class<T> type) {return null;}
267                         public Set<String> getInstanceNames(Class<?> type) {return null;}
268 
269                         public void inject(Object o) {
270                             cont.inject(o);
271                             if (o instanceof Form) {
272                                 ((Form)o).setConfiguration(self);
273                             }
274                         }
275                     };
276                 }
277                 public RuntimeConfiguration getRuntimeConfiguration() {
278                     return new RuntimeConfiguration() {
279                         public ActionConfig getActionConfig(String namespace, String name) {
280                             ActionConfig actionConfig = new ActionConfig("", name, "") {
281                                 public List getInterceptors() {
282                                     List interceptors = new ArrayList();
283 
284                                     ValidationInterceptor validationInterceptor = new ValidationInterceptor();
285                                     validationInterceptor.setExcludeMethods("*");
286 
287                                     InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
288                                     interceptors.add(interceptorMapping);
289 
290                                     return interceptors;
291                                 }
292                                 public String getClassName() {
293                                     return ActionSupport.class.getName();
294                                 }
295                             };
296                             return actionConfig;
297                         }
298 
299                         public Map getActionConfigs() {
300                             return null;
301                         }
302                     };
303                 }
304             });
305 
306             FormTag tag = new FormTag();
307             tag.setPageContext(pageContext);
308             tag.setName("myForm");
309             tag.setMethod("post");
310             tag.setAction("myAction");
311             tag.setAcceptcharset("UTF-8");
312             tag.setEnctype("myEncType");
313             tag.setTitle("mytitle");
314             tag.setOnsubmit("submitMe()");
315             tag.setValidate("true");
316             tag.setNamespace("");
317 
318             UpDownSelectTag t = new UpDownSelectTag();
319             t.setPageContext(pageContext);
320             t.setName("myUpDownSelectTag");
321             t.setList("{}");
322 
323             tag.doStartTag();
324             t.doStartTag();
325             t.doEndTag();
326             tag.doEndTag();
327 
328             verify(FormTag.class.getResource("Formtag-11.txt"));
329         }
330         finally {
331             configurationManager.setConfiguration(originalConfiguration);
332         }
333     }
334 
335     /***
336      * Tests the numbers are formatted correctly to not break the javascript
337      */
338     public void testFormWithCustomOnsubmitEnabledWithValidateEnabled3() throws Exception {
339 
340         final Container cont = container;
341         // used to determined if the form action needs js validation
342         configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
343             private DefaultConfiguration self = this;
344             public Container getContainer() {
345                 return new Container() {
346                     public <T> T inject(Class<T> implementation) {return null;}
347                     public void removeScopeStrategy() {}
348                     public void setScopeStrategy(Strategy scopeStrategy) {}
349                     public <T> T getInstance(Class<T> type, String name) {return null;}
350                     public <T> T getInstance(Class<T> type) {return null;}
351                     public Set<String> getInstanceNames(Class<?> type) {return null;}
352 
353                     public void inject(Object o) {
354                         cont.inject(o);
355                         if (o instanceof Form) {
356                             ((Form)o).setConfiguration(self);
357                         }
358                     }
359                 };
360             }
361             public RuntimeConfiguration getRuntimeConfiguration() {
362                 return new RuntimeConfiguration() {
363                     public ActionConfig getActionConfig(String namespace, String name) {
364                         ActionConfig actionConfig = new ActionConfig("", name, IntValidationAction.class.getName()) {
365                             public List getInterceptors() {
366                                 List interceptors = new ArrayList();
367 
368                                 ValidationInterceptor validationInterceptor = new ValidationInterceptor();
369                                 validationInterceptor.setIncludeMethods("*");
370 
371                                 InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
372                                 interceptors.add(interceptorMapping);
373 
374                                 return interceptors;
375                             }
376                             public String getClassName() {
377                                 return IntValidationAction.class.getName();
378                             }
379                         };
380                         return actionConfig;
381                     }
382 
383                     public Map getActionConfigs() {
384                         return null;
385                     }
386                 };
387             }
388         });
389 
390         FormTag tag = new FormTag();
391         tag.setPageContext(pageContext);
392         tag.setName("myForm");
393         tag.setMethod("post");
394         tag.setAction("myAction");
395         tag.setAcceptcharset("UTF-8");
396         tag.setEnctype("myEncType");
397         tag.setTitle("mytitle");
398         tag.setOnsubmit("submitMe()");
399         tag.setValidate("true");
400         tag.setNamespace("");
401 
402         UpDownSelectTag t = new UpDownSelectTag();
403         t.setPageContext(pageContext);
404         t.setName("myUpDownSelectTag");
405         t.setList("{}");
406 
407         tag.doStartTag();
408         tag.getComponent().getParameters().put("actionClass", IntValidationAction.class);
409         t.doStartTag();
410         t.doEndTag();
411         tag.doEndTag();
412 
413         verify(FormTag.class.getResource("Formtag-22.txt"));
414     }
415 
416 /***
417      * Tests the numbers are formatted correctly to not break the javascript, using doubles
418      */
419     public void testFormWithCustomOnsubmitEnabledWithValidateEnabled4() throws Exception {
420 
421         final Container cont = container;
422         // used to determined if the form action needs js validation
423         configurationManager.setConfiguration(new com.opensymphony.xwork2.config.impl.DefaultConfiguration() {
424             private DefaultConfiguration self = this;
425             public Container getContainer() {
426                 return new Container() {
427                     public <T> T inject(Class<T> implementation) {return null;}
428                     public void removeScopeStrategy() {}
429                     public void setScopeStrategy(Strategy scopeStrategy) {}
430                     public <T> T getInstance(Class<T> type, String name) {return null;}
431                     public <T> T getInstance(Class<T> type) {return null;}
432                     public Set<String> getInstanceNames(Class<?> type) {return null;}
433 
434                     public void inject(Object o) {
435                         cont.inject(o);
436                         if (o instanceof Form) {
437                             ((Form)o).setConfiguration(self);
438                         }
439                     }
440                 };
441             }
442             public RuntimeConfiguration getRuntimeConfiguration() {
443                 return new RuntimeConfiguration() {
444                     public ActionConfig getActionConfig(String namespace, String name) {
445                         ActionConfig actionConfig = new ActionConfig("", name, DoubleValidationAction.class.getName()) {
446                             public List getInterceptors() {
447                                 List interceptors = new ArrayList();
448 
449                                 ValidationInterceptor validationInterceptor = new ValidationInterceptor();
450                                 validationInterceptor.setIncludeMethods("*");
451 
452                                 InterceptorMapping interceptorMapping = new InterceptorMapping("validation", validationInterceptor);
453                                 interceptors.add(interceptorMapping);
454 
455                                 return interceptors;
456                             }
457                             public String getClassName() {
458                                 return DoubleValidationAction.class.getName();
459                             }
460                         };
461                         return actionConfig;
462                     }
463 
464                     public Map getActionConfigs() {
465                         return null;
466                     }
467                 };
468             }
469         });
470 
471         FormTag tag = new FormTag();
472         tag.setPageContext(pageContext);
473         tag.setName("myForm");
474         tag.setMethod("post");
475         tag.setAction("myAction");
476         tag.setAcceptcharset("UTF-8");
477         tag.setEnctype("myEncType");
478         tag.setTitle("mytitle");
479         tag.setOnsubmit("submitMe()");
480         tag.setValidate("true");
481         tag.setNamespace("");
482 
483         UpDownSelectTag t = new UpDownSelectTag();
484         t.setPageContext(pageContext);
485         t.setName("myUpDownSelectTag");
486         t.setList("{}");
487 
488         tag.doStartTag();
489         tag.getComponent().getParameters().put("actionClass", DoubleValidationAction.class);
490         t.doStartTag();
491         t.doEndTag();
492         tag.doEndTag();
493 
494         verify(FormTag.class.getResource("Formtag-24.txt"));
495     }
496 
497 
498     /***
499      * This test with form tag validation disabled.
500      */
501     public void testFormWithCustomOnsubmitEnabledWithValidateDisabled() throws Exception {
502         FormTag tag = new FormTag();
503         tag.setPageContext(pageContext);
504         tag.setName("myForm");
505         tag.setMethod("post");
506         tag.setAction("myAction");
507         tag.setEnctype("myEncType");
508         tag.setTitle("mytitle");
509         tag.setOnsubmit("submitMe()");
510         tag.setValidate("false");
511 
512         UpDownSelectTag t = new UpDownSelectTag();
513         t.setPageContext(pageContext);
514         t.setName("myUpDownSelectTag");
515         t.setList("{}");
516 
517         tag.doStartTag();
518         t.doStartTag();
519         t.doEndTag();
520         tag.doEndTag();
521 
522         verify(FormTag.class.getResource("Formtag-6.txt"));
523     }
524 
525 
526     /***
527      * Testing that this: <p>
528      * &lt;a:form name=&quot;'myForm'&quot; namespace=&quot;'/testNamespace'&quot; action=&quot;'testNamespaceAction'&quot; method=&quot;'post'&quot;&gt;
529      * <p/>
530      * doesn't create an action of &quot;/testNamespace/testNamespaceAction.action&quot; when the &quot;struts.action.extension&quot;
531      * config property is set to &quot;jspa&quot;.
532      */
533     public void testFormTagWithDifferentActionExtension() throws Exception {
534         initDispatcher(new HashMap<String,String>(){{ 
535             put(StrutsConstants.STRUTS_ACTION_EXTENSION, "jspa");
536             put("configProviders", TestConfigurationProvider.class.getName());
537         }});
538         request.setupGetServletPath("/testNamespace/testNamespaceAction");
539 
540         FormTag tag = new FormTag();
541         tag.setPageContext(pageContext);
542         tag.setNamespace("/testNamespace");
543         tag.setAction("testNamespaceAction");
544         tag.setMethod("post");
545         tag.setName("myForm");
546 
547         tag.doStartTag();
548         tag.doEndTag();
549 
550         verify(FormTag.class.getResource("Formtag-5.txt"));
551     }
552 
553     /***
554      * Testing that this: <p>
555      * &lt;a:form name=&quot;'myForm'&quot; action=&quot;'/testNamespace/testNamespaceAction.jspa'&quot; method=&quot;'post'&quot;&gt;
556      * <p/>
557      * doesn't create an action of &quot;/testNamespace/testNamespaceAction.action&quot;
558      */
559     public void testFormTagWithDifferentActionExtensionHardcoded() throws Exception {
560         request.setupGetServletPath("/testNamespace/testNamespaceAction");
561 
562         FormTag tag = new FormTag();
563         tag.setPageContext(pageContext);
564         tag.setAction("/testNamespace/testNamespaceAction.jspa");
565         tag.setMethod("post");
566         tag.setName("myForm");
567 
568         tag.doStartTag();
569         tag.doEndTag();
570 
571         verify(FormTag.class.getResource("Formtag-5.txt"));
572     }
573 
574     public void testFormWithNamespaceDefaulting() throws Exception {
575         request.setupGetServletPath("/testNamespace/testNamespaceAction");
576 
577         TestAction testAction = (TestAction) action;
578         testAction.setFoo("bar");
579 
580         FormTag tag = new FormTag();
581         tag.setPageContext(pageContext);
582         tag.setName("myForm");
583         tag.setMethod("post");
584         tag.setAction("testNamespaceAction");
585 
586         tag.doStartTag();
587         tag.doEndTag();
588 
589         verify(FormTag.class.getResource("Formtag-3.txt"));
590     }
591 
592     public void testFormTagForStackOverflowException1() throws Exception {
593         request.setRequestURI("/requestUri");
594 
595         FormTag form1 = new FormTag();
596         form1.setPageContext(pageContext);
597         form1.doStartTag();
598 
599         assertEquals(form1.getComponent().getComponentStack().size(), 1);
600 
601         ActionTag tag = new ActionTag();
602         tag.setPageContext(pageContext);
603         tag.setName("testAction");
604         tag.doStartTag();
605 
606         assertEquals(tag.getComponent().getComponentStack().size(), 2);
607 
608         tag.doEndTag();
609 
610         assertEquals(form1.getComponent().getComponentStack().size(), 1);
611 
612         form1.doEndTag();
613 
614         assertNull(form1.getComponent()); // component is removed after end tag
615     }
616 
617     public void testFormTagForStackOverflowException2() throws Exception {
618         request.setRequestURI("/requestUri");
619 
620         FormTag form1 = new FormTag();
621         form1.setPageContext(pageContext);
622         form1.doStartTag();
623 
624         assertEquals(form1.getComponent().getComponentStack().size(), 1);
625 
626         FormTag form2 = new FormTag();
627         form2.setPageContext(pageContext);
628         form2.doStartTag();
629 
630         assertEquals(form2.getComponent().getComponentStack().size(), 2);
631 
632         ActionTag tag = new ActionTag();
633         tag.setPageContext(pageContext);
634         tag.setName("testAction");
635         tag.doStartTag();
636 
637         assertEquals(tag.getComponent().getComponentStack().size(), 3);
638 
639         tag.doEndTag();
640 
641         assertEquals(form2.getComponent().getComponentStack().size(), 2);
642 
643         form2.doEndTag();
644 
645         assertEquals(form1.getComponent().getComponentStack().size(), 1);
646 
647         form1.doEndTag();
648 
649         assertNull(form1.getComponent()); // component is removed after end tag
650     }
651 
652 
653     public void testFormTagForStackOverflowException3() throws Exception {
654         request.setRequestURI("/requestUri");
655 
656         FormTag form1 = new FormTag();
657         form1.setPageContext(pageContext);
658         form1.doStartTag();
659 
660         assertEquals(form1.getComponent().getComponentStack().size(), 1);
661 
662         FormTag form2 = new FormTag();
663         form2.setPageContext(pageContext);
664         form2.doStartTag();
665 
666         assertEquals(form2.getComponent().getComponentStack().size(), 2);
667 
668         FormTag form3 = new FormTag();
669         form3.setPageContext(pageContext);
670         form3.doStartTag();
671 
672         assertEquals(form3.getComponent().getComponentStack().size(), 3);
673 
674         ActionTag tag = new ActionTag();
675         tag.setPageContext(pageContext);
676         tag.setName("testAction");
677         tag.doStartTag();
678 
679         assertEquals(tag.getComponent().getComponentStack().size(), 4);
680 
681         tag.doEndTag();
682 
683         assertEquals(form3.getComponent().getComponentStack().size(), 3);
684 
685         form3.doEndTag();
686 
687         assertEquals(form2.getComponent().getComponentStack().size(), 2);
688 
689         form2.doEndTag();
690 
691         assertEquals(form1.getComponent().getComponentStack().size(), 1);
692 
693         form1.doEndTag();
694 
695         assertNull(form1.getComponent()); // component is removed after end tag
696     }
697 
698 
699     public void testFormComponentIsRemoved() throws Exception {
700         request.setRequestURI("/requestUri");
701 
702         FormTag form = new FormTag();
703         form.setPageContext(pageContext);
704         form.doStartTag();
705 
706         assertEquals(form.getComponent().getComponentStack().size(), 1);
707 
708         form.doEndTag();
709 
710         assertNull(form.getComponent());
711     }
712 
713 
714     public void testFormWithNoAction() throws Exception {
715         request.setupGetServletPath("/");
716         request.setupGetContextPath("/");
717         request.setRequestURI("/foo.jsp");
718 
719         FormTag tag = new FormTag();
720         tag.setPageContext(pageContext);
721         tag.doStartTag();
722         tag.doEndTag();
723 
724         verify(FormTag.class.getResource("Formtag-4.txt"));
725     }
726 
727     public void testFormWithStaticAction() throws Exception {
728         request.setupGetServletPath("/");
729         request.setupGetContextPath("/");
730         request.setRequestURI("/foo.jsp");
731 
732         FormTag tag = new FormTag();
733         tag.setPageContext(pageContext);
734         tag.setAction("test.html");
735         tag.doStartTag();
736         tag.doEndTag();
737 
738         verify(FormTag.class.getResource("Formtag-7.txt"));
739     }
740 
741     public void testFormWithActionAndExtension() throws Exception {
742         request.setupGetServletPath("/BLA");
743         
744         FormTag tag = new FormTag();
745         tag.setPageContext(pageContext);
746         tag.setAction("/testNamespace/testNamespaceAction.jspa");
747         tag.setMethod("post");
748         tag.setName("myForm");
749 
750         tag.doStartTag();
751         tag.doEndTag();
752 
753         verify(FormTag.class.getResource("Formtag-8.txt"));
754 
755     }
756 
757     @Override
758     protected void setUp() throws Exception {
759         super.setUp();
760         initDispatcher(new HashMap<String,String>(){{ 
761             put("configProviders", TestConfigurationProvider.class.getName());
762         }});
763         ActionContext.getContext().setValueStack(stack);
764 
765         ActionConfig config = new ActionConfig.Builder("", "name", "").build();
766         ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
767         ActionProxy proxy = EasyMock.createNiceMock(ActionProxy.class);
768 
769         EasyMock.expect(invocation.getProxy()).andReturn(proxy).anyTimes();
770         EasyMock.expect(invocation.getAction()).andReturn(null).anyTimes();
771         EasyMock.expect(invocation.invoke()).andReturn(Action.SUCCESS).anyTimes();
772         EasyMock.expect(proxy.getMethod()).andReturn("execute").anyTimes();
773         EasyMock.expect(proxy.getConfig()).andReturn(config).anyTimes();
774 
775 
776         EasyMock.replay(invocation);
777         EasyMock.replay(proxy);
778 
779         ActionContext.getContext().setActionInvocation(invocation);
780     }
781 }