1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.phoenix.common;
19
20 import java.net.InetAddress;
21 import java.net.UnknownHostException;
22 import java.security.AccessControlException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import junit.framework.TestCase;
26 import net.jini.export.ServerContext;
27 import net.jini.io.context.ClientHost;
28 import org.apache.river.resource.ServiceConfigurationError;
29
30 public class LocalAccessTest extends TestCase {
31
32 public void testNoServerContext() {
33 try {
34 LocalAccess.check();
35 } catch(AccessControlException e) {
36 fail("unexpected: " + e);
37 } catch(ServiceConfigurationError e){
38
39 }
40 }
41
42 public void testNoClientHost() {
43 ServerContext.doWithServerContext(new Runnable() {
44 public void run() {
45 try {
46 LocalAccess.check();
47 }
48 catch(AccessControlException e) {
49 fail("unexpected: " + e);
50 }
51 }
52 }, new ArrayList(0));
53
54 }
55
56 public void testLocalClientHost() throws UnknownHostException {
57 Collection col = new ArrayList(1);
58 col.add(new ClientHost() {
59 public InetAddress getClientHost() {
60 try {
61 return InetAddress.getLocalHost();
62 }
63 catch(UnknownHostException e) {
64 return null;
65 }
66 }
67 });
68 ServerContext.doWithServerContext(new Runnable() {
69 public void run() {
70 try {
71 LocalAccess.check();
72 }
73 catch(AccessControlException e) {
74 fail("unexpected: " + e);
75 }
76 }
77 }, col);
78 }
79
80 public void testLoopBackClientHost() {
81 Collection col = new ArrayList(1);
82 col.add(new ClientHost() {
83 public InetAddress getClientHost() {
84 try {
85 return InetAddress.getByName("127.0.1.1");
86 }
87 catch(UnknownHostException e) {
88 return null;
89 }
90 }
91 });
92 ServerContext.doWithServerContext(new Runnable() {
93 public void run() {
94 try {
95 LocalAccess.check();
96 }
97 catch(AccessControlException e) {
98 fail("unexpected: " + e);
99 }
100 }
101 }, col);
102
103 }
104
105 public void testRemoteClientHost() {
106 Collection col = new ArrayList(1);
107 col.add(new ClientHost() {
108 public InetAddress getClientHost() {
109 try {
110 return InetAddress.getByName("www.apache.org");
111 }
112 catch(UnknownHostException e) {
113 return null;
114 }
115 }
116 });
117 ServerContext.doWithServerContext(new Runnable() {
118 public void run() {
119 try {
120 LocalAccess.check();
121 }
122 catch(AccessControlException e) {
123 return;
124 }
125 fail("expected AccessControlException not thrown");
126 }
127 }, col);
128
129 }
130
131 }