Jacek Laskowski wrote:
On Nov 25, 2007 11:09 PM, Paul Spencer <[EMAIL PROTECTED]> wrote:
Since the test is using OpenEJB as an embedded server, why is the test
class not considered as a DI target?
if (test class == ejb class && test case == interceptor class) {
// the test class *is* a target of DI machinery
} else {
// do nothing with it, just load the class and provide to other
classes with no DI-related changes
}
I need to think about this. I start a new thread if I have questions.
My intent is to test the EJB in the same manor as an application would
use the EJB. This includes the use of DI. Is my implementation
consistent with my intent?
Have you considered checking out the openejb examples from
http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/?
Unless you have, I'd strongly recommend doing so as there're quite a
few examples of how ejbs look like and work in openejb. There's
nothing specific to openejb in them so they should work in other ejb
containers with no changes. You can read about them on
http://openejb.apache.org/examples.html. If you're not satisfied with
them, write what you're after and I'll create one for you (consider it
a New Year present ;-))
I have attached a modified version of the EjbDependencyTest that
illustrates how I want to test my EJBs.
Jacek
Thank you,
Paul Spencer
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.examples.injection;
import java.util.Properties;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import junit.framework.TestCase;
/**
* A test case for DataReaderImpl ejb, testing both the remote and local
interface
* using Depenency Injection.
*/
public class EjbDiTest extends TestCase {
private static final String REMOTE_STORE_RESULT = "REMOTE:42";
private static final String LOCAL_STORE_RESULT = "LOCAL:42";
@EJB private DataReaderLocal dataReaderLocal;
@EJB private DataReaderRemote dataReaderRemote;
//START SNIPPET: setup
private InitialContext initialContext;
protected void setUp() throws Exception {
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
properties.setProperty("openejb.deployments.classpath.include",
".*injection.*");
initialContext = new InitialContext(properties);
}
//END SNIPPET: setup
//START SNIPPET: test
public void testViaLocalInterface() throws Exception {
assertNotNull(dataReaderLocal);
assertEquals(LOCAL_STORE_RESULT,
dataReaderLocal.readDataFromLocalStore());
assertEquals(REMOTE_STORE_RESULT,
dataReaderLocal.readDataFromRemoteStore());
}
//END SNIPPET: test
public void testViaRemoteInterface() throws Exception {
assertNotNull(dataReaderRemote);
assertEquals(LOCAL_STORE_RESULT,
dataReaderRemote.readDataFromLocalStore());
assertEquals(REMOTE_STORE_RESULT,
dataReaderRemote.readDataFromRemoteStore());
}
}