001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.assembler.classic;
017:
018: import junit.framework.TestCase;
019: import org.apache.openejb.client.LocalInitialContextFactory;
020: import org.apache.openejb.config.ConfigurationFactory;
021: import org.apache.openejb.core.ivm.naming.InitContextFactory;
022: import org.apache.openejb.test.stateful.AnnotatedFieldInjectionStatefulBean;
023: import org.apache.openejb.test.stateful.EncStatefulHome;
024: import org.apache.openejb.test.stateful.EncStatefulObject;
025: import org.apache.openejb.test.stateless.BasicStatelessBean;
026: import org.apache.openejb.loader.JarLocation;
027: import org.w3c.dom.Document;
028: import org.w3c.dom.Node;
029: import org.w3c.dom.NodeList;
030:
031: import javax.naming.Context;
032: import javax.naming.InitialContext;
033: import javax.naming.NamingException;
034: import javax.xml.parsers.DocumentBuilder;
035: import javax.xml.parsers.DocumentBuilderFactory;
036:
037: import java.io.File;
038: import java.util.Properties;
039:
040: /**
041: * @version $Rev: 634826 $ $Date: 2008-03-07 13:12:48 -0800 $
042: */
043: public class RedeployTest extends TestCase {
044: public void test() throws Exception {
045: // create reference to openejb itests
046: File file = JarLocation.jarLocation(BasicStatelessBean.class);
047:
048: if (file == null)
049: return;
050:
051: System.setProperty(
052: javax.naming.Context.INITIAL_CONTEXT_FACTORY,
053: InitContextFactory.class.getName());
054:
055: ConfigurationFactory config = new ConfigurationFactory();
056: Assembler assembler = new Assembler();
057:
058: assembler.createProxyFactory(config
059: .configureService(ProxyFactoryInfo.class));
060: assembler.createTransactionManager(config
061: .configureService(TransactionServiceInfo.class));
062: assembler.createSecurityService(config
063: .configureService(SecurityServiceInfo.class));
064:
065: // managed JDBC
066: assembler.createResource(config.configureService(
067: "Default JDBC Database", ResourceInfo.class));
068:
069: // unmanaged JDBC
070: assembler.createResource(config.configureService(
071: "Default Unmanaged JDBC Database", ResourceInfo.class));
072:
073: // JMS
074: assembler.createResource(config.configureService(
075: "Default JMS Resource Adapter", ResourceInfo.class));
076: assembler.createResource(config.configureService(
077: "Default JMS Connection Factory", ResourceInfo.class));
078:
079: // containers
080: assembler.createContainer(config
081: .configureService(BmpEntityContainerInfo.class));
082: assembler.createContainer(config
083: .configureService(CmpEntityContainerInfo.class));
084: assembler.createContainer(config
085: .configureService(StatefulSessionContainerInfo.class));
086: assembler.createContainer(config
087: .configureService(StatelessSessionContainerInfo.class));
088: assembler.createContainer(config
089: .configureService(MdbContainerInfo.class));
090:
091: createAndDestroy(assembler, config, file);
092: createAndDestroy(assembler, config, file);
093: createAndDestroy(assembler, config, file);
094: }
095:
096: private void createAndDestroy(Assembler assembler,
097: ConfigurationFactory config, File file) throws Exception {
098: assembler.createApplication(config.configureApplication(file));
099:
100: Properties properties = new Properties();
101: properties.put(Context.INITIAL_CONTEXT_FACTORY,
102: LocalInitialContextFactory.class.getName());
103: InitialContext ctx = new InitialContext(properties);
104: EncStatefulHome home = (EncStatefulHome) ctx
105: .lookup(AnnotatedFieldInjectionStatefulBean.class
106: .getSimpleName());
107: EncStatefulObject ejbObject = home.create("foo");
108: ejbObject.lookupStringEntry();
109:
110: assembler.destroyApplication(file.getAbsolutePath());
111:
112: try {
113: ejbObject.lookupStringEntry();
114: fail("Proxy should no longer be valid");
115: } catch (Exception e) {
116: // this should happen
117: }
118:
119: try {
120: ctx.lookup(AnnotatedFieldInjectionStatefulBean.class
121: .getSimpleName());
122: fail("JNDI References should have been cleaned up");
123: } catch (NamingException e) {
124: // this also should happen
125: }
126: }
127: }
|