1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jdkim;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.james.jdkim.api.PublicKeyRecordRetriever;
27 import org.apache.james.jdkim.exceptions.FailException;
28 import org.apache.james.jdkim.exceptions.PermFailException;
29 import org.apache.james.jdkim.exceptions.TempFailException;
30 import org.apache.james.jdkim.impl.MultiplexingPublicKeyRecordRetriever;
31
32 import junit.framework.TestCase;
33
34 public class MultiplexingPublicKeyRecordRetrieverTest extends TestCase {
35
36 private PublicKeyRecordRetriever myMethodRetriever = new PublicKeyRecordRetriever() {
37
38 public List getRecords(CharSequence methodAndOption,
39 CharSequence selector, CharSequence token)
40 throws TempFailException, PermFailException {
41 List l = new ArrayList();
42 l.add(selector.toString());
43 l.add(token.toString());
44 return l;
45 }
46
47 };
48
49 public void testMultiplexingPublicKeyRecordRetriever() {
50 MultiplexingPublicKeyRecordRetriever pkrr = new MultiplexingPublicKeyRecordRetriever();
51 try {
52 pkrr.getRecords("method", "selector", "token");
53 fail("method is unknown");
54 } catch (FailException e) {
55 }
56 }
57
58 public void testMultiplexingPublicKeyRecordRetrieverStringPublicKeyRecordRetriever()
59 throws TempFailException, PermFailException {
60 MultiplexingPublicKeyRecordRetriever pkrr = new MultiplexingPublicKeyRecordRetriever(
61 "mymethod", myMethodRetriever);
62 check(pkrr, "mymethod");
63 }
64
65 private void check(MultiplexingPublicKeyRecordRetriever pkrr, String method)
66 throws TempFailException, PermFailException {
67 List l = pkrr.getRecords(method, "selector", "token");
68 Iterator i = l.iterator();
69 assertEquals("selector", i.next());
70 assertEquals("token", i.next());
71 try {
72 l = pkrr.getRecords("anothermethod", "selector", "token");
73 fail("anothermethod is not declared");
74 } catch (FailException e) {
75 }
76 }
77
78 public void testAddRetriever() throws TempFailException, PermFailException {
79 MultiplexingPublicKeyRecordRetriever pkrr = new MultiplexingPublicKeyRecordRetriever();
80 pkrr.addRetriever("mymethod", myMethodRetriever);
81 check(pkrr, "mymethod");
82 }
83
84 public void testAddRetrieverWithOptions() throws TempFailException,
85 PermFailException {
86 MultiplexingPublicKeyRecordRetriever pkrr = new MultiplexingPublicKeyRecordRetriever();
87 pkrr.addRetriever("mymethod", myMethodRetriever);
88 check(pkrr, "mymethod/option");
89 }
90
91 }