001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.tomcat.cluster;
021:
022: import java.io.IOException;
023:
024: import javax.servlet.ServletException;
025:
026: import org.apache.catalina.Valve;
027: import org.apache.catalina.connector.Request;
028: import org.apache.catalina.connector.Response;
029: import org.apache.geronimo.clustering.ClusteredInvocation;
030: import org.apache.geronimo.clustering.ClusteredInvocationException;
031:
032: import com.agical.rmock.extension.junit.RMockTestCase;
033:
034: /**
035: *
036: * @version $Rev:$ $Date:$
037: */
038: public class AnAbstractClusteredValveTest extends RMockTestCase {
039:
040: private AbstractClusteredValve valve;
041: private Request request;
042: private Response response;
043: private Valve nextValve;
044:
045: @Override
046: protected void setUp() throws Exception {
047: valve = new AbstractClusteredValve() {
048: @Override
049: protected ClusteredInvocation newClusteredInvocation(
050: Request request, Response response) {
051: return new WebClusteredInvocation(request, response) {
052: public void invoke()
053: throws ClusteredInvocationException {
054: invokeLocally();
055: }
056: };
057: }
058: };
059:
060: nextValve = (Valve) mock(Valve.class);
061: valve.setNext(nextValve);
062:
063: request = new Request();
064: response = new Response();
065: }
066:
067: public void testSuccessfulInvocation() throws Exception {
068: nextValve.invoke(request, response);
069:
070: startVerification();
071:
072: valve.invoke(request, response);
073: }
074:
075: public void testIOEIsUnwrapped() throws Exception {
076: nextValve.invoke(request, response);
077: IOException expected = new IOException();
078: modify().throwException(expected);
079:
080: startVerification();
081:
082: try {
083: valve.invoke(request, response);
084: } catch (IOException e) {
085: assertSame(expected, e);
086: }
087: }
088:
089: public void testSEIsUnwrapped() throws Exception {
090: nextValve.invoke(request, response);
091: ServletException expected = new ServletException();
092: modify().throwException(expected);
093:
094: startVerification();
095:
096: try {
097: valve.invoke(request, response);
098: } catch (ServletException e) {
099: assertSame(expected, e);
100: }
101: }
102:
103: public void testCIEIsWrappedAsIOE() throws Exception {
104: final ClusteredInvocationException expected = new ClusteredInvocationException();
105: valve = new AbstractClusteredValve() {
106: @Override
107: protected ClusteredInvocation newClusteredInvocation(
108: Request request, Response response) {
109: return new WebClusteredInvocation(request, response) {
110: public void invoke()
111: throws ClusteredInvocationException {
112: throw expected;
113: }
114: };
115: }
116: };
117:
118: startVerification();
119:
120: try {
121: valve.invoke(request, response);
122: } catch (IOException e) {
123: assertSame(expected, e.getCause());
124: }
125: }
126:
127: }
|