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.injection;
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: /**
26: * A test case for DataReaderImpl ejb, testing both the remote and local interface
27: *
28: */
29: public class EjbDependencyTest extends TestCase {
30:
31: private static final String REMOTE_STORE_RESULT = "REMOTE:42";
32: private static final String LOCAL_STORE_RESULT = "LOCAL:42";
33:
34: //START SNIPPET: setup
35: private InitialContext initialContext;
36:
37: protected void setUp() throws Exception {
38: Properties properties = new Properties();
39: properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
40: "org.apache.openejb.client.LocalInitialContextFactory");
41:
42: initialContext = new InitialContext(properties);
43: }
44:
45: //END SNIPPET: setup
46:
47: //START SNIPPET: test
48: public void testViaLocalInterface() throws Exception {
49: Object object = initialContext.lookup("DataReaderImplLocal");
50:
51: assertNotNull(object);
52: assertEquals(LOCAL_STORE_RESULT, ((DataReaderLocal) object)
53: .readDataFromLocalStore());
54: assertEquals(REMOTE_STORE_RESULT, ((DataReaderLocal) object)
55: .readDataFromRemoteStore());
56: }
57:
58: //END SNIPPET: test
59:
60: public void testViaRemoteInterface() throws Exception {
61: Object object = initialContext.lookup("DataReaderImplRemote");
62:
63: assertNotNull(object);
64: assertEquals(LOCAL_STORE_RESULT, ((DataReaderRemote) object)
65: .readDataFromLocalStore());
66: assertEquals(REMOTE_STORE_RESULT, ((DataReaderRemote) object)
67: .readDataFromRemoteStore());
68: }
69: }
|