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.clustering.wadi;
021:
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import org.codehaus.wadi.core.session.Session;
026:
027: import com.agical.rmock.extension.junit.RMockTestCase;
028:
029: import junit.framework.TestCase;
030:
031: /**
032: *
033: * @version $Rev:$ $Date:$
034: */
035: public class WADISessionAdaptorTest extends RMockTestCase {
036:
037: private Session session;
038:
039: @Override
040: protected void setUp() throws Exception {
041: session = (Session) mock(Session.class);
042: session.getLocalStateMap();
043: modify().multiplicity(expect.from(0))
044: .returnValue(new HashMap());
045: }
046:
047: public void testGetSessionIdDelegation() throws Exception {
048: session.getName();
049: String name = "name";
050: modify().returnValue(name);
051:
052: startVerification();
053:
054: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
055: assertEquals(name, adaptor.getSessionId());
056: }
057:
058: public void testReleaseDelegation() throws Exception {
059: session.destroy();
060:
061: startVerification();
062:
063: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
064: adaptor.release();
065: }
066:
067: public void testReleaseThrowsISEWhenDestroyThrowsException()
068: throws Exception {
069: session.destroy();
070: modify().throwException(new Exception());
071:
072: startVerification();
073:
074: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
075: try {
076: adaptor.release();
077: fail();
078: } catch (IllegalStateException e) {
079: }
080: }
081:
082: public void testAddStateDelegation() throws Exception {
083: String key = "key";
084: String value = "value";
085: session.addState(key, value);
086:
087: startVerification();
088:
089: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
090: adaptor.addState(key, value);
091: }
092:
093: public void testRemoveStateDelegation() throws Exception {
094: String key = "key";
095: session.removeState(key);
096:
097: startVerification();
098:
099: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
100: adaptor.removeState(key);
101: }
102:
103: public void testGetStateDelegation() throws Exception {
104: Map state = session.getState();
105:
106: startVerification();
107:
108: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
109: assertSame(state, adaptor.getState());
110: }
111:
112: public void testOnEndAccessDelegation() throws Exception {
113: session.onEndProcessing();
114:
115: startVerification();
116:
117: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
118: adaptor.onEndAccess();
119: }
120:
121: public void testRetrieveAdaptorOK() throws Exception {
122: startVerification();
123:
124: WADISessionAdaptor adaptor = new WADISessionAdaptor(session);
125: assertSame(adaptor, WADISessionAdaptor.retrieveAdaptor(session));
126: }
127:
128: public void testRetrieveThrowsISEIfNoAdaptor() throws Exception {
129: startVerification();
130:
131: try {
132: WADISessionAdaptor.retrieveAdaptor(session);
133: fail();
134: } catch (IllegalStateException e) {
135: }
136: }
137: }
|