KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > controller > DispatcherTest


1 package com.tonbeller.wcf.controller;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import junit.framework.TestCase;
7
8 /**
9  */

10
11 public class DispatcherTest extends TestCase {
12
13   DispatcherSupport disp;
14   int count;
15
16   class MyListener implements RequestListener {
17     public void request(RequestContext context) {
18       ++ count;
19     }
20   }
21
22   public DispatcherTest(String JavaDoc name) {
23     super(name);
24   }
25   public static void main(String JavaDoc[] args) {
26     junit.textui.TestRunner.run(DispatcherTest.class);
27   }
28
29   public void setUp() {
30     disp = new DispatcherSupport();
31     count = 0;
32   }
33
34   public void testLookup() throws Exception JavaDoc {
35     disp.addRequestListener("name1", "value1", new MyListener());
36     disp.addRequestListener(null, "value2", new MyListener());
37     disp.addRequestListener("name3", null, new MyListener());
38     disp.addRequestListener(null, null, new MyListener());
39     disp.addRequestListener("name5", null, new MyListener());
40
41     check("name1", "value1", 2);
42     check("xxx", "value2", 2);
43     check("name3", "xxx", 2);
44     check("xxx", "xxx", 1);
45     check("name5", "123", 2);
46     // image button support: default listener and name5 listener will fire.
47
check("name5.x", "123", 2);
48   }
49
50   private void check(String JavaDoc name, String JavaDoc value, int size) {
51     Map JavaDoc map = new HashMap JavaDoc();
52     map.put(name, new String JavaDoc[]{value});
53     assertEquals(size, disp.findAll(map).size());
54   }
55 }
Popular Tags