Author: vyemialyanchyk
Date: 2009-04-17 06:57:33 -0400 (Fri, 17 Apr 2009)
New Revision: 14790
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java
Log:
JBIDE-4141
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java 2009-04-17
10:57:20 UTC (rev 14789)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java 2009-04-17
10:57:33 UTC (rev 14790)
@@ -13,9 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -24,44 +22,36 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
-import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.core.JpaAnnotationProvider;
-import org.eclipse.jpt.core.JpaFactory;
import org.eclipse.jpt.core.JpaFile;
import org.eclipse.jpt.core.JpaPlatform;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.ResourceModel;
import org.eclipse.jpt.core.context.persistence.Persistence;
import org.eclipse.jpt.core.context.persistence.PersistenceUnit;
+import org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider;
import org.eclipse.jpt.core.internal.resource.java.JavaResourcePersistentAttributeImpl;
import org.eclipse.jpt.core.internal.utility.jdt.JDTFieldAttribute;
-import org.eclipse.jpt.core.resource.java.JavaResourceModel;
+import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
-import org.eclipse.jpt.core.resource.java.JpaCompilationUnit;
-import org.eclipse.jpt.core.resource.orm.OrmArtifactEdit;
import org.eclipse.jpt.core.resource.persistence.PersistenceFactory;
import org.eclipse.jpt.core.resource.persistence.PersistencePackage;
+import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef;
import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef;
import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnitTransactionType;
-import org.eclipse.jpt.db.Catalog;
-import org.eclipse.jpt.db.ConnectionProfile;
-import org.eclipse.jpt.db.Schema;
-import org.eclipse.wst.common.componentcore.ModuleCoreNature;
-import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel;
+import org.eclipse.jpt.utility.CommandExecutor;
+import org.eclipse.jpt.utility.CommandExecutor.Default;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent;
import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent.Type;
-import org.jboss.tools.hibernate.jpt.core.internal.HibernateFactory;
-import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaAnnotationProvider;
-import org.jboss.tools.hibernate.jpt.core.internal.HibernatePlatform;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaPlatform;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaPlatformFactory;
import org.jboss.tools.hibernate.jpt.core.internal.JPAPostInstallFasetListener;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.GenericGeneratorAnnotationImpl;
@@ -133,41 +123,6 @@
};
/**
- * mock hibernate factory, redefine some methods of base GenericJpaFactory
- * to avoid unnecessary checks, which are not a subject of testing.
- */
- static public class MockHibernateFactory extends HibernateFactory {
- /**
- * during the testing our file has relevant content,
- * so just return true without dig into the base code.
- */
- public boolean hasRelevantContent(IFile file) {
- return true;
- }
- /**
- * just build resource model from JavaCore.JAVA_SOURCE_CONTENT_TYPE
- * all base code checks are unnecessary.
- */
- public ResourceModel buildResourceModel(JpaProject jpaProject,
- IFile file) {
- return buildResourceModel(jpaProject, file,
- JavaCore.JAVA_SOURCE_CONTENT_TYPE);
- }
- }
-
- /**
- * mock hibernate platform to get MockHibernateFactory
- * instead of HibernateFactory
- */
- public class MockHibernatePlatform extends HibernatePlatform {
- protected JpaFactory buildJpaFactory() {
- JpaFactory jpaFactory = super.buildJpaFactory();
- assertTrue(jpaFactory instanceof HibernateFactory);
- return new MockHibernateFactory();
- }
- }
-
- /**
* mock input stream to simulate javaFileName file reading
*/
public static class MockJavaInputStream extends InputStream {
@@ -210,23 +165,14 @@
public void testMockJPTCore() throws CoreException, IOException {
// define/prepare mock objects for testing
- final JpaPlatform jpaPlatform = new MockHibernatePlatform();
+ final HibernateJpaPlatformFactory hibernateJpaPlatformFactory = new
HibernateJpaPlatformFactory();
+ final JpaPlatform jpaPlatform =
hibernateJpaPlatformFactory.buildJpaPlatform("hibernate"); //$NON-NLS-1$
final String hibernatePlatformId = jpaPlatform.getId();
- assertTrue(HibernatePlatform.ID.equals(hibernatePlatformId));
+ assertTrue(HibernateJpaPlatform.ID.equals(hibernatePlatformId));
//
final JpaProject jpaProject = context.mock(JpaProject.class);
final IProject project = context.mock(IProject.class);
final IFile file = context.mock(IFile.class);
- final JavaResourceModel javaResourceModel = context
- .mock(JavaResourceModel.class);
- final Schema schema = context.mock(Schema.class);
- final ConnectionProfile connectionProfile = context
- .mock(ConnectionProfile.class);
- final Catalog catalog = context.mock(Catalog.class);
- final ArtifactEditModel artifactEditModel = context
- .mock(ArtifactEditModel.class);
- final ModuleCoreNature moduleCoreNature = context
- .mock(ModuleCoreNature.class);
final Persistence persistence = context.mock(Persistence.class);
final XmlPersistenceUnit xmlPersistenceUnit = context
.mock(XmlPersistenceUnit.class);
@@ -254,15 +200,14 @@
final EList<XmlMappingFileRef> mappingFiles = new
EObjectContainmentEList<XmlMappingFileRef>(
XmlMappingFileRef.class, xmlPersistenceUnit,
PersistencePackage.XML_PERSISTENCE_UNIT__MAPPING_FILES);
- final List<String> annotatedClassNamesList = new ArrayList<String>();
- final Iterator<String> annotatedClassNames = annotatedClassNamesList
- .iterator();
//
+ final EList<XmlJarFileRef> jarFiles = new
EObjectContainmentEList<XmlJarFileRef>(
+ XmlJarFileRef.class, xmlPersistenceUnit,
+ PersistencePackage.XML_PERSISTENCE_UNIT__JAR_FILES);
+ //
final JavaResourcePersistentType javaResourcePersistentType = context
.mock(JavaResourcePersistentType.class);
//
- final List<JavaResourcePersistentAttribute> resourceAttributesList1 = new
ArrayList<JavaResourcePersistentAttribute>();
- //
final List<JavaResourcePersistentAttribute> resourceAttributesList2 = new
ArrayList<JavaResourcePersistentAttribute>();
final JDTFieldAttribute jdtFieldAttribute = new JDTFieldAttribute(null,
"", 1, null, null); //$NON-NLS-1$
@@ -279,6 +224,8 @@
final IPath pathProject = new Path(""); //$NON-NLS-1$
//
final IPath pathJavaFile = new Path(javaFileName);
+ //
+ final CommandExecutor commandExecutor = Default.INSTANCE;
// define/check jpaPlatform.buildJpaFile expectations
context.checking(new Expectations() {
{
@@ -286,10 +233,6 @@
allowing(jpaProject).getJpaPlatform();
will(returnValue(jpaPlatform));
- oneOf(jpaProject)
- .getModifySharedDocumentCommandExecutorProvider();
- will(returnValue(null));
-
oneOf(file).getProject();
will(returnValue(project));
@@ -317,13 +260,13 @@
allowing(project).getName();
will(returnValue("IProj")); //$NON-NLS-1$
- allowing(jpaProject).getProject();
- will(returnValue(project));
+ allowing(jpaProject).getModifySharedDocumentCommandExecutor();
+ will(returnValue(commandExecutor));
oneOf(file).getParent();
will(returnValue(project));
- oneOf(file).getName();
+ allowing(file).getName();
will(returnValue(javaFileName));
oneOf(project).getWorkingLocation("org.eclipse.jdt.core"); //$NON-NLS-1$
@@ -338,6 +281,9 @@
oneOf(file).getLocation();
will(returnValue(pathJavaFile));
+ oneOf(file).getContents();
+ will(returnValue(javaIStream));
+
oneOf(file).getContents(true);
will(returnValue(javaIStream));
@@ -355,9 +301,10 @@
final JpaFile jpaFile = jpaPlatform.buildJpaFile(jpaProject, file);
//
// define/prepare mock objects for further testing
- final JpaCompilationUnit jpaCompilationUnit = context
- .mock(JpaCompilationUnit.class);
- final JpaAnnotationProvider jpaAnnotationProvider = new
HibernateJpaAnnotationProvider();
+ final JavaResourceCompilationUnit javaResourceCompilationUnit = context
+ .mock(JavaResourceCompilationUnit.class);
+ final JpaAnnotationProvider jpaAnnotationProvider =
jpaPlatform.getAnnotationProvider();
+ new GenericJpaAnnotationProvider();
//
final IProjectFacetActionEvent projectFacetActionEvent = context
.mock(IProjectFacetActionEvent.class);
@@ -379,34 +326,20 @@
allowing(persistence).getJpaProject();
will(returnValue(jpaProject));
- // Dali 2.0
- allowing(jpaProject).getJavaPersistentTypeResource(
- classFullName);
+ allowing(jpaProject).getJavaResourcePersistentType(classFullName);
will(returnValue(javaResourcePersistentType));
- allowing(jpaProject).getJavaPersistentTypeResource(null);
+ allowing(jpaProject).getJavaResourcePersistentType(null);
will(returnValue(null));
- // Dali 2.1
- //allowing(jpaProject).getJavaResourcePersistentType(classFullName); //$NON-NLS-1$
- // will(returnValue(factory));
-
- // Dali 2.0
- allowing(javaResourcePersistentType).getAnnotation(
- Hibernate.GENERIC_GENERATOR);
+ allowing(javaResourcePersistentType).getSupportingAnnotation(
+ Hibernate.GENERIC_GENERATOR);
will(returnValue(genericGeneratorAnnotation));
- // Dali 2.1
- // allowing(javaResourcePersistentType).getSupportingAnnotation(
- // Hibernate.GENERIC_GENERATOR);
- // will(returnValue(genericGeneratorAnnotation));
allowing(javaResourcePersistentType)
.getSuperClassQualifiedName();
will(returnValue(null));
- allowing(persistence).getOrmPersistentType();
- will(returnValue(null));
-
allowing(javaResourcePersistentType).getAccess();
will(returnValue(org.eclipse.jpt.core.resource.java.AccessType.PROPERTY));
@@ -416,60 +349,27 @@
allowing(javaResourcePersistentType).getMappingAnnotation();
will(returnValue(null));
- allowing(javaResourcePersistentType).fields();
- will(returnValue(resourceAttributesList1.iterator()));
-
- allowing(javaResourcePersistentType).properties();
+ allowing(javaResourcePersistentType).persistableProperties();
will(returnValue(resourceAttributesList2.iterator()));
- oneOf(javaResourcePersistentType).getJpaCompilationUnit();
- will(returnValue(jpaCompilationUnit));
-
- oneOf(jpaCompilationUnit).getAnnotationProvider();
+ oneOf(javaResourcePersistentType).getRoot();
+ will(returnValue(javaResourceCompilationUnit));
+
+ oneOf(javaResourceCompilationUnit).getAnnotationProvider();
will(returnValue(jpaAnnotationProvider));
- allowing(project).isAccessible();
- will(returnValue(true));
-
allowing(xmlPersistenceUnit).getMappingFiles();
will(returnValue(mappingFiles));
- allowing(project).getNature(
- "org.eclipse.wst.common.modulecore.ModuleCoreNature"); //$NON-NLS-1$
- will(returnValue(moduleCoreNature));
-
- allowing(project).isNatureEnabled(
- "org.eclipse.wst.common.project.facet.core.nature"); //$NON-NLS-1$
- will(returnValue(true));
-
- oneOf(project)
- .getFile(
- with(".settings/org.eclipse.wst.common.project.facet.core.xml"));
//$NON-NLS-1$
- will(returnValue(file));
-
- allowing(file).getModificationStamp();
- will(returnValue(-1L));
-
- allowing(moduleCoreNature).getArtifactEditModelForRead(
- with(any(URI.class)), with(any(Object.class)),
- with(any(String.class)), with(any(Map.class)));
- will(returnValue(artifactEditModel));
-
- allowing(artifactEditModel).getResource(with(any(URI.class)));
+ allowing(jpaProject).getDefaultOrmXmlResource();
will(returnValue(null));
- allowing(artifactEditModel).releaseAccess(
- with(any(OrmArtifactEdit.class)));
-
- oneOf(jpaProject).discoversAnnotatedClasses();
- will(returnValue(true));
-
- allowing(jpaProject).annotatedClassNames();
- will(returnValue(annotatedClassNames));
-
allowing(xmlPersistenceUnit).getProperties();
will(returnValue(null));
+ allowing(xmlPersistenceUnit).getJarFiles();
+ will(returnValue(jarFiles));
+
allowing(xmlPersistenceUnit).getTransactionType();
will(returnValue(XmlPersistenceUnitTransactionType.JTA));
@@ -500,32 +400,21 @@
oneOf(xmlPersistenceUnit).setNonJtaDataSource(
"nonJtaDataSource"); //$NON-NLS-1$
- oneOf(javaResourcePersistentType).getResourceModel();
- will(returnValue(javaResourceModel));
- oneOf(javaResourceModel).getFile();
- will(returnValue(null));
+ oneOf(javaResourcePersistentType).getFile();
+ will(returnValue(file));
- oneOf(jpaProject).getJpaFile(null);
+ oneOf(jpaProject).getJpaFile(file);
will(returnValue(jpaFile));
oneOf(xmlPersistenceUnit).setExcludeUnlistedClasses(true);
- oneOf(jpaProject).getDefaultSchema();
- will(returnValue(schema));
-
- allowing(jpaProject).update();
-
- oneOf(schema).getName();
+ allowing(jpaProject).getDefaultSchema();
will(returnValue("schemaName")); //$NON-NLS-1$
- oneOf(jpaProject).getConnectionProfile();
- will(returnValue(connectionProfile));
+ oneOf(jpaProject).update();
- oneOf(connectionProfile).getDefaultCatalog();
- will(returnValue(catalog));
-
- oneOf(catalog).getName();
+ allowing(jpaProject).getDefaultCatalog();
will(returnValue("catalogName")); //$NON-NLS-1$
oneOf(projectFacetActionEvent).getType();