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.superbiz.counter;
17:
18: import java.util.Properties;
19:
20: import javax.naming.Context;
21: import javax.naming.InitialContext;
22:
23: import junit.framework.TestCase;
24:
25: public class CounterImplTest extends TestCase {
26:
27: //START SNIPPET: setup
28: private InitialContext initialContext;
29:
30: protected void setUp() throws Exception {
31: Properties properties = new Properties();
32: properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
33: "org.apache.openejb.client.LocalInitialContextFactory");
34:
35: initialContext = new InitialContext(properties);
36: }
37:
38: //END SNIPPET: setup
39:
40: /**
41: * Lookup the Counter bean via its remote home interface
42: *
43: * @throws Exception
44: */
45: //START SNIPPET: remote
46: public void testCounterViaRemoteInterface() throws Exception {
47: Object object = initialContext.lookup("CounterImplRemote");
48:
49: assertNotNull(object);
50: assertTrue(object instanceof CounterRemote);
51: CounterRemote counter = (CounterRemote) object;
52: assertEquals(0, counter.reset());
53: assertEquals(1, counter.increment());
54: assertEquals(2, counter.increment());
55: assertEquals(0, counter.reset());
56: }
57:
58: //END SNIPPET: remote
59:
60: /**
61: * Lookup the Counter bean via its local home interface
62: *
63: * @throws Exception
64: */
65: //START SNIPPET: local
66: public void testCounterViaLocalInterface() throws Exception {
67: Object object = initialContext.lookup("CounterImplLocal");
68:
69: assertNotNull(object);
70: assertTrue(object instanceof CounterLocal);
71: CounterLocal counter = (CounterLocal) object;
72: assertEquals(0, counter.reset());
73: assertEquals(1, counter.increment());
74: assertEquals(2, counter.increment());
75: assertEquals(0, counter.reset());
76: }
77: //END SNIPPET: local
78:
79: }
|