KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > EjbJarProviderTest


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.ejbjarproject;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectManager;
25 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
26 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
27 import org.netbeans.modules.j2ee.ejbjarproject.test.TestBase;
28 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
29 import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarImplementation;
30 import org.netbeans.spi.project.support.ant.AntProjectHelper;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  *
36  * @author Andrei Badea
37  */

38 public class EjbJarProviderTest extends TestBase {
39     
40     private static final String JavaDoc EJBJAR_XML = "ejb-jar.xml";
41     
42     private Project project;
43     private AntProjectHelper helper;
44     
45     public EjbJarProviderTest(String JavaDoc testName) {
46         super(testName);
47     }
48     
49     /**
50      * Tests that the deployment descriptor and beans are returned correctly.
51      */

52     public void testPathsAreReturned() throws Exception JavaDoc {
53         File JavaDoc f = new File JavaDoc(getDataDir().getAbsolutePath(), "projects/EJBModule1");
54         project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f));
55         // XXX should not cast a Project
56
helper = ((EjbJarProject)project).getAntProjectHelper();
57         
58         // first ensure meta.inf exists
59
String JavaDoc metaInf = helper.getStandardPropertyEvaluator().getProperty("meta.inf");
60         assertTrue(metaInf.endsWith("conf"));
61         FileObject metaInfFO =helper.resolveFileObject(metaInf);
62         assertNotNull(metaInfFO);
63         
64         // ensuer ejb-jar.xml and webservices.xml exist
65
FileObject ejbJarXmlFO = metaInfFO.getFileObject(EJBJAR_XML);
66         assertNotNull(ejbJarXmlFO);
67         assertNotNull(metaInfFO.getFileObject("webservices.xml"));
68
69         // ensure deployment descriptor files and beans are returned
70

71         J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
72         assertEquals(ejbJarXmlFO, provider.findDeploymentConfigurationFile(EJBJAR_XML));
73         assertEquals(FileUtil.toFile(metaInfFO.getFileObject(EJBJAR_XML)), provider.getDeploymentConfigurationFile(EJBJAR_XML));
74         
75         J2eeModule j2eeModule = (J2eeModule)project.getLookup().lookup(J2eeModule.class);
76         assertNotNull(j2eeModule.getDeploymentDescriptor(J2eeModule.EJBJAR_XML));
77         assertNotNull(j2eeModule.getDeploymentDescriptor(J2eeModule.EJBSERVICES_XML));
78         
79         EjbJarImplementation ejbJar = (EjbJarImplementation)project.getLookup().lookup(EjbJarImplementation.class);
80         assertEquals(metaInfFO, ejbJar.getMetaInf());
81         assertEquals(ejbJarXmlFO, ejbJar.getDeploymentDescriptor());
82     }
83     
84     /**
85      * Tests that null is silently returned for files in the configuration files directory
86      * (meta.inf) when this directory does not exist.
87      */

88     public void testMetaInfBasedPathsAreNullWhenMetaInfIsNullIssue65888() throws Exception JavaDoc {
89         File JavaDoc f = new File JavaDoc(getDataDir().getAbsolutePath(), "projects/BrokenEJBModule1");
90         project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f));
91         // XXX should not cast a Project
92
helper = ((EjbJarProject)project).getAntProjectHelper();
93         
94         // first ensure meta.inf does not exist
95
String JavaDoc metaInf = helper.getStandardPropertyEvaluator().getProperty("meta.inf");
96         assertTrue(metaInf.endsWith("conf"));
97         assertNull(helper.resolveFileObject(metaInf));
98         
99         // ensure meta.inf-related files are silently returned as null
100

101         J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
102         assertNull(provider.findDeploymentConfigurationFile(EJBJAR_XML));
103         assertNotNull(provider.getDeploymentConfigurationFile(EJBJAR_XML));
104         
105         J2eeModule j2eeModule = (J2eeModule)project.getLookup().lookup(J2eeModule.class);
106         assertNull(j2eeModule.getDeploymentDescriptor(J2eeModule.EJBJAR_XML));
107         assertNull(j2eeModule.getDeploymentDescriptor(J2eeModule.EJBSERVICES_XML));
108         
109         EjbJarImplementation ejbJar = (EjbJarImplementation)project.getLookup().lookup(EjbJarImplementation.class);
110         assertNull(ejbJar.getMetaInf());
111         assertNull(ejbJar.getDeploymentDescriptor());
112     }
113     
114     public void testNeedConfigurationFolder() {
115         assertTrue("1.3 needs configuration folder",
116                 EjbJarProvider.needConfigurationFolder(EjbJarProjectProperties.J2EE_1_3));
117         assertTrue("1.4 needs configuration folder",
118                 EjbJarProvider.needConfigurationFolder(EjbJarProjectProperties.J2EE_1_4));
119         assertFalse("5.0 does not need configuration folder",
120                 EjbJarProvider.needConfigurationFolder(EjbJarProjectProperties.JAVA_EE_5));
121         assertFalse("Anything else does not need configuration folder",
122                 EjbJarProvider.needConfigurationFolder("5.0"));
123         assertFalse("Anything else does not need configuration folder",
124                 EjbJarProvider.needConfigurationFolder("6.0.hmmm?"));
125         assertFalse("Even null does not need configuration folder",
126                 EjbJarProvider.needConfigurationFolder(null));
127     }
128     
129 }
130
Popular Tags