1 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 ; 15 import java.util.Collections ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import java.util.Map ; 19 import java.util.Properties ; 20 21 import junit.framework.Test; 22 23 24 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 { 38 super.tearDown(); 39 stopAllWebServers(); 40 } 41 42 public void testSellitem() throws Exception { 43 44 server1.start(); 45 server2.start(); 46 47 WebConversation webConversation1 = new WebConversation(); 48 executeConversation(webConversation1, server1, server2, server2, server1); 50 51 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 { 59 Properties 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 flowExecutionKey2 = response1.getProperty("flowExecutionKey"); 67 68 Map map2 = new HashMap (); 69 map2.put("price", "101.5"); 70 map2.put("itemCount", "500"); 71 map2.put("_eventId_submit", "Next"); 72 Properties 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 flowExecutionKey3 = response2.getProperty("flowExecutionKey"); 80 81 Map map3 = new HashMap (); 82 map3.put("shipping", "true"); 83 map3.put("category", "B"); 84 map3.put("_eventId_submit", "Next"); 85 Properties 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 flowExecutionKey4 = response3.getProperty("flowExecutionKey"); 95 96 Map map4 = new HashMap (); 97 map4.put("_eventId_submit", "Next"); 98 map4.put("statusValue", "E"); 99 Properties response4 = request(s4, webConversation1, flowExecutionKey4, map4); 101 assertProperty(response4, "form", "costOverview"); 102 assertProperty(response4, "totalCost"); 104 } 105 106 private void assertProperty(Properties properties, String name) { 107 assertNotNull("No properties returned; "+ properties, properties); 108 String 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 properties, String name, String expected) { 114 assertNotNull("No properties returned; "+ properties, properties); 115 String value = properties.getProperty(name); 116 assertEquals("Invalid "+name+"; "+properties, expected, value); 117 } 118 119 private Properties request(WebApplicationServer server, WebConversation conversation, String flowExecutionKey, Map map) throws Exception { 120 String params = ""; 121 if(map==null) { 122 params += "_eventId=submit"; 123 } else { 124 for (Iterator it = map.entrySet().iterator(); it.hasNext();) { 125 Map.Entry entry = (Map.Entry ) 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 properties = new Properties (); 138 properties.load(new ByteArrayInputStream (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 { 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) .addDirectoryOrJARContainingClass(javax.servlet.jsp.jstl.core.Config.class) .addDirectoryOrJARContainingClass(org.springframework.webflow.engine.builder.xml.XmlFlowRegistryFactoryBean.class) .addDirectoryOrJARContainingClass(org.springframework.binding.convert.Converter.class) .addDirectoryOrJARContainingClass(org.apache.commons.codec.StringDecoder.class) .addDirectoryOrJARContainingClass(ognl.Ognl.class) .addDirectoryOrJARContainingClass(EDU.oswego.cs.dl.util.concurrent.ReentrantLock.class) 167 .addDirectoryOrJARContainingClass(org.hsqldb.jdbcDriver.class) 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 { 193 return sm.makeWebApplicationServer("/tc-config-files/sellitem-tc-config.xml") 194 .addWarDeployment(deployment, "sellitem"); 195 } 196 197 } 198 199 } 200 201 | Popular Tags |