001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity.intercept.web;
017:
018: import junit.framework.TestCase;
019:
020: import org.springframework.mock.web.MockHttpServletRequest;
021: import org.springframework.mock.web.MockHttpServletResponse;
022:
023: import java.io.IOException;
024:
025: import javax.servlet.FilterChain;
026: import javax.servlet.ServletException;
027: import javax.servlet.ServletRequest;
028: import javax.servlet.ServletResponse;
029:
030: /**
031: * Tests {@link AbstractFilterInvocationDefinitionSource}.
032: *
033: * @author Ben Alex
034: * @version $Id: AbstractFilterInvocationDefinitionSourceTests.java 1496 2006-05-23 13:38:33Z benalex $
035: */
036: public class AbstractFilterInvocationDefinitionSourceTests extends
037: TestCase {
038: //~ Constructors ===================================================================================================
039:
040: public AbstractFilterInvocationDefinitionSourceTests() {
041: super ();
042: }
043:
044: public AbstractFilterInvocationDefinitionSourceTests(String arg0) {
045: super (arg0);
046: }
047:
048: //~ Methods ========================================================================================================
049:
050: public static void main(String[] args) {
051: junit.textui.TestRunner
052: .run(AbstractFilterInvocationDefinitionSourceTests.class);
053: }
054:
055: public final void setUp() throws Exception {
056: super .setUp();
057: }
058:
059: public void testDoesNotSupportAnotherObject() {
060: MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(
061: false, true);
062: assertFalse(mfis.supports(String.class));
063: }
064:
065: public void testGetAttributesForANonFilterInvocation() {
066: MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(
067: false, true);
068:
069: try {
070: mfis.getAttributes(new String());
071: fail("Should have thrown IllegalArgumentException");
072: } catch (IllegalArgumentException expected) {
073: assertTrue(true);
074: }
075: }
076:
077: public void testGetAttributesForANullObject() {
078: MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(
079: false, true);
080:
081: try {
082: mfis.getAttributes(null);
083: fail("Should have thrown IllegalArgumentException");
084: } catch (IllegalArgumentException expected) {
085: assertTrue(true);
086: }
087: }
088:
089: public void testGetAttributesForFilterInvocationSuccess() {
090: MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(
091: false, true);
092:
093: try {
094: mfis.getAttributes(new FilterInvocation(
095: new MockHttpServletRequest(null, null),
096: new MockHttpServletResponse(),
097: new MockFilterChain()));
098: fail("Should have thrown UnsupportedOperationException");
099: } catch (UnsupportedOperationException expected) {
100: assertTrue(true);
101: }
102: }
103:
104: public void testSupportsFilterInvocation() {
105: MockFilterInvocationDefinitionSource mfis = new MockFilterInvocationDefinitionSource(
106: false, true);
107: assertTrue(mfis.supports(FilterInvocation.class));
108: }
109:
110: //~ Inner Classes ==================================================================================================
111:
112: private class MockFilterChain implements FilterChain {
113: public void doFilter(ServletRequest arg0, ServletResponse arg1)
114: throws IOException, ServletException {
115: throw new UnsupportedOperationException(
116: "mock method not implemented");
117: }
118: }
119: }
|