1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 40 41 public class Aggregate02 extends HttpServlet { 42 43 public void doPost(HttpServletRequest request, HttpServletResponse response) 44 throws IOException, ServletException { 45 46 response.setContentType("text/plain"); 47 PrintWriter writer = response.getWriter(); 48 49 StringBuffer errors = new StringBuffer (); 51 Map map = request.getParameterMap(); 52 if (map == null) { 53 errors.append(" No parameter map returned."); 54 map = new HashMap (); 55 } 56 String values[] = (String []) map.get("a"); 57 if (values == null) 58 errors.append(" Received no parameter values for 'a'."); 59 else if (values.length != 2) 60 errors.append(" Received " + values.length + 61 " parameter values for 'a' instead of 2."); 62 else { 63 if (!"1".equals(values[0])) 64 errors.append(" First value for 'a' was '" + values[0] + 65 "' instead of '1'."); 66 if (!"2".equals(values[1])) 67 errors.append(" Second value for 'a' was '" + values[1] + 68 "' instead of '2'."); 69 } 70 values = (String []) map.get("b"); 71 if (values == null) 72 errors.append(" Received no parameter values for 'b'."); 73 else if (values.length != 1) 74 errors.append(" Received " + values.length + 75 " parameter values for 'b' instead of 1."); 76 else { 77 if (!"3".equals(values[0])) 78 errors.append(" Value for 'b' was '" + values[0] + 79 "' instead of '3'."); 80 } 81 Iterator names = map.keySet().iterator(); 82 while (names.hasNext()) { 83 String name = (String ) names.next(); 84 if ("a".equals(name)) 85 continue; 86 if ("b".equals(name)) 87 continue; 88 errors.append(" Received parameter '" + name + "'."); 89 } 90 91 if (errors.length() < 1) 93 writer.println("Aggregate02 PASSED"); 94 else 95 writer.println("Aggregate02 FAILED -" + errors.toString()); 96 while (true) { 97 String message = StaticLogger.read(); 98 if (message == null) 99 break; 100 writer.println(message); 101 } 102 StaticLogger.reset(); 103 104 } 105 106 } 107 | Popular Tags |