1 16 17 package org.apache.tester; 18 19 20 import java.io.*; 21 import java.util.Enumeration ; 22 import javax.servlet.*; 23 import javax.servlet.http.*; 24 25 35 36 public class Aggregate01 extends HttpServlet { 37 38 public void doPost(HttpServletRequest request, HttpServletResponse response) 39 throws IOException, ServletException { 40 41 response.setContentType("text/plain"); 42 PrintWriter writer = response.getWriter(); 43 44 StringBuffer errors = new StringBuffer (); 46 String values[] = request.getParameterValues("a"); 47 if (values == null) 48 errors.append(" Received no parameter values for 'a'."); 49 else if (values.length != 2) 50 errors.append(" Received " + values.length + 51 " parameter values for 'a' instead of 2."); 52 else { 53 if (!"1".equals(values[0])) 54 errors.append(" First value for 'a' was '" + values[0] + 55 "' instead of '1'."); 56 if (!"2".equals(values[1])) 57 errors.append(" Second value for 'a' was '" + values[1] + 58 "' instead of '2'."); 59 } 60 values = request.getParameterValues("b"); 61 if (values == null) 62 errors.append(" Received no parameter values for 'b'."); 63 else if (values.length != 1) 64 errors.append(" Received " + values.length + 65 " parameter values for 'b' instead of 1."); 66 else { 67 if (!"3".equals(values[0])) 68 errors.append(" Value for 'b' was '" + values[0] + 69 "' instead of '3'."); 70 } 71 Enumeration names = request.getParameterNames(); 72 while (names.hasMoreElements()) { 73 String name = (String ) names.nextElement(); 74 if ("a".equals(name)) 75 continue; 76 if ("b".equals(name)) 77 continue; 78 errors.append(" Received parameter '" + name + "'."); 79 } 80 81 if (errors.length() < 1) 83 writer.println("Aggregate01 PASSED"); 84 else 85 writer.println("Aggregate01 FAILED -" + errors.toString()); 86 while (true) { 87 String message = StaticLogger.read(); 88 if (message == null) 89 break; 90 writer.println(message); 91 } 92 StaticLogger.reset(); 93 94 } 95 96 } 97 | Popular Tags |