1 19 20 package org.netbeans.modules.j2ee.ejbcore.api.codegeneration; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.List ; 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 42 public class MessageGeneratorTest extends TestBase { 43 44 public MessageGeneratorTest(String testName) { 45 super(testName); 46 } 47 48 public void testGenerateJavaEE14() throws IOException , 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 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 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 126 AssemblyDescriptor assemblyDescriptor = ejbJar.getSingleAssemblyDescriptor(); 127 List <String > messageDestinationNames = new ArrayList <String >(); 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 { 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 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 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 |