KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tctest > spring > integrationtests > tests > WebFlowSellItemTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4
5 package com.tctest.spring.integrationtests.tests;
6
7 import com.meterware.httpunit.WebConversation;
8 import com.meterware.httpunit.WebResponse;
9 import com.tctest.spring.integrationtests.framework.AbstractTwoServerDeploymentTest;
10 import com.tctest.spring.integrationtests.framework.Deployment;
11 import com.tctest.spring.integrationtests.framework.ServerTestSetup;
12 import com.tctest.spring.integrationtests.framework.WebApplicationServer;
13
14 import java.io.ByteArrayInputStream JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Properties JavaDoc;
20
21 import junit.framework.Test;
22
23
24 /**
25  * Test Spring WebFlow Sellitem test
26  *
27  * LKC-2369: Nested lock exception with TCSpring clustering of sample apps
28  * https://jira.terracotta.lan/jira/browse/LKC-2369
29  */

30 public class WebFlowSellItemTest extends AbstractTwoServerDeploymentTest {
31
32   public static Test suite() {
33     return new WebFlowTestSetup();
34   }
35
36   
37   protected void tearDown() throws Exception JavaDoc {
38     super.tearDown();
39     stopAllWebServers();
40   }
41   
42   public void testSellitem() throws Exception JavaDoc {
43
44     server1.start();
45     server2.start();
46     
47     WebConversation webConversation1 = new WebConversation();
48     // XXX interleave servers when LKC-2369 is fixed
49
executeConversation(webConversation1, server1, server2, server2, server1);
50     
51     // XXX Uncomment when LKC-2369 is fixed
52
WebConversation webConversation2 = new WebConversation();
53     executeConversation(webConversation2, server1, server2, server1, server2);
54     
55   }
56
57   private void executeConversation(WebConversation webConversation1,
58          WebApplicationServer s1, WebApplicationServer s2, WebApplicationServer s3, WebApplicationServer s4) throws Exception JavaDoc {
59     // priceAndItemCountForm.jsp
60
Properties JavaDoc response1 = request(s1, webConversation1, null, null);
61     assertProperty(response1, "form", "priceAndItemCountForm");
62     assertProperty(response1, "flowExecutionKey");
63     assertProperty(response1, "price");
64     assertProperty(response1, "itemCount");
65     
66     String JavaDoc flowExecutionKey2 = response1.getProperty("flowExecutionKey");
67     
68     Map JavaDoc map2 = new HashMap JavaDoc();
69     map2.put("price", "101.5");
70     map2.put("itemCount", "500");
71     map2.put("_eventId_submit", "Next");
72     // categoryForm.jsp
73
Properties JavaDoc response2 = request(s2, webConversation1, flowExecutionKey2, map2);
74     assertProperty(response2, "form", "categoryForm");
75     assertProperty(response2, "flowExecutionKey");
76     assertProperty(response2, "price", "101.5");
77     assertProperty(response2, "itemCount", "500");
78
79     String JavaDoc flowExecutionKey3 = response2.getProperty("flowExecutionKey");
80
81     Map JavaDoc map3 = new HashMap JavaDoc();
82     map3.put("shipping", "true");
83     map3.put("category", "B");
84     map3.put("_eventId_submit", "Next");
85     // shippingDetailsForm.jsp
86
Properties JavaDoc response3 = request(s3, webConversation1, flowExecutionKey3, map3);
87     assertProperty(response3, "form", "shippingDetailsForm");
88     assertProperty(response3, "flowExecutionKey");
89     assertProperty(response2, "price", "101.5");
90     assertProperty(response2, "itemCount", "500");
91     assertProperty(response3, "category", "B");
92     assertProperty(response3, "shipping", "true");
93
94     String JavaDoc flowExecutionKey4 = response3.getProperty("flowExecutionKey");
95     
96     Map JavaDoc map4 = new HashMap JavaDoc();
97     map4.put("_eventId_submit", "Next");
98     map4.put("statusValue", "E");
99     // costOverview
100
Properties JavaDoc response4 = request(s4, webConversation1, flowExecutionKey4, map4);
101     assertProperty(response4, "form", "costOverview");
102     // assertProperty(response4, "flowExecutionKey");
103
assertProperty(response4, "totalCost");
104   }
105   
106   private void assertProperty(Properties JavaDoc properties, String JavaDoc name) {
107     assertNotNull("No properties returned; "+ properties, properties);
108     String JavaDoc value = properties.getProperty(name);
109     assertNotNull("Missing property "+name+"; "+ properties, value);
110     assertTrue("Expecting non-empty "+name+"; "+properties, value.trim().length()>0);
111   }
112
113   private void assertProperty(Properties JavaDoc properties, String JavaDoc name, String JavaDoc expected) {
114     assertNotNull("No properties returned; "+ properties, properties);
115     String JavaDoc value = properties.getProperty(name);
116     assertEquals("Invalid "+name+"; "+properties, expected, value);
117   }
118   
119   private Properties JavaDoc request(WebApplicationServer server, WebConversation conversation, String JavaDoc flowExecutionKey, Map JavaDoc map) throws Exception JavaDoc {
120     String JavaDoc params = "";
121     if(map==null) {
122       params += "_eventId=submit";
123     } else {
124       for (Iterator JavaDoc it = map.entrySet().iterator(); it.hasNext();) {
125         Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
126         params += "&"+entry.getKey()+"="+entry.getValue();
127       }
128     }
129     if(flowExecutionKey!=null) {
130       params += "&_flowExecutionKey="+flowExecutionKey.trim();
131     } else {
132       params += "&_flowId=sellitem";
133     }
134     
135     WebResponse response = server.ping("/sellitem/pos.htm?"+params, conversation);
136     
137     Properties JavaDoc properties = new Properties JavaDoc();
138     properties.load(new ByteArrayInputStream JavaDoc(response.getText().getBytes("ASCII")));
139     logger.info("*** "+properties);
140     return properties;
141   }
142
143
144   private static class WebFlowTestSetup extends ServerTestSetup {
145
146     public WebFlowTestSetup() {
147       super(WebFlowSellItemTest.class);
148     }
149
150     protected void setUp() throws Exception JavaDoc {
151       super.setUp();
152
153       Deployment deployment2 = makeDeploymentBuilder("sellitem.war")
154           .addDirectoryOrJARContainingClass(WebFlowTestSetup.class)
155           .addDirectoryContainingResource("/tc-config-files/sellitem-tc-config.xml")
156           .addDirectoryContainingResource("/com/tctest/spring/sellitem-ctx.xml")
157           
158           .addDirectoryOrJARContainingClass(org.apache.taglibs.standard.Version.class) // standard-1.0.6.jar
159
.addDirectoryOrJARContainingClass(javax.servlet.jsp.jstl.core.Config.class) // jstl-1.0.jar
160
// .addDirectoryOrJARContainingClass(org.springframework.webflow.registry.XmlFlowRegistryFactoryBean.class) // spring-webflow-1.0-rc3.jar
161
.addDirectoryOrJARContainingClass(org.springframework.webflow.engine.builder.xml.XmlFlowRegistryFactoryBean.class) // spring-webflow-1.0-rc4.jar
162
.addDirectoryOrJARContainingClass(org.springframework.binding.convert.Converter.class) // spring-binding-1.0-rc3.jar
163
.addDirectoryOrJARContainingClass(org.apache.commons.codec.StringDecoder.class) // commons-codec-1.3.jar
164
.addDirectoryOrJARContainingClass(ognl.Ognl.class) // ognl-2.7.jar
165
.addDirectoryOrJARContainingClass(EDU.oswego.cs.dl.util.concurrent.ReentrantLock.class) // concurrent-1.3.4.jar for SWF on jdk1.4
166

167           .addDirectoryOrJARContainingClass(org.hsqldb.jdbcDriver.class) // hsqldb*.jar
168

169           .addResource("/web-resources/sellitem", "categoryForm.jsp", "WEB-INF/jsp")
170           .addResource("/web-resources/sellitem", "costOverview.jsp", "WEB-INF/jsp")
171           .addResource("/web-resources/sellitem", "error.jsp", "WEB-INF/jsp")
172           .addResource("/web-resources/sellitem", "includeTop.jsp", "WEB-INF/jsp")
173           .addResource("/web-resources/sellitem", "priceAndItemCountForm.jsp", "WEB-INF/jsp")
174           .addResource("/web-resources/sellitem", "shippingDetailsForm.jsp", "WEB-INF/jsp")
175           .addResource("/web-resources", "weblogic.xml", "/WEB-INF")
176           
177           .addResource("/com/tctest/spring", "sellitem.xml", "WEB-INF")
178           .addResource("/com/tctest/spring", "sellitem-shipping.xml", "WEB-INF")
179           .addResource("/com/tctest/spring", "sellitem-beans.xml", "WEB-INF")
180           .addResource("/com/tctest/spring", "sellitem-servlet.xml", "WEB-INF")
181           
182           .addServlet("sellitem", "*.htm", org.springframework.web.servlet.DispatcherServlet.class,
183               Collections.singletonMap("contextConfigLocation",
184                   "/WEB-INF/sellitem-servlet.xml\n" +
185                   "classpath:com/tctest/spring/sellitem-ctx.xml"), true)
186           .makeDeployment();
187       
188       server1 = createServer(deployment2);
189       server2 = createServer(deployment2);
190     }
191
192     private WebApplicationServer createServer(Deployment deployment) throws Exception JavaDoc {
193       return sm.makeWebApplicationServer("/tc-config-files/sellitem-tc-config.xml")
194           .addWarDeployment(deployment, "sellitem");
195     }
196     
197   }
198
199 }
200
201
Popular Tags