KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > dispatcher > DefautActionMapperTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 /*
6  * Created on 2/10/2003
7  *
8  */

9 package com.opensymphony.webwork.dispatcher;
10
11 import com.mockobjects.servlet.MockHttpServletRequest;
12 import com.opensymphony.webwork.WebWorkTestCase;
13 import com.opensymphony.webwork.dispatcher.mapper.ActionMapping;
14 import com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper;
15
16 import java.util.HashMap JavaDoc;
17
18
19 /**
20  * @author roughley
21  */

22 public class DefautActionMapperTest extends WebWorkTestCase {
23     public void testGetMapping() throws Exception JavaDoc {
24         MockHttpServletRequest req = new MockHttpServletRequest();
25         req.setupGetParameterMap(new HashMap JavaDoc());
26         req.setupGetRequestURI("/my/namespace/actionName.action");
27         req.setupGetServletPath("/my/namespace/actionName.action");
28         req.setupGetAttribute(null);
29         req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");
30
31         DefaultActionMapper mapper = new DefaultActionMapper();
32         ActionMapping mapping = mapper.getMapping(req);
33
34         assertEquals("/my/namespace", mapping.getNamespace());
35         assertEquals("actionName", mapping.getName());
36         assertNull(mapping.getMethod());
37     }
38
39     public void testGetMappingWithMethod() throws Exception JavaDoc {
40         MockHttpServletRequest req = new MockHttpServletRequest();
41         req.setupGetParameterMap(new HashMap JavaDoc());
42         req.setupGetRequestURI("/my/namespace/actionName!add.action");
43         req.setupGetServletPath("/my/namespace/actionName!add.action");
44         req.setupGetAttribute(null);
45         req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");
46
47         DefaultActionMapper mapper = new DefaultActionMapper();
48         ActionMapping mapping = mapper.getMapping(req);
49
50         assertEquals("/my/namespace", mapping.getNamespace());
51         assertEquals("actionName", mapping.getName());
52         assertEquals("add", mapping.getMethod());
53     }
54
55     public void testGetUri() throws Exception JavaDoc {
56         MockHttpServletRequest req = new MockHttpServletRequest();
57         req.setupGetParameterMap(new HashMap JavaDoc());
58         req.setupGetRequestURI("/my/namespace/actionName.action");
59         req.setupGetServletPath("/my/namespace/actionName.action");
60         req.setupGetAttribute(null);
61         req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");
62
63         DefaultActionMapper mapper = new DefaultActionMapper();
64         ActionMapping mapping = mapper.getMapping(req);
65         assertEquals("/my/namespace/actionName.action", mapper.getUriFromActionMapping(mapping));
66     }
67
68     public void testGetUriWithMethod() throws Exception JavaDoc {
69         MockHttpServletRequest req = new MockHttpServletRequest();
70         req.setupGetParameterMap(new HashMap JavaDoc());
71         req.setupGetRequestURI("/my/namespace/actionName!add.action");
72         req.setupGetServletPath("/my/namespace/actionName!add.action");
73         req.setupGetAttribute(null);
74         req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");
75
76         DefaultActionMapper mapper = new DefaultActionMapper();
77         ActionMapping mapping = mapper.getMapping(req);
78
79         assertEquals("/my/namespace/actionName!add.action", mapper.getUriFromActionMapping(mapping));
80     }
81 }
82
Popular Tags