001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.timer;
018:
019: import javax.annotation.Resource;
020: import javax.ejb.SessionContext;
021: import javax.ejb.Stateless;
022: import javax.ejb.TimerService;
023: import javax.naming.InitialContext;
024:
025: import junit.framework.TestCase;
026:
027: import org.apache.openejb.assembler.classic.Assembler;
028: import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
029: import org.apache.openejb.assembler.classic.SecurityServiceInfo;
030: import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
031: import org.apache.openejb.assembler.classic.TransactionServiceInfo;
032: import org.apache.openejb.config.ConfigurationFactory;
033: import org.apache.openejb.core.ivm.naming.InitContextFactory;
034: import org.apache.openejb.jee.EjbJar;
035: import org.apache.openejb.jee.StatelessBean;
036:
037: /**
038: * @version $Revision: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
039: */
040: public class TimerContainerTest extends TestCase {
041:
042: public void testTimerServiceInjection() throws Exception {
043: InitialContext ctx = new InitialContext();
044:
045: Object object = ctx.lookup("WidgetBeanLocal");
046:
047: assertTrue("instanceof widget", object instanceof Widget);
048:
049: Widget widget = (Widget) object;
050:
051: // Do a business method...
052: assertTrue("Timer was not injected", widget.isTimerSet());
053: }
054:
055: protected void setUp() throws Exception {
056: super .setUp();
057:
058: System.setProperty(
059: javax.naming.Context.INITIAL_CONTEXT_FACTORY,
060: InitContextFactory.class.getName());
061:
062: ConfigurationFactory config = new ConfigurationFactory();
063: Assembler assembler = new Assembler();
064:
065: assembler.createProxyFactory(config
066: .configureService(ProxyFactoryInfo.class));
067: assembler.createTransactionManager(config
068: .configureService(TransactionServiceInfo.class));
069: assembler.createSecurityService(config
070: .configureService(SecurityServiceInfo.class));
071:
072: // containers
073: StatelessSessionContainerInfo statelessContainerInfo = config
074: .configureService(StatelessSessionContainerInfo.class);
075: statelessContainerInfo.properties.setProperty("TimeOut", "10");
076: statelessContainerInfo.properties.setProperty("PoolSize", "0");
077: statelessContainerInfo.properties.setProperty("StrictPooling",
078: "false");
079: assembler.createContainer(statelessContainerInfo);
080:
081: // Setup the descriptor information
082:
083: StatelessBean bean = new StatelessBean(WidgetBean.class);
084: bean.addBusinessLocal(Widget.class.getName());
085: bean.addBusinessRemote(RemoteWidget.class.getName());
086:
087: EjbJar ejbJar = new EjbJar();
088: ejbJar.addEnterpriseBean(bean);
089:
090: assembler
091: .createApplication(config.configureApplication(ejbJar));
092:
093: }
094:
095: public static interface Widget {
096: boolean isTimerSet();
097: }
098:
099: public static interface RemoteWidget extends Widget {
100: }
101:
102: @Stateless
103: public static class WidgetBean implements Widget, RemoteWidget {
104:
105: @Resource
106: TimerService timer;
107:
108: public WidgetBean() {
109: }
110:
111: public void setSessionContext(SessionContext sessionContext) {
112: }
113:
114: public boolean isTimerSet() {
115: return timer != null;
116: }
117:
118: }
119: }
|