KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.j2ee.dd.api.common.MessageDestination;
26 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
27 import org.netbeans.modules.j2ee.dd.api.ejb.ActivationConfig;
28 import org.netbeans.modules.j2ee.dd.api.ejb.ActivationConfigProperty;
29 import org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor;
30 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
31 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
32 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
33 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
34 import org.netbeans.modules.j2ee.ejbcore.test.TestBase;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileUtil;
37
38 /**
39  *
40  * @author Martin Adamek
41  */

42 public class MessageGeneratorTest extends TestBase {
43     
44     public MessageGeneratorTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     public void testGenerateJavaEE14() throws IOException JavaDoc, VersionNotSupportedException {
49         TestModule testModule = ejb14();
50         FileObject sourceRoot = testModule.getSources()[0];
51         FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE14");
52         if (packageFileObject != null) {
53             packageFileObject.delete();
54         }
55         packageFileObject = sourceRoot.createFolder("testGenerateJavaEE14");
56
57         // Queue based MessageDriven EJB in Java EE 1.4
58

59         MessageGenerator generator = MessageGenerator.create("TestMDBQueue", packageFileObject, true, false, true);
60         generator.generate();
61         
62         EjbJar ejbJar = DDProvider.getDefault().getDDRoot(testModule.getDeploymentDescriptor());
63         EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans();
64         MessageDriven messageDriven = (MessageDriven) enterpriseBeans.findBeanByName(
65                 EnterpriseBeans.MESSAGE_DRIVEN, MessageDriven.EJB_NAME, "TestMDBQueueBean");
66         assertNotNull(messageDriven);
67         assertEquals("TestMDBQueueMDB", messageDriven.getDefaultDisplayName());
68         assertEquals("TestMDBQueueBean", messageDriven.getEjbName());
69         assertEquals("testGenerateJavaEE14.TestMDBQueueBean", messageDriven.getEjbClass());
70         assertEquals("Container", messageDriven.getTransactionType());
71         assertEquals("javax.jms.Queue", messageDriven.getMessageDestinationType());
72         assertEquals("TestMDBQueueBeanDestination", messageDriven.getMessageDestinationLink());
73         ActivationConfig activationConfig = messageDriven.getActivationConfig();
74         assertEquals(2, activationConfig.getActivationConfigProperty().length);
75         ActivationConfigProperty acProperty = activationConfig.getActivationConfigProperty()[0];
76         assertEquals("acknowledgeMode", acProperty.getActivationConfigPropertyName());
77         assertEquals("Auto-acknowledge", acProperty.getActivationConfigPropertyValue());
78         acProperty = activationConfig.getActivationConfigProperty()[1];
79         assertEquals("destinationType", acProperty.getActivationConfigPropertyName());
80         assertEquals("javax.jms.Queue", acProperty.getActivationConfigPropertyValue());
81         assertFile(
82                 FileUtil.toFile(packageFileObject.getFileObject("TestMDBQueueBean.java")),
83                 getGoldenFile("testGenerateJavaEE14/TestMDBQueueBean.java"),
84                 FileUtil.toFile(packageFileObject)
85                 );
86
87         // Topic based MessageDriven EJB in Java EE 1.4
88

89         generator = MessageGenerator.create("TestMDBTopic", packageFileObject, false, false, true);
90         generator.generate();
91         
92         messageDriven = (MessageDriven) enterpriseBeans.findBeanByName(
93                 EnterpriseBeans.MESSAGE_DRIVEN, MessageDriven.EJB_NAME, "TestMDBTopicBean");
94         assertNotNull(messageDriven);
95         assertEquals("TestMDBTopicMDB", messageDriven.getDefaultDisplayName());
96         assertEquals("TestMDBTopicBean", messageDriven.getEjbName());
97         assertEquals("testGenerateJavaEE14.TestMDBTopicBean", messageDriven.getEjbClass());
98         assertEquals("Container", messageDriven.getTransactionType());
99         assertEquals("javax.jms.Topic", messageDriven.getMessageDestinationType());
100         assertEquals("TestMDBTopicBeanDestination", messageDriven.getMessageDestinationLink());
101         activationConfig = messageDriven.getActivationConfig();
102         assertEquals(5, activationConfig.getActivationConfigProperty().length);
103         acProperty = activationConfig.getActivationConfigProperty()[0];
104         assertEquals("acknowledgeMode", acProperty.getActivationConfigPropertyName());
105         assertEquals("Auto-acknowledge", acProperty.getActivationConfigPropertyValue());
106         acProperty = activationConfig.getActivationConfigProperty()[1];
107         assertEquals("subscriptionDurability", acProperty.getActivationConfigPropertyName());
108         assertEquals("Durable", acProperty.getActivationConfigPropertyValue());
109         acProperty = activationConfig.getActivationConfigProperty()[2];
110         assertEquals("clientId", acProperty.getActivationConfigPropertyName());
111         assertEquals("TestMDBTopicBean", acProperty.getActivationConfigPropertyValue());
112         acProperty = activationConfig.getActivationConfigProperty()[3];
113         assertEquals("subscriptionName", acProperty.getActivationConfigPropertyName());
114         assertEquals("TestMDBTopicBean", acProperty.getActivationConfigPropertyValue());
115         acProperty = activationConfig.getActivationConfigProperty()[4];
116         assertEquals("destinationType", acProperty.getActivationConfigPropertyName());
117         assertEquals("javax.jms.Topic", acProperty.getActivationConfigPropertyValue());
118         assertFile(
119                 FileUtil.toFile(packageFileObject.getFileObject("TestMDBTopicBean.java")),
120                 getGoldenFile("testGenerateJavaEE14/TestMDBTopicBean.java"),
121                 FileUtil.toFile(packageFileObject)
122                 );
123
124         // added by both previous generators
125

126         AssemblyDescriptor assemblyDescriptor = ejbJar.getSingleAssemblyDescriptor();
127         List JavaDoc<String JavaDoc> messageDestinationNames = new ArrayList JavaDoc<String JavaDoc>();
128         for (MessageDestination messageDestination : assemblyDescriptor.getMessageDestination()) {
129             messageDestinationNames.add(messageDestination.getMessageDestinationName());
130         }
131         assertTrue(messageDestinationNames.contains("TestMDBQueueBeanDestination"));
132         assertTrue(messageDestinationNames.contains("TestMDBTopicBeanDestination"));
133     }
134     
135     public void testGenerateJavaEE50() throws IOException JavaDoc {
136         TestModule testModule = ejb14();
137         FileObject sourceRoot = testModule.getSources()[0];
138         FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE50");
139         if (packageFileObject != null) {
140             packageFileObject.delete();
141         }
142         packageFileObject = sourceRoot.createFolder("testGenerateJavaEE50");
143         
144         // Queue based MessageDriven EJB in Java EE 5 defined in annotation
145

146         MessageGenerator generator = MessageGenerator.create("TestMDBQueue", packageFileObject, true, true, false);
147         generator.generate();
148         
149         assertFile(
150                 FileUtil.toFile(packageFileObject.getFileObject("TestMDBQueueBean.java")),
151                 getGoldenFile("testGenerateJavaEE50/TestMDBQueueBean.java"),
152                 FileUtil.toFile(packageFileObject)
153                 );
154
155         // Topic based MessageDriven EJB in Java EE 5 defined in annotation
156

157         generator = MessageGenerator.create("TestMDBTopic", packageFileObject, false, true, false);
158         generator.generate();
159         
160         assertFile(
161                 FileUtil.toFile(packageFileObject.getFileObject("TestMDBQueueBean.java")),
162                 getGoldenFile("testGenerateJavaEE50/TestMDBQueueBean.java"),
163                 FileUtil.toFile(packageFileObject)
164                 );
165     }
166
167 }
168
Popular Tags