| /******************************************************************************* |
| * Copyright (c) 2009 Oracle. All rights reserved. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v1.0, which accompanies this distribution |
| * and is available at http://www.eclipse.org/legal/epl-v10.html. |
| * |
| * Contributors: |
| * Oracle - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.jpt.eclipselink.core.tests.internal.context; |
| |
| import org.eclipse.jpt.core.JptCorePlugin; |
| import org.eclipse.jpt.core.internal.facet.JpaFacetInstallDataModelProperties; |
| import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties; |
| import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProvider; |
| import org.eclipse.jpt.core.resource.xml.JpaXmlResource; |
| import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; |
| import org.eclipse.jpt.eclipselink.core.internal.operations.EclipseLinkOrmFileCreationDataModelProvider; |
| import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; |
| import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
| |
| @SuppressWarnings("nls") |
| public class EclipseLinkJpaProjectTests extends EclipseLinkContextModelTestCase |
| { |
| |
| public EclipseLinkJpaProjectTests(String name) { |
| super(name); |
| } |
| |
| |
| @Override |
| protected IDataModel buildJpaConfigDataModel() { |
| IDataModel dataModel = super.buildJpaConfigDataModel(); |
| // don't build orm.xml |
| dataModel.setProperty(JpaFacetInstallDataModelProperties.CREATE_ORM_XML, Boolean.FALSE); |
| return dataModel; |
| } |
| |
| public void testGetDefaultOrmXmlResource() throws Exception { |
| JpaXmlResource resource = this.getJpaProject().getDefaultOrmXmlResource(); |
| assertNull(resource); |
| |
| //add the orm.xml file with eclipselink orm content type |
| createDefaultOrmXmlFileWithEclipseLinkContentType(); |
| resource = this.getJpaProject().getDefaultOrmXmlResource(); |
| assertNotNull(resource); |
| assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); |
| |
| |
| //delete the orm.xml file and verify it is not returned from getDefaultOrmXmlResource() |
| resource.delete(null); |
| resource = this.getJpaProject().getDefaultOrmXmlResource(); |
| assertNull(resource); |
| |
| |
| //add the orm.xml file this time with orm content type |
| createDefaultOrmXmlFile(); |
| resource = this.getJpaProject().getDefaultOrmXmlResource(); |
| assertNotNull(resource); |
| assertEquals(JptCorePlugin.ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/orm.xml", resource.getFile().getProjectRelativePath().toString()); |
| } |
| |
| public void testGetDefaultEclipseLinkOrmXmlResource() throws Exception { |
| JpaXmlResource resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); |
| assertNull(resource); |
| |
| //add the eclipselink-orm.xml file |
| createDefaultEclipseLinkOrmXmlFile(); |
| resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); |
| assertNotNull(resource); |
| assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); |
| |
| |
| //delete the eclipselink-orm.xml file and verify it is not returned from getDefaultOrmXmlResource() |
| resource.delete(null); |
| resource = this.getJpaProject().getDefaultEclipseLinkOrmXmlResource(); |
| assertNull(resource); |
| } |
| |
| private void createDefaultOrmXmlFile() throws Exception { |
| IDataModel config = |
| DataModelFactory.createDataModel(new OrmFileCreationDataModelProvider()); |
| config.setProperty(OrmFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName()); |
| config.getDefaultOperation().execute(null, null); |
| } |
| |
| private void createDefaultOrmXmlFileWithEclipseLinkContentType() throws Exception { |
| createEclipseLinkOrmXmlFile(JptCorePlugin.DEFAULT_ORM_XML_FILE_PATH); |
| } |
| |
| private void createDefaultEclipseLinkOrmXmlFile() throws Exception { |
| createEclipseLinkOrmXmlFile(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH); |
| } |
| |
| private void createEclipseLinkOrmXmlFile(String filePath) throws Exception { |
| IDataModel config = |
| DataModelFactory.createDataModel(new EclipseLinkOrmFileCreationDataModelProvider()); |
| config.setProperty(OrmFileCreationDataModelProperties.PROJECT_NAME, getJpaProject().getProject().getName()); |
| config.setProperty(OrmFileCreationDataModelProperties.FILE_PATH, filePath); |
| config.getDefaultOperation().execute(null, null); |
| } |
| |
| public void testGetMappingFileResource() throws Exception { |
| JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH); |
| assertNull(resource); |
| |
| //add the eclipselink-orm.xml file |
| createDefaultEclipseLinkOrmXmlFile(); |
| resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH); |
| assertNotNull(resource); |
| assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/eclipselink-orm.xml", resource.getFile().getProjectRelativePath().toString()); |
| |
| //delete the eclipselink-orm.xml file and verify it is not returned from getMappingFileResource() |
| resource.delete(null); |
| resource = this.getJpaProject().getMappingFileXmlResource(JptEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH); |
| assertNull(resource); |
| } |
| |
| public void testGetDifferentlyNamedMappingFileResource() throws Exception { |
| JpaXmlResource resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); |
| assertNull(resource); |
| |
| //create the orm2.xml file |
| createEclipseLinkOrmXmlFile("META-INF/orm2.xml"); |
| resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); |
| assertNotNull(resource); |
| assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); |
| |
| //delete the orm2.xml file and verify it is not returned from getMappingFileResource() |
| resource.delete(null); |
| resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); |
| assertNull(resource); |
| |
| //add the orm2.xml file back |
| createEclipseLinkOrmXmlFile("META-INF/orm2.xml"); |
| resource = this.getJpaProject().getMappingFileXmlResource("META-INF/orm2.xml"); |
| assertNotNull(resource); |
| assertEquals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE, resource.getContentType()); |
| assertEquals("src/META-INF/orm2.xml", resource.getFile().getProjectRelativePath().toString()); |
| } |
| } |