KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > api > codegeneration > SessionGeneratorTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ejbcore.api.codegeneration;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
25 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
26 import org.netbeans.modules.j2ee.dd.api.ejb.Session;
27 import org.netbeans.modules.j2ee.ejbcore.test.TestBase;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30
31 /**
32  *
33  * @author Martin Adamek
34  */

35 public class SessionGeneratorTest extends TestBase {
36     
37     public SessionGeneratorTest(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     public void testGenerateJavaEE14() throws IOException JavaDoc {
42         TestModule testModule = ejb14();
43         FileObject sourceRoot = testModule.getSources()[0];
44         FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE14");
45         if (packageFileObject != null) {
46             packageFileObject.delete();
47         }
48         packageFileObject = sourceRoot.createFolder("testGenerateJavaEE14");
49
50         // Stateless EJB in Java EE 1.4
51

52         SessionGenerator sessionGenerator = SessionGenerator.create("TestStatelessLR", packageFileObject, true, true, false, false, false, true);
53         sessionGenerator.generate();
54         EjbJar ejbJar = DDProvider.getDefault().getDDRoot(testModule.getDeploymentDescriptor());
55         EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans();
56         Session session = (Session) enterpriseBeans.findBeanByName(EnterpriseBeans.SESSION, Session.EJB_NAME, "TestStatelessLRBean");
57
58         assertNotNull(session);
59         assertEquals("TestStatelessLRSB", session.getDefaultDisplayName());
60         assertEquals("TestStatelessLRBean", session.getEjbName());
61         assertEquals("testGenerateJavaEE14.TestStatelessLRRemoteHome", session.getHome());
62         assertEquals("testGenerateJavaEE14.TestStatelessLRRemote", session.getRemote());
63         assertEquals("testGenerateJavaEE14.TestStatelessLRLocalHome", session.getLocalHome());
64         assertEquals("testGenerateJavaEE14.TestStatelessLRLocal", session.getLocal());
65         assertEquals("testGenerateJavaEE14.TestStatelessLRBean", session.getEjbClass());
66         assertEquals("Stateless", session.getSessionType());
67         assertEquals("Container", session.getTransactionType());
68         assertFile(
69                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLRBean.java")),
70                 getGoldenFile("testGenerateJavaEE14/TestStatelessLRBean.java"),
71                 FileUtil.toFile(packageFileObject)
72                 );
73         assertFile(
74                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLRLocal.java")),
75                 getGoldenFile("testGenerateJavaEE14/TestStatelessLRLocal.java"),
76                 FileUtil.toFile(packageFileObject)
77                 );
78         assertFile(
79                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLRLocalHome.java")),
80                 getGoldenFile("testGenerateJavaEE14/TestStatelessLRLocalHome.java"),
81                 FileUtil.toFile(packageFileObject)
82                 );
83         assertFile(
84                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLRRemote.java")),
85                 getGoldenFile("testGenerateJavaEE14/TestStatelessLRRemote.java"),
86                 FileUtil.toFile(packageFileObject)
87                 );
88         assertFile(
89                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLRRemoteHome.java")),
90                 getGoldenFile("testGenerateJavaEE14/TestStatelessLRRemoteHome.java"),
91                 FileUtil.toFile(packageFileObject)
92                 );
93
94         // Stateful EJB in Java EE 1.4
95

96         sessionGenerator = SessionGenerator.create("TestStatefulLR", packageFileObject, false, true, true, false, false, true);
97         sessionGenerator.generate();
98         session = (Session) enterpriseBeans.findBeanByName(EnterpriseBeans.SESSION, Session.EJB_NAME, "TestStatefulLRBean");
99
100         assertNotNull(session);
101         assertEquals("TestStatefulLRSB", session.getDefaultDisplayName());
102         assertEquals("TestStatefulLRBean", session.getEjbName());
103         assertNull(session.getHome());
104         assertNull(session.getRemote());
105         assertEquals("testGenerateJavaEE14.TestStatefulLRLocalHome", session.getLocalHome());
106         assertEquals("testGenerateJavaEE14.TestStatefulLRLocal", session.getLocal());
107         assertEquals("testGenerateJavaEE14.TestStatefulLRBean", session.getEjbClass());
108         assertEquals("Stateful", session.getSessionType());
109         assertEquals("Container", session.getTransactionType());
110         assertFile(
111                 FileUtil.toFile(packageFileObject.getFileObject("TestStatefulLRBean.java")),
112                 getGoldenFile("testGenerateJavaEE14/TestStatefulLRBean.java"),
113                 FileUtil.toFile(packageFileObject)
114                 );
115         assertFile(
116                 FileUtil.toFile(packageFileObject.getFileObject("TestStatefulLRLocal.java")),
117                 getGoldenFile("testGenerateJavaEE14/TestStatefulLRLocal.java"),
118                 FileUtil.toFile(packageFileObject)
119                 );
120         assertFile(
121                 FileUtil.toFile(packageFileObject.getFileObject("TestStatefulLRLocalHome.java")),
122                 getGoldenFile("testGenerateJavaEE14/TestStatefulLRLocalHome.java"),
123                 FileUtil.toFile(packageFileObject)
124                 );
125         assertNull(packageFileObject.getFileObject("TestStatefulLRRemote.java"));
126         assertNull(packageFileObject.getFileObject("TestStatefulLRRemoteHome.java"));
127     }
128     
129     public void testGenerateJavaEE50() throws IOException JavaDoc {
130         TestModule testModule = ejb50();
131         FileObject sourceRoot = testModule.getSources()[0];
132         FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE50");
133         if (packageFileObject != null) {
134             packageFileObject.delete();
135         }
136         packageFileObject = sourceRoot.createFolder("testGenerateJavaEE50");
137
138         // Stateless EJB in Java EE 5.0 defined in annotations
139

140         SessionGenerator sessionGenerator = SessionGenerator.create("TestStateless", packageFileObject, true, true, false, true, false, false);
141         sessionGenerator.generate();
142
143         assertFile(
144                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessBean.java")),
145                 getGoldenFile("testGenerateJavaEE50/TestStatelessBean.java"),
146                 FileUtil.toFile(packageFileObject)
147                 );
148         assertFile(
149                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessLocal.java")),
150                 getGoldenFile("testGenerateJavaEE50/TestStatelessLocal.java"),
151                 FileUtil.toFile(packageFileObject)
152                 );
153         assertFile(
154                 FileUtil.toFile(packageFileObject.getFileObject("TestStatelessRemote.java")),
155                 getGoldenFile("testGenerateJavaEE50/TestStatelessRemote.java"),
156                 FileUtil.toFile(packageFileObject)
157                 );
158
159         // Stateful EJB in Java EE 5.0 defined in annotations
160

161         sessionGenerator = SessionGenerator.create("TestStateful", packageFileObject, true, false, true, true, false, false);
162         sessionGenerator.generate();
163
164         assertFile(
165                 FileUtil.toFile(packageFileObject.getFileObject("TestStatefulBean.java")),
166                 getGoldenFile("testGenerateJavaEE50/TestStatefulBean.java"),
167                 FileUtil.toFile(packageFileObject)
168                 );
169         assertFile(
170                 FileUtil.toFile(packageFileObject.getFileObject("TestStatefulRemote.java")),
171                 getGoldenFile("testGenerateJavaEE50/TestStatefulRemote.java"),
172                 FileUtil.toFile(packageFileObject)
173                 );
174         assertNull(packageFileObject.getFileObject("TestStatefulLocal.java"));
175     }
176     
177 }
178
Popular Tags