KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > security > jacc > WebUserDataPermissionTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 //
19
// This source code implements specifications defined by the Java
20
// Community Process. In order to remain compliant with the specification
21
// DO NOT add / change / or delete method signatures!
22
//
23

24 package javax.security.jacc;
25
26 import java.io.ByteArrayOutputStream;
27 import java.io.ObjectOutputStream;
28 import java.io.ByteArrayInputStream;
29 import java.io.ObjectInputStream;
30 import java.io.IOException;
31
32 import junit.framework.TestCase;
33
34 /**
35  *
36  * @version $Rev: 106621 $ $Date: 2004-11-25 14:55:22 -0800 (Thu, 25 Nov 2004) $
37  */

38 public class WebUserDataPermissionTest extends TestCase {
39
40     /*
41      * Testing WebResourcePermission(java.lang.String, java.lang.String)
42      */

43     public void testConstructorStringString() {
44
45         WebUserDataPermission permission = new WebUserDataPermission("/foo", "GET,POST:INTEGRAL");
46
47         assertEquals(permission.getName(), "/foo");
48         assertEquals(permission.getActions(), "GET,POST:INTEGRAL");
49         
50         permission = new WebUserDataPermission("/foo", "GET,POST,POST,GET:INTEGRAL");
51         assertEquals(permission.getActions(), "GET,POST:INTEGRAL");
52
53         // bad HTTP method
54
try {
55             permission = new WebUserDataPermission("/foo", "GET,POST,BAR:INTEGRAL");
56             fail("Bad HTTP method");
57         } catch(IllegalArgumentException iae) {
58         }
59
60         // If you have a colon, then you must have a transportType
61
try {
62             permission = new WebUserDataPermission("/foo", "GET,POST,BAR:");
63             fail("Missing transportType");
64         } catch(IllegalArgumentException iae) {
65         }
66     }
67
68     public void testSerialization() throws Exception {
69         testSerialization(new WebUserDataPermission("/foo", "GET,POST:INTEGRAL"));
70         testSerialization(new WebUserDataPermission("/foo", "GET,POST:NONE"));
71         testSerialization(new WebUserDataPermission("/foo", ""));
72         testSerialization(new WebUserDataPermission("/foo", ":NONE"));
73         testSerialization(new WebUserDataPermission("/foo", "GET,POST"));
74     }
75
76     private void testSerialization(WebUserDataPermission permission) throws IOException, ClassNotFoundException {
77         ByteArrayOutputStream baos = new ByteArrayOutputStream();
78         ObjectOutputStream oos = new ObjectOutputStream(baos);
79         oos.writeObject(permission);
80         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
81         ObjectInputStream ois = new ObjectInputStream(bais);
82         Object o = ois.readObject();
83         assertEquals(permission, o);
84     }
85
86     public void testImpliesStringString() {
87         // An actions string without a transportType is a shorthand for a
88
// actions string with the value "NONE" as its TransportType
89
WebUserDataPermission permissionFooGP = new WebUserDataPermission("/foo", "GET,POST:INTEGRAL");
90         WebUserDataPermission permissionFooE = new WebUserDataPermission("/foo", "");
91         WebUserDataPermission permissionFooGPN = new WebUserDataPermission("/foo", "GET,POST");
92         
93         assertTrue(permissionFooE.implies(permissionFooGP));
94         assertTrue(permissionFooE.implies(permissionFooGPN));
95         assertFalse(permissionFooGP.implies(permissionFooE));
96         assertFalse(permissionFooGPN.implies(permissionFooE));
97
98         assertTrue(permissionFooGPN.implies(permissionFooGP));
99         assertFalse(permissionFooGP.implies(permissionFooGPN));
100     }
101
102     /*
103      * Testing WebResourcePermission(String, String[])
104      */

105     public void testConstructorStringStringArray() {
106     }
107     
108     public void testImpliesStringStringArray() {
109     }
110
111     /*
112      * Testing WebResourcePermission(HttpServletRequest)
113      */

114     public void testConstructorHttpServletRequest() {
115     }
116     
117     public void testImpliesHttpServletRequest() {
118     }
119 }
120
121
Popular Tags