001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.server.ejbd;
017:
018: import java.io.IOException;
019: import java.net.URI;
020:
021: import org.apache.openejb.ClusteredRPCContainer;
022: import org.apache.openejb.DeploymentInfo;
023: import org.apache.openejb.client.ClusterableRequest;
024: import org.apache.openejb.client.ClusterableResponse;
025: import org.apache.openejb.client.ServerMetaData;
026:
027: import com.agical.rmock.core.describe.ExpressionDescriber;
028: import com.agical.rmock.core.match.operator.AbstractExpression;
029: import com.agical.rmock.extension.junit.RMockTestCase;
030:
031: public class BasicClusterableRequestHandlerTest extends RMockTestCase {
032:
033: private BasicClusterableRequestHandler requestHandler;
034: private ClusterableRequest request;
035: private ClusterableResponse response;
036: private DeploymentInfo deploymentInfo;
037: private ClusteredRPCContainer clusteredContainer;
038:
039: @Override
040: protected void setUp() throws Exception {
041: requestHandler = new BasicClusterableRequestHandler();
042: request = (ClusterableRequest) mock(ClusterableRequest.class);
043: response = (ClusterableResponse) mock(ClusterableResponse.class);
044: deploymentInfo = (DeploymentInfo) mock(DeploymentInfo.class);
045: clusteredContainer = (ClusteredRPCContainer) mock(ClusteredRPCContainer.class);
046: }
047:
048: public void testNoOpWhenNotAClusteredContainer() throws Exception {
049: deploymentInfo.getContainer();
050:
051: startVerification();
052:
053: requestHandler.updateServer(deploymentInfo, request, response);
054: }
055:
056: public void testUpdateServerWhenRequestHashDiffersFromServerSideHash()
057: throws Exception {
058: final URI[] locations = new URI[] { new URI(
059: "ejbd://localhost:4201") };
060: ServerMetaData server = new ServerMetaData(locations);
061:
062: deploymentInfo.getContainer();
063: modify().returnValue(clusteredContainer);
064:
065: request.getServerHash();
066: modify().returnValue(server.buildHash() + 1);
067:
068: response.setServer(null);
069: modify().args(new AbstractExpression() {
070: public void describeWith(ExpressionDescriber arg0)
071: throws IOException {
072: }
073:
074: public boolean passes(Object arg0) {
075: ServerMetaData actualServer = (ServerMetaData) arg0;
076: assertSame(locations, actualServer.getLocations());
077: return true;
078: }
079: });
080:
081: clusteredContainer.getLocations(deploymentInfo);
082: modify().returnValue(locations);
083:
084: startVerification();
085:
086: requestHandler.updateServer(deploymentInfo, request, response);
087: }
088:
089: public void testServerIsNotUpdatedWhenRequestHashEqualsServerSideHash()
090: throws Exception {
091: URI[] locations = new URI[] { new URI("ejbd://localhost:4201") };
092: ServerMetaData server = new ServerMetaData(locations);
093:
094: deploymentInfo.getContainer();
095: modify().returnValue(clusteredContainer);
096:
097: request.getServerHash();
098: modify().returnValue(server.buildHash());
099:
100: clusteredContainer.getLocations(deploymentInfo);
101: modify().returnValue(locations);
102:
103: startVerification();
104:
105: requestHandler.updateServer(deploymentInfo, request, response);
106: }
107:
108: }
|