1 // Tags: JDK1.4 |
|
2 // Uses: TestHandler TestSecurityManager |
|
3 |
|
4 // Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch> |
|
5 |
|
6 // This file is part of Mauve. |
|
7 |
|
8 // Mauve is free software; you can redistribute it and/or modify |
|
9 // it under the terms of the GNU General Public License as published by |
|
10 // the Free Software Foundation; either version 2, or (at your option) |
|
11 // any later version. |
|
12 |
|
13 // Mauve is distributed in the hope that it will be useful, |
|
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 // GNU General Public License for more details. |
|
17 |
|
18 // You should have received a copy of the GNU General Public License |
|
19 // along with Mauve; see the file COPYING. If not, write to |
|
20 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 // Boston, MA 02111-1307, USA. |
|
22 |
|
23 package gnu.testlet.java.util.logging.Handler; |
|
24 |
|
25 import gnu.testlet.Testlet; |
|
26 import gnu.testlet.TestHarness; |
|
27 |
|
28 import java.util.logging.Filter; |
|
29 import java.util.logging.LogRecord; |
|
30 |
|
31 |
|
32 /** |
|
33 * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a> |
|
34 */ |
|
35 public class setFilter |
|
36 implements Testlet |
|
37 { |
|
38 private final TestSecurityManager sec = new TestSecurityManager(); |
|
39 |
|
40 private final TestHandler handler = new TestHandler(); |
|
41 |
|
42 private final Filter filter = new Filter() |
|
43 { |
|
44 public boolean isLoggable(LogRecord rec) |
|
45 { |
|
46 return true; |
|
47 } |
|
48 }; |
|
49 |
|
50 public void test(TestHarness th) |
|
51 { |
|
52 Throwable caught; |
|
53 |
|
54 sec.install(); |
|
55 try |
|
56 { |
|
57 // Check #1: setFilter(null) [no permission] |
|
58 sec.setGrantLoggingControl(false); |
|
59 caught = null; |
|
60 try |
|
61 { |
|
62 handler.setFilter(null); |
|
63 } |
|
64 catch (Exception ex) |
|
65 { |
|
66 caught = ex; |
|
67 } |
|
68 th.check(caught instanceof SecurityException); |
|
69 |
|
70 // Check #2: setFilter(null) [with permission] |
|
71 sec.setGrantLoggingControl(true); |
|
72 caught = null; |
|
73 try |
|
74 { |
|
75 handler.setFilter(null); |
|
76 } |
|
77 catch (Exception ex) |
|
78 { |
|
79 caught = ex; |
|
80 } |
|
81 th.check(caught, null); |
|
82 |
|
83 // Check #3: setFilter(f) [no permission] |
|
84 sec.setGrantLoggingControl(false); |
|
85 caught = null; |
|
86 try |
|
87 { |
|
88 handler.setFilter(filter); |
|
89 } |
|
90 catch (Exception ex) |
|
91 { |
|
92 caught = ex; |
|
93 } |
|
94 th.check(caught instanceof SecurityException |
|
95 && handler.getFilter() == null); |
|
96 |
|
97 // Check #4: setFilter(f) [with permission] |
|
98 sec.setGrantLoggingControl(true); |
|
99 caught = null; |
|
100 try |
|
101 { |
|
102 handler.setFilter(filter); |
|
103 } |
|
104 catch (Exception ex) |
|
105 { |
|
106 caught = ex; |
|
107 } |
|
108 th.check(caught == null && handler.getFilter() == filter); |
|
109 } |
|
110 finally |
|
111 { |
|
112 sec.uninstall(); |
|
113 } |
|
114 } |
|
115 } |
|