01: /* Copyright 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.intercept.web;
17:
18: import java.util.ArrayList;
19: import java.util.Iterator;
20: import java.util.List;
21:
22: import org.acegisecurity.ConfigAttributeDefinition;
23: import org.acegisecurity.SecurityConfig;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * Test for {@link FilterInvocationDefinitionDecorator}
29: *
30: * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
31: * @version $Id: FilterInvocationDefinitionDecoratorTest.java 1570 2006-07-06 17:05:08Z carlossg $
32: */
33: public class FilterInvocationDefinitionDecoratorTest extends TestCase {
34:
35: private FilterInvocationDefinitionDecorator decorator;
36:
37: private FilterInvocationDefinition decorated;
38:
39: protected void setUp() throws Exception {
40: super .setUp();
41: decorated = new MockFilterInvocationDefinition();
42: decorator = new FilterInvocationDefinitionDecorator(decorated);
43: }
44:
45: public void testFilterInvocationDefinitionMapDecorator() {
46: decorator = new FilterInvocationDefinitionDecorator();
47: decorator.setDecorated(decorated);
48: assertEquals(decorated, decorator.getDecorated());
49: }
50:
51: public void testSetMappings() {
52: List roles = new ArrayList();
53: roles.add("ROLE_USER");
54: roles.add("ROLE_ADMIN");
55:
56: FilterInvocationDefinitionSourceMapping mapping = new FilterInvocationDefinitionSourceMapping();
57: mapping.setUrl("/secure/**");
58: mapping.setConfigAttributes(roles);
59:
60: List mappings = new ArrayList();
61: mappings.add(mapping);
62:
63: decorator.setMappings(mappings);
64:
65: ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
66: Iterator it = roles.iterator();
67: while (it.hasNext()) {
68: String role = (String) it.next();
69: configDefinition
70: .addConfigAttribute(new SecurityConfig(role));
71: }
72:
73: it = decorator.getConfigAttributeDefinitions();
74: int i = 0;
75: while (it.hasNext()) {
76: i++;
77: assertEquals(configDefinition, it.next());
78: }
79: assertEquals(1, i);
80:
81: assertEquals(mappings, decorator.getMappings());
82: }
83: }
|