001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TestBasicElements.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.deploymentdesc;
025:
026: import org.ow2.easybeans.tests.common.ejbs.base.xmldescriptor.ItfBasicBeanRemote;
027: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor.ItfXmlDescriptorTester;
028: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor.SFSBXmlDescriptorTester00;
029: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.xmldescriptor.SFSBXmlDescriptorTester01;
030: import org.ow2.easybeans.tests.common.helper.EJBHelper;
031: import org.testng.annotations.BeforeMethod;
032: import org.testng.annotations.Test;
033:
034: /**
035: * Verifies if the container can deploy an bean with the parameters defined in
036: * the deployment descriptor. The elements that are tested are the mappedName,
037: * ejb-name, local, remote and session type.
038: * @reference JSR 220 - FINAL RELEASE
039: * @requirement the bean SFSBXmlDescriptorTester must be deployed to make the
040: * tests, and, the BasicBean with the different deployment
041: * descriptors must be deployed too.
042: * @setup gets an instance of the SFSBXmlDescriptorTester.
043: * @author Gisele Pinheiro Souza
044: * @author Eduardo Studzinski Estima de Castro
045: */
046: public class TestBasicElements {
047:
048: /**
049: * Bean used to verify the local access.
050: */
051: private ItfXmlDescriptorTester sfTester;
052:
053: /**
054: * Bean used to verify the local access.
055: */
056: private ItfXmlDescriptorTester slTester;
057:
058: /**
059: * Creates the stateful bean used during the tests.
060: * @throws Exception if an error occurs during the lookup.
061: */
062: @BeforeMethod
063: public void setup() throws Exception {
064: slTester = EJBHelper.getBeanRemoteInstance(
065: SFSBXmlDescriptorTester00.class,
066: ItfXmlDescriptorTester.class);
067: sfTester = EJBHelper.getBeanRemoteInstance(
068: SFSBXmlDescriptorTester01.class,
069: ItfXmlDescriptorTester.class);
070: }
071:
072: /**
073: * Verifies if the bean can get an instance of a stateless bean by the
074: * mappedName.This test verifies the local interface.
075: * @input -
076: * @output the correct method execution.
077: * @throws Exception if an error occurs.
078: */
079: @Test
080: public void verifySLMappedName() throws Exception {
081: ItfBasicBeanRemote bean = EJBHelper
082: .getBeanByMappedName("SLSBBasicBeanByXMLMappedRemote");
083: bean.toString();
084: }
085:
086: /**
087: * Verifies if the bean can get an instance of a stateful bean by the
088: * mappedName.This test verifies the remote interface.
089: * @input -
090: * @output the correct method execution.
091: * @throws Exception if an error occurs.
092: */
093: @Test
094: public void verifySFMappedName() throws Exception {
095: ItfBasicBeanRemote bean = EJBHelper
096: .getBeanByMappedName("SFSBBasicBeanByXMLMappedRemote");
097: bean.toString();
098: }
099:
100: /**
101: * Verifies if the bean defined as stateless is deployed as a stateless. The
102: * bean class begins an userTransaction, but does not make the commit. So,
103: * if the bean is stateless the container must throw an EJBException.
104: * @input -
105: * @output an EJBException.
106: * @throws Exception if an error occurs.
107: */
108: @Test(dependsOnMethods={"verifySLMappedName"},expectedExceptions=javax.ejb.EJBException.class)
109: public void verifySLBeanTypeElement() throws Exception {
110: ItfBasicBeanRemote bean = EJBHelper
111: .getBeanByMappedName("SLSBBasicBeanByXMLMappedRemote");
112: bean.openTransaction();
113: }
114:
115: /**
116: * Verifies if the bean defined as stateful is deployed as a stateless. The
117: * bean class begins an userTransaction, but does not make the commit. So,
118: * if the bean is stateful the container must NOT throw any exception.
119: * @input -
120: * @output the correct method execution.
121: * @throws Exception if an error occurs.
122: */
123: @Test(dependsOnMethods={"verifySFMappedName"})
124: public void verifySFBeanTypeElement() throws Exception {
125: ItfBasicBeanRemote bean = EJBHelper
126: .getBeanByMappedName("SFSBBasicBeanByXMLMappedRemote");
127: bean.openTransaction();
128: }
129:
130: /**
131: * Verifies if a bean can make a lookup in other bean(stateless) by the
132: * mappedName. This test verifies the local interface.
133: * @input -
134: * @output the correct method execution.
135: * @throws Exception if an error occurs.
136: */
137: @Test
138: public void verifySLMappedNameLocal() throws Exception {
139: slTester.verifyBeanMappedName();
140: }
141:
142: /**
143: * Verifies if a bean can make a lookup in other bean(stateful) by the
144: * mappedName. This test verifies the local interface.
145: * @throws Exception
146: * @input -
147: * @output the correct method execution.
148: * @throws Exception if an error occurs.
149: */
150: @Test
151: public void verifySFMappedNameLocal() throws Exception {
152: sfTester.verifyBeanMappedName();
153: }
154:
155: /**
156: * Verifies if the stateless bean is injected by the ejb-name.
157: * @input -
158: * @output an EJBException because the stateless bean begins a transaction
159: * without making a commit.
160: * @throws Exception if an error occurs.
161: */
162: @Test(expectedExceptions=javax.ejb.EJBException.class)
163: public void verifySLInjectionByEjbName() throws Exception {
164: slTester.verifyBeanTypeElement();
165: }
166:
167: /**
168: * Verifies if the stateful bean is injected by the ejb-name.
169: * @input -
170: * @output the correct method execution.
171: * @throws Exception if an error occurs.
172: */
173: public void verifySFInjectionByEjbName() throws Exception {
174: sfTester.verifyBeanTypeElement();
175: }
176:
177: }
|