ParseCommonLog extends UnaryFunction<String, HttpRequest> { public static Map<String,String> queryToMap(String query, Method m) { Map<String,String> out = new HashMap<String,String>(); if (query == null) return out; String[] pairs = query.split("&"); if (pairs.length == 1 && pairs[0].indexOf("=") < 0) { if (m == Method.GET) { out.put(pairs[0], ""); } else { out.put("", pairs[0]); } } else { for (String pair : pairs) { String[] av = pair.split("="); String att = av[0]; String val; if (av.length > 1) val = av[1]; else val = ""; out.put(att, val); } } return out; } ParseCommonLog(); @Override HttpRequest getValue(String log_line); static long parseTime(Calendar calendar, String time_string); static int stringToMonth(String m); static Map<String,String> queryToMap(String query, Method m); static final String methodToString(HttpRequest.Method m); static Method stringToMethod(String s); static Map<String,String> parseParameters(String param_string); static final ParseCommonLog instance; }
@Test public void testArguments1() { Map<String,String> args = ParseCommonLog.queryToMap("", HttpRequest.Method.GET); assertEquals(1, args.size()); assertEquals("", args.get("")); }
@Test public void testArguments2() { Map<String,String> args = ParseCommonLog.queryToMap("abc", HttpRequest.Method.GET); assertEquals(1, args.size()); assertEquals("", args.get("abc")); }
@Test public void testArguments3() { Map<String,String> args = ParseCommonLog.queryToMap("abc=def", HttpRequest.Method.GET); assertEquals(1, args.size()); assertEquals("def", args.get("abc")); }
@Test public void testArguments4() { Map<String,String> args = ParseCommonLog.queryToMap("abc=def&foo", HttpRequest.Method.GET); assertEquals(2, args.size()); assertEquals("def", args.get("abc")); assertEquals("", args.get("foo")); }
@Test public void testArguments5() { Map<String,String> args = ParseCommonLog.queryToMap("foo&abc=def", HttpRequest.Method.GET); assertEquals(2, args.size()); assertEquals("def", args.get("abc")); assertEquals("", args.get("foo")); }