01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.clustering.wadi;
17:
18: import org.codehaus.wadi.group.Peer;
19: import org.codehaus.wadi.servicespace.InvocationMetaData;
20: import org.codehaus.wadi.servicespace.ServiceProxy;
21: import org.codehaus.wadi.servicespace.ServiceProxyFactory;
22: import org.codehaus.wadi.servicespace.ServiceRegistry;
23: import org.codehaus.wadi.servicespace.ServiceSpace;
24:
25: import com.agical.rmock.extension.junit.RMockTestCase;
26:
27: /**
28: *
29: * @version $Rev$ $Date$
30: */
31: public class NodeServiceHelperTest extends RMockTestCase {
32:
33: private ServiceSpace serviceSpace;
34: private NodeServiceHelper serviceHelper;
35: private NodeService nodeService;
36:
37: @Override
38: protected void setUp() throws Exception {
39: nodeService = (NodeService) mock(NodeServiceProxy.class);
40: serviceSpace = (ServiceSpace) mock(ServiceSpace.class);
41: serviceHelper = new NodeServiceHelper(serviceSpace);
42: }
43:
44: public void testNodeServiceRegistration() throws Exception {
45: ServiceRegistry serviceRegistry = serviceSpace
46: .getServiceRegistry();
47: serviceRegistry.register(NodeService.SERVICE_NAME, nodeService);
48:
49: startVerification();
50:
51: serviceHelper.registerNodeService(nodeService);
52: }
53:
54: public void testGetNodeServiceProxy() throws Exception {
55: Peer peer = (Peer) mock(Peer.class);
56: ServiceProxyFactory proxyFactory = serviceSpace
57: .getServiceProxyFactory(NodeService.SERVICE_NAME,
58: new Class[] { NodeService.class });
59: proxyFactory.getInvocationMetaData();
60:
61: InvocationMetaData invMetaData = (InvocationMetaData) intercept(
62: InvocationMetaData.class, "InvocationMetaData");
63: modify().returnValue(invMetaData);
64:
65: invMetaData.setTargets(new Peer[] { peer });
66:
67: proxyFactory.getProxy();
68: modify().returnValue(nodeService);
69:
70: startVerification();
71:
72: assertSame(nodeService, serviceHelper.getNodeServiceProxy(peer));
73: }
74:
75: public static interface NodeServiceProxy extends NodeService,
76: ServiceProxy {
77: }
78:
79: }
|