summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Silgidjian2011-07-15 04:08:54 (EDT)
committerKaloyan Raev2011-07-15 04:08:54 (EDT)
commit1b5b5ca353cd4fb326df62e1bcc62211b232fe2b (patch)
tree35c6214e59649d218f2494f6d041c394b09f11ed
parent338c8f6178c820789dd34bebcb3324db32ef1bcb (diff)
downloadorg.eclipse.libra-1b5b5ca353cd4fb326df62e1bcc62211b232fe2b.zip
org.eclipse.libra-1b5b5ca353cd4fb326df62e1bcc62211b232fe2b.tar.gz
org.eclipse.libra-1b5b5ca353cd4fb326df62e1bcc62211b232fe2b.tar.bz2
Bug 341398 - JPA: persistence.xml should be placed in Project
Root/META-INF Add JUnit tests for this bug.
-rw-r--r--tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF6
-rw-r--r--tests/org.eclipse.libra.facet.test/resources/testJPAwithUtility.zip_bin0 -> 4895 bytes
-rw-r--r--tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java115
3 files changed, 94 insertions, 27 deletions
diff --git a/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF b/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
index e1b35b6..01acdfb 100644
--- a/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.libra.facet.test/META-INF/MANIFEST.MF
@@ -12,7 +12,11 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.wst.common.project.facet.core;bundle-version="1.4.102",
org.eclipse.core.databinding.observable;bundle-version="1.3.0",
org.eclipse.ui.ide;bundle-version="3.6.0",
- org.eclipse.jpt.jpa.core;bundle-version="3.0.0"
+ org.eclipse.jpt.jpa.core;bundle-version="3.0.0",
+ org.eclipse.jst.common.project.facet.core,
+ org.eclipse.jst.j2ee,
+ org.eclipse.jst.j2ee.web,
+ org.eclipse.jst.j2ee.ejb
Bundle-Vendor: %Bundle-Vendor
Import-Package: org.junit;version="4.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/tests/org.eclipse.libra.facet.test/resources/testJPAwithUtility.zip_ b/tests/org.eclipse.libra.facet.test/resources/testJPAwithUtility.zip_
new file mode 100644
index 0000000..bce1d5d
--- /dev/null
+++ b/tests/org.eclipse.libra.facet.test/resources/testJPAwithUtility.zip_
Binary files differ
diff --git a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
index 23300c6..8af5189 100644
--- a/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
+++ b/tests/org.eclipse.libra.facet.test/src/org/eclipse/libra/facet/test/WabConversionTest.java
@@ -8,11 +8,12 @@
* Contributors:
* Dimo Stoilov (SAP AG) - initial API and implementation
*******************************************************************************/
-package org.eclipse.libra.facet.test;
-
+package org.eclipse.libra.facet.test;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.core.resources.ICommand;
@@ -40,11 +41,16 @@ import org.eclipse.pde.core.project.IPackageExportDescription;
import org.eclipse.pde.core.project.IPackageImportDescription;
import org.eclipse.pde.internal.core.PDECore;
import org.eclipse.pde.internal.core.natures.PDE;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.junit.Assert;
import org.junit.Test;
+
+
@@ -53,11 +59,15 @@ public class WabConversionTest {
private static final NullProgressMonitor monitor = new NullProgressMonitor();
private static final String WEB_PRJ_LOCATION = "resources/testWeb.zip_";
private static final String JAVA_PRJ_LOCATION = "resources/testJava.zip_";
- private static final String JPA_PRJ_LOCATION = "resources/testJPA.zip_";
+ private static final String JPA_PRJ_LOCATION = "resources/testJPA.zip_";
+ private static final String JPA_UTILITY_PRJ_LOCATION = "resources/testJPAwithUtility.zip_";
private static final String SIMPLE_PRJ_LOCATION = "resources/testSimple.zip_";
private static final String WEB_PRJ_NAME = "testWeb";
private static final String JAVA_PRJ_NAME = "testJava";
- private static final String JPA_PRJ_NAME = "testJPA";
+ private static final String JPA_PRJ_NAME = "testJPA";
+ private static final String JPA_CREATE_PRJ_NAME = "testJPACreate";
+ private static final String JPA_UTILITY_CREATE_PRJ_NAME = "testJPAUtilityCreate";
+ private static final String JPA_UTILITY_PRJ_NAME = "testJPAwithUtility";
private static final String SIMPLE_PRJ_NAME = "testSimple";
private static final String WEB_REFERRING_JAVA_PRJ_LOCATION = "resources/testWebReferringJava.zip_";
private static final String WEB_REFERRING_JAVA_PRJ_NAME = "testWebReferringJava";
@@ -83,8 +93,28 @@ public class WabConversionTest {
private static final String SIMPLE_PRJ_COPY_NAME = "testSimpleCopy";
private static final String JAVA_PRJ_COPY_LOCATION = "resources/testJavaCopy.zip_";
private static final String JAVA_PRJ_COPY_NAME = "testJavaCopy";
-
-
+
+
+ @Test
+ public void createJPAProject() throws Exception {
+ IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
+ fProject.setProjectName(JPA_CREATE_PRJ_NAME);
+ HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "osgi.bundle"});
+ fProject.setProjectFacets(facets);
+ fProject.commitChanges(monitor);
+ checkMetaInf(fProject.getProject());
+ }
+
+ @Test
+ public void createJPAUtilityProject() throws Exception {
+ IFacetedProjectWorkingCopy fProject = FacetedProjectFramework.createNewProject();
+ fProject.setProjectName(JPA_UTILITY_CREATE_PRJ_NAME);
+ HashSet<IProjectFacetVersion> facets = getFacets(new String[] {"java", "jpt.jpa", "jst.utility", "osgi.bundle"});
+ fProject.setProjectFacets(facets);
+ fProject.commitChanges(monitor);
+ checkMetaInf(fProject.getProject());
+ }
+
@Test
public void convertSimpleProject() throws Exception {
IProject simpleProject = importProjectInWorkspace(SIMPLE_PRJ_LOCATION, SIMPLE_PRJ_NAME);
@@ -106,20 +136,20 @@ public class WabConversionTest {
IBundleProjectDescription description = bundleProjectService.getDescription(javaProject);
checkJavaProject(javaProject, JAVA_PRJ_NAME, "TestJava", null, "1.0.0.qualifier", new String[] {"javapack", "javapack1"}, description);
- }
-
- @Test
- public void convertJavaProjectCustomHeaders() throws Exception {
-
- IProject javaProject = importProjectInWorkspace(JAVA_PRJ_COPY_LOCATION, JAVA_PRJ_COPY_NAME);
- OSGiBundleFacetInstallConfig osgiBundleFacetInstallConfig = setupOSGiBundleFacetInstallConfig("customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier");
- IFacetedProject fproj = ProjectFacetsManager.create(javaProject, true, monitor);
- fproj.installProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
-
- IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
- IBundleProjectDescription description = bundleProjectService.getDescription(javaProject);
-
- checkJavaProject(javaProject, "customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier", new String[] {"javapack", "javapack1"}, description);
+ }
+
+ @Test
+ public void convertJavaProjectCustomHeaders() throws Exception {
+
+ IProject javaProject = importProjectInWorkspace(JAVA_PRJ_COPY_LOCATION, JAVA_PRJ_COPY_NAME);
+ OSGiBundleFacetInstallConfig osgiBundleFacetInstallConfig = setupOSGiBundleFacetInstallConfig("customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier");
+ IFacetedProject fproj = ProjectFacetsManager.create(javaProject, true, monitor);
+ fproj.installProjectFacet(OSGiBundleFacetUtils.OSGI_BUNDLE_FACET_42, osgiBundleFacetInstallConfig, monitor);
+
+ IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ IBundleProjectDescription description = bundleProjectService.getDescription(javaProject);
+
+ checkJavaProject(javaProject, "customSymbolicName", "CustomBundleName", "customVendor", "1.0.1.qualifier", new String[] {"javapack", "javapack1"}, description);
}
@Test
@@ -173,6 +203,7 @@ public class WabConversionTest {
checkWebProject(webProject, WEB_PRJ_NAME, "TestWeb", null, "1.0.0.qualifier", new String[] {"test", "test1"}, "/" + WEB_PRJ_NAME, description);
}
+
@Test
public void convertJPAProject() throws Exception {
IProject jpaProject = importProjectInWorkspace(JPA_PRJ_LOCATION, JPA_PRJ_NAME);
@@ -183,7 +214,18 @@ public class WabConversionTest {
checkJPAProject(jpaProject, JPA_PRJ_NAME, "TestJPA", null, "1.0.0.qualifier", new String[] {"test"}, description);
}
-
+
+ @Test
+ public void convertJPAProjectWithUtilityFacet() throws Exception {
+ IProject jpaProject = importProjectInWorkspace(JPA_UTILITY_PRJ_LOCATION, JPA_UTILITY_PRJ_NAME);
+ new ConvertProjectsToBundlesOperation(new IProject[]{jpaProject}).run(monitor);
+
+ IBundleProjectService bundleProjectService = Activator.getDefault().getBundleProjectService();
+ IBundleProjectDescription description = bundleProjectService.getDescription(jpaProject);
+
+ checkJPAProject(jpaProject, JPA_UTILITY_PRJ_NAME, "TestJPAwithUtility", null, "1.0.0.qualifier", new String[] {"test"}, description);
+ }
+
@Test
public void convertWebProjectCustomHeders() throws Exception {
IProject webProject = importProjectInWorkspace(WEB_PRJ_COPY_LOCATION, WEB_PRJ_COPY_NAME);
@@ -280,7 +322,8 @@ public class WabConversionTest {
Assert.assertFalse(hasBuildSpec(simpleProject, PDE.SCHEMA_BUILDER_ID));
IFile buildPropertiesFile = simpleProject.getFile(OSGiBundleFacetUtils.BUILD_PROPERTIES);
Assert.assertFalse(buildPropertiesFile.exists());
- }
+ }
+
private void checkWebProject(IProject project, String expectedSymbolicName, String expectedBundleName, String expectedVendor, String expectedVersion, String[] expectedPackageExports, String expectedWebContextPath, IBundleProjectDescription description) throws JavaModelException {
checkJavaProject(project, expectedSymbolicName, expectedBundleName, expectedVendor, expectedVersion, expectedPackageExports, description);
@@ -307,7 +350,17 @@ public class WabConversionTest {
Assert.assertNull(bundleClasspath[0].getBinaryPath());
Assert.assertEquals("src/", bundleClasspath[0].getSourcePath().toPortableString());
IPath outputFolder = description.getDefaultOutputFolder();
- Assert.assertEquals("build/classes", outputFolder.toString());
+ Assert.assertEquals("build/classes", outputFolder.toString());
+ checkMetaInf(project);
+ }
+
+ private void checkMetaInf(IProject project) {
+ Assert.assertTrue(project.getFolder("/META-INF/").exists());
+ Assert.assertTrue(project.getFile("/META-INF/MANIFEST.MF").exists());
+ Assert.assertTrue(project.getFile("/META-INF/persistence.xml").exists());
+ Assert.assertFalse(project.getFolder("/src/META-INF/").exists());
+ Assert.assertFalse(project.getFile("/src/META-INF/MANIFEST.MF").exists());
+ Assert.assertFalse(project.getFile("/src/META-INF/persistence.xml").exists());
}
private void checkJavaProject(IProject project, String expectedSymbolicName, String expectedBundleName, String expectedVendor, String expectedVersion, String[] expectedPackageExports, IBundleProjectDescription description) throws JavaModelException {
@@ -417,6 +470,16 @@ public class WabConversionTest {
}
}
return false;
- }
-
-}
+ }
+
+ private HashSet<IProjectFacetVersion> getFacets(String[] facetNames) {
+ HashSet<IProjectFacetVersion> facets = new HashSet<IProjectFacetVersion>();
+ for(int i=0; i<facetNames.length; i++) {
+ IProjectFacet aFacet = ProjectFacetsManager.getProjectFacet(facetNames[i]);
+ IProjectFacetVersion aFacetVersion = aFacet.getDefaultVersion();
+ facets.add(aFacetVersion);
+ }
+ return facets;
+ }
+
+} \ No newline at end of file