Author: dgeraskov
Date: 2010-05-28 05:06:52 -0400 (Fri, 28 May 2010)
New Revision: 22403
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.classpath
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.project
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jdt.core.prefs
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jpt.core.prefs
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.component
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.xml
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.hibernate.eclipse.console.prefs
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/ejb3-persistence.jar
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate-annotations.jar
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate3.jar
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/postgresql-8.4-701.jdbc3.jar
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/MANIFEST.MF
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/persistence.xml
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany1.java
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany2.java
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/ns/
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/ns/NamingStrategy.java
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/testHibernateJpaProject.launch
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaAllTests.java
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaModelTests.java
Removed:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java
Modified:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/META-INF/MANIFEST.MF
Log:
Update jpa tests
Modified:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/META-INF/MANIFEST.MF
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/META-INF/MANIFEST.MF 2010-05-28
00:34:33 UTC (rev 22402)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/META-INF/MANIFEST.MF 2010-05-28
09:06:52 UTC (rev 22403)
@@ -13,7 +13,9 @@
org.eclipse.jpt.db,
org.eclipse.jdt.core,
org.hibernate.eclipse.console.test,
- org.jboss.tools.hibernate.jpt.core
+ org.jboss.tools.hibernate.jpt.core,
+ org.jboss.tools.tests;bundle-version="2.0.0",
+ org.hibernate.eclipse;bundle-version="3.3.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.hibernate.jpt.core.test
Bundle-Activator: org.jboss.tools.hibernate.jpt.core.test.HibernateJPTuiTestPlugin
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.classpath
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.classpath
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.classpath 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
+ <attributes>
+ <attribute name="owner.project.facets" value="java"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.module.container"/>
+ <classpathentry kind="lib" path="lib/hibernate3.jar"/>
+ <classpathentry kind="lib" path="lib/ejb3-persistence.jar"/>
+ <classpathentry kind="lib"
path="lib/hibernate-annotations.jar"/>
+ <classpathentry kind="lib"
path="lib/postgresql-8.4-701.jdbc3.jar"/>
+ <classpathentry kind="output" path="build/classes"/>
+</classpath>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.project
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.project
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.project 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>testHibernateJpaProject</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.hibernate.eclipse.console.hibernateBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.hibernate.eclipse.console.hibernateNature</nature>
+ </natures>
+</projectDescription>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jdt.core.prefs
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jdt.core.prefs 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,8 @@
+#Mon May 10 13:11:51 EEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jpt.core.prefs
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jpt.core.prefs
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.jpt.core.prefs 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,3 @@
+#Mon May 10 13:11:52 EEST 2010
+eclipse.preferences.version=1
+org.eclipse.jpt.core.platform=hibernate
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.component
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.component
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.component 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="testHibernateJpaProject">
+ <wb-resource deploy-path="/" source-path="/src"/>
+ </wb-module>
+</project-modules>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,7 @@
+<root>
+ <facet id="jpt.jpa">
+ <node name="libprov">
+ <attribute name="provider-id"
value="jpa-no-op-library-provider"/>
+ </node>
+ </facet>
+</root>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.xml
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.xml
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.eclipse.wst.common.project.facet.core.xml 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="java"/>
+ <fixed facet="jst.utility"/>
+ <fixed facet="jpt.jpa"/>
+ <installed facet="java" version="1.5"/>
+ <installed facet="jst.utility" version="1.0"/>
+ <installed facet="jpt.jpa" version="1.0"/>
+</faceted-project>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.hibernate.eclipse.console.prefs
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.hibernate.eclipse.console.prefs
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/.settings/org.hibernate.eclipse.console.prefs 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,4 @@
+#Mon May 10 13:11:52 EEST 2010
+default.configuration=testHibernateJpaProject
+eclipse.preferences.version=1
+hibernate3.enabled=true
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/ejb3-persistence.jar
===================================================================
(Binary files differ)
Property changes on:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/ejb3-persistence.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate-annotations.jar
===================================================================
(Binary files differ)
Property changes on:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate-annotations.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate3.jar
===================================================================
(Binary files differ)
Property changes on:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/hibernate3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/postgresql-8.4-701.jdbc3.jar
===================================================================
(Binary files differ)
Property changes on:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/lib/postgresql-8.4-701.jdbc3.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/MANIFEST.MF
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/MANIFEST.MF
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/MANIFEST.MF 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/persistence.xml
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/persistence.xml
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/META-INF/persistence.xml 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
+ <persistence-unit name="testHibernateJpaProject">
+ <class>entity.ManyToMany2</class>
+ <class>entity.ManyToMany1</class>
+ </persistence-unit>
+</persistence>
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany1.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany1.java
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany1.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,20 @@
+package entity;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+@Entity
+public class ManyToMany1 implements Serializable {
+
+ @Id
+ private int id1;
+
+ private String justData1;
+
+ @ManyToMany(mappedBy = "mtm1")
+ private Set<ManyToMany2> mtm2;
+}
\ No newline at end of file
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany2.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany2.java
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/entity/ManyToMany2.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,29 @@
+package entity;
+
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Column;
+import javax.persistence.Table;
+import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.annotations.NamedQuery;
+
+@Entity
+@Table(name = "ManyToMany22")
+@NamedQuery(name = "my_query", query = "select all from my_table")
+public class ManyToMany2 implements Serializable {
+
+ @Id
+ @Column(name = "id")
+ @GenericGenerator(name = "my_generator", strategy = "hilo")
+ private int id2;
+
+ @Column(name = "justData")
+ private String justData2;
+
+ @ManyToMany
+ private Set<ManyToMany1> mtm1;
+}
\ No newline at end of file
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/ns/NamingStrategy.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/ns/NamingStrategy.java
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/src/ns/NamingStrategy.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,69 @@
+package ns;
+
+import org.hibernate.cfg.DefaultNamingStrategy;
+
+public class NamingStrategy extends DefaultNamingStrategy{
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String CT_PREFIX = "ctn_";
+
+ private static final String TN_PREFIX = "tn_";
+
+ private static final String PC_PREFIX = "pc_";
+
+ private static final String CN_PREFIX = "cn_";
+
+ private static final String FK_PREFIX = "fk_";
+
+ private static final String COL_PREFIX = "col_";
+
+ private static final String JKCN_PREFIX = "jkcn_";
+
+ @Override
+ public String classToTableName(String className) {
+ return CT_PREFIX + unqualify(className);
+ }
+
+ public String propertyToColumnName(String propertyName) {
+ return PC_PREFIX + unqualify(propertyName);
+ }
+
+ @Override
+ public String tableName(String tableName) {
+ return TN_PREFIX + tableName;
+ }
+
+ @Override
+ public String collectionTableName(String ownerEntity,
+ String ownerEntityTable, String associatedEntity,
+ String associatedEntityTable, String propertyName) {
+ return COL_PREFIX + unqualify(ownerEntity) + "_"+ associatedEntity+
"_" +
+ associatedEntityTable + "_" + unqualify( associatedEntity ) +
+ "_" +propertyName;
+ }
+
+ @Override
+ public String columnName(String columnName) {
+ return CN_PREFIX + columnName;
+ }
+
+ @Override
+ public String joinKeyColumnName(String joinedColumn, String joinedTable) {
+ return JKCN_PREFIX + joinedColumn + '_' + joinedTable;
+ }
+
+ @Override
+ public String foreignKeyColumnName(String propertyName,
+ String propertyEntityName, String propertyTableName,
+ String referencedColumnName) {
+ return FK_PREFIX + propertyName + "_"+ unqualify(propertyEntityName)
+ + "_" + propertyTableName + "_" + referencedColumnName;
+ }
+
+ private String unqualify(String s) {
+ if (s != null) return s;//.replaceAll("\\.", "");
+ return "null";
+ }
+
+}
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/testHibernateJpaProject.launch
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/testHibernateJpaProject.launch
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/res/testHibernateJpaProject/testHibernateJpaProject.launch 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="no"?>
+<launchConfiguration
type="org.hibernate.eclipse.launch.ConsoleConfigurationLaunchConfigurationType">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="testHibernateJpaProject"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH"
value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR"
value="testHibernateJpaProject"/>
+<stringAttribute key="org.hibernate.eclipse.launch.CONFIGURATION_FACTORY"
value="JPA"/>
+<listAttribute key="org.hibernate.eclipse.launch.FILE_MAPPINGS"/>
+<stringAttribute key="org.hibernate.eclipse.launchDIALECT"
value="org.hibernate.dialect.PostgreSQLDialect"/>
+<stringAttribute key="org.hibernate.eclipse.launchNAMING_STRATEGY"
value="ns.NamingStrategy"/>
+</launchConfiguration>
Deleted:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java 2010-05-28
00:34:33 UTC (rev 22402)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJPACoreTests.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -1,448 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.hibernate.jpt.core.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.util.EObjectContainmentEList;
-import org.eclipse.jpt.core.JpaAnnotationProvider;
-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.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.utility.jdt.JDTFieldAttribute;
-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.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.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.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.resource.java.GenericGeneratorAnnotationImpl;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
-
-/**
- * JUnit plugin test class for core Hibernate JPA platform
- * (org.jboss.tools.hibernate.jpt.core)
- *
- * @author Vitali Yemialyanchyk
- */
-public class HibernateJPACoreTests extends TestCase {
-
- /**
- * annotated class name
- */
- public static final String className = "TestPTR"; //$NON-NLS-1$
- /**
- * annotated package name
- */
- public static final String packageName = "org.test"; //$NON-NLS-1$
- /**
- * fully qualified name of annotated class
- */
- public static final String classFullName = packageName + "." + className;
//$NON-NLS-1$
- /**
- * annotated java file name
- */
- public static final String javaFileName = className + ".java"; //$NON-NLS-1$
- /**
- * content of annotated java file
- */
- public static final String strJava = "package " + packageName +
";\n" + //$NON-NLS-1$ //$NON-NLS-2$
- "import javax.persistence.*;\n" + //$NON-NLS-1$
- "import org.hibernate.annotations.GenericGenerator;\n" + //$NON-NLS-1$
- "@Entity\n" + //$NON-NLS-1$
- "@NamedQueries( { @NamedQuery(name = \"arName\", query = \"From
" + //$NON-NLS-1$
- className + " \") })\n" + //$NON-NLS-1$
- "public class " + className + " {\n" + //$NON-NLS-1$
//$NON-NLS-2$
- "@Id\n" + //$NON-NLS-1$
- "@GeneratedValue(generator=\"wrongGenerator\")\n" + //$NON-NLS-1$
- "private Short id_Article;\n" + //$NON-NLS-1$
- "@GenericGenerator(name=\"rightGenerator\",
strategy=\"hilo\")\n" + //$NON-NLS-1$
- "@GeneratedValue(generator=\"rightGenerator\")\n" + //$NON-NLS-1$
- "private Short id_Article2;\n" + //$NON-NLS-1$
- "public Short getId_Article(){return id_Article;}\n" + //$NON-NLS-1$
- "public Short getId_Article2(){return id_Article2;}\n" + //$NON-NLS-1$
- "}\n"; //$NON-NLS-1$
- /**
- * content of .classpath file
- */
- public static final String strClassPath = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
- "<classpath>\n" + //$NON-NLS-1$
- "<classpathentry kind=\"src\" path=\"src\"/>\n" +
//$NON-NLS-1$
- "<classpathentry kind=\"con\"
path=\"org.eclipse.jdt.launching.JRE_CONTAINER\"/>\n" + //$NON-NLS-1$
- "<classpathentry kind=\"con\"
path=\"org.eclipse.pde.core.requiredPlugins\"/>\n" + //$NON-NLS-1$
- "<classpathentry kind=\"output\" path=\"bin\"/>\n"
+ //$NON-NLS-1$
- "</classpath>\n"; //$NON-NLS-1$
-
-
- public Mockery context = new Mockery() {
- {
- setImposteriser(ClassImposteriser.INSTANCE);
- }
- };
-
- /**
- * mock input stream to simulate javaFileName file reading
- */
- public static class MockJavaInputStream extends InputStream {
-
- protected int pointer = 0;
-
- @Override
- public int read() throws IOException {
- if (pointer < strJava.getBytes().length) {
- return strJava.getBytes()[pointer++];
- }
- return -1;
- }
- }
-
- /**
- * mock input stream to simulate .classpath file reading
- */
- public static class MockClassPathInputStream extends InputStream {
-
- protected int pointer = 0;
-
- @Override
- public int read() throws IOException {
- if (pointer < strClassPath.getBytes().length) {
- return strClassPath.getBytes()[pointer++];
- }
- return -1;
- }
- }
-
- /**
- * The general goal of this test is cover org.jboss.tools.hibernate.jpt.core
- * plugin functionality, it doesn't test org.eclipse.jdt functionality,
- * so here all org.eclipse.jdt internal objects substituted with mock values.
- *
- * @throws CoreException
- * @throws IOException
- */
- public void testMockJPTCore() throws CoreException, IOException {
-
- // define/prepare mock objects for testing
- final HibernateJpaPlatformFactory hibernateJpaPlatformFactory = new
HibernateJpaPlatformFactory();
- final JpaPlatform jpaPlatform =
hibernateJpaPlatformFactory.buildJpaPlatform("hibernate"); //$NON-NLS-1$
- final String hibernatePlatformId = jpaPlatform.getId();
- 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 Persistence persistence = context.mock(Persistence.class);
- final XmlPersistenceUnit xmlPersistenceUnit = context
- .mock(XmlPersistenceUnit.class);
- final InternalEObject owner = xmlPersistenceUnit;
- // setup expectations to mock model notifications during
- // EList<XmlJavaClassRef> classes - value insertion
- context.checking(new Expectations() {
- {
- oneOf(owner).eNotificationRequired();
- will(returnValue(false));
-
- oneOf(owner).eInternalResource();
- will(returnValue(null));
- }
- });
- final String testClassName = classFullName;
- final EList<XmlJavaClassRef> classes = new
EObjectContainmentEList<XmlJavaClassRef>(
- XmlJavaClassRef.class, owner,
- PersistencePackage.XML_PERSISTENCE_UNIT__CLASSES);
- final XmlJavaClassRef xmlJavaClassRef1 = PersistenceFactory.eINSTANCE
- .createXmlJavaClassRef();
- xmlJavaClassRef1.setJavaClass(testClassName);
- // insert testClass into classes list
- classes.add(xmlJavaClassRef1);
- final EList<XmlMappingFileRef> mappingFiles = new
EObjectContainmentEList<XmlMappingFileRef>(
- XmlMappingFileRef.class, xmlPersistenceUnit,
- PersistencePackage.XML_PERSISTENCE_UNIT__MAPPING_FILES);
- //
- 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> resourceAttributesList2 = new
ArrayList<JavaResourcePersistentAttribute>();
- final JDTFieldAttribute jdtFieldAttribute = new JDTFieldAttribute(null,
- "", 1, null, null); //$NON-NLS-1$
- //final JavaResourcePersistentAttribute jrpa1 = new
JavaResourcePersistentAttributeImpl(
- // javaResourcePersistentType, jdtFieldAttribute);
- //resourceAttributesList2.add(jrpa1);
- //
- final GenericGeneratorAnnotationImpl genericGeneratorAnnotation = new
GenericGeneratorAnnotationImpl(
- javaResourcePersistentType, null, null, null);
- //
- final InputStream classPathIStream = new MockClassPathInputStream();
- final InputStream javaIStream = new MockJavaInputStream();
- //
- 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() {
- {
-
- allowing(jpaProject).getJpaPlatform();
- will(returnValue(jpaPlatform));
-
- oneOf(file).getProject();
- will(returnValue(project));
-
- allowing(project).getType();
- will(returnValue(IResource.PROJECT));
-
- oneOf(file).getFullPath();
- will(returnValue(pathProject));
-
- allowing(project).hasNature("org.eclipse.jdt.core.javanature");
//$NON-NLS-1$
- will(returnValue(true));
-
- oneOf(project).getFile(with(".classpath")); //$NON-NLS-1$
- will(returnValue(file));
-
- oneOf(file).exists();
- will(returnValue(true));
-
- oneOf(file).getContents(true);
- will(returnValue(classPathIStream));
-
- allowing(project).getFullPath();
- will(returnValue(pathProject));
-
- allowing(project).getName();
- will(returnValue("IProj")); //$NON-NLS-1$
-
- allowing(jpaProject).getModifySharedDocumentCommandExecutor();
- will(returnValue(commandExecutor));
-
- oneOf(file).getParent();
- will(returnValue(project));
-
- allowing(file).getName();
- will(returnValue(javaFileName));
-
- oneOf(project).getWorkingLocation("org.eclipse.jdt.core"); //$NON-NLS-1$
- will(returnValue(null));
-
- oneOf(project).getFile(new Path(javaFileName));
- will(returnValue(file));
-
- oneOf(file).getCharset();
- will(returnValue(null));
-
- oneOf(file).getLocation();
- will(returnValue(pathJavaFile));
-
- oneOf(file).getContents();
- will(returnValue(javaIStream));
-
- oneOf(file).getContents(true);
- will(returnValue(javaIStream));
-
- oneOf(project).getDefaultCharset();
- will(returnValue(null));
- }
- });
- // setup JptCorePlugin preferences:
- // a) setup hibernate as default jpa platform
- JptCorePlugin.setDefaultJpaPlatformId(hibernatePlatformId);
- // b) setup hibernate as jpa platform for project
- JptCorePlugin.setJpaPlatformId(project, hibernatePlatformId);
- // FIRST TEST:
- // try to build jpa file using hibernate jpa platform
- final JpaFile jpaFile = jpaPlatform.buildJpaFile(jpaProject, file);
- //
- // define/prepare mock objects for further testing
- final JavaResourceCompilationUnit javaResourceCompilationUnit = context
- .mock(JavaResourceCompilationUnit.class);
- final JpaAnnotationProvider jpaAnnotationProvider =
jpaPlatform.getAnnotationProvider();
- new GenericJpaAnnotationProvider();
- //
- final IProjectFacetActionEvent projectFacetActionEvent = context
- .mock(IProjectFacetActionEvent.class);
- final IFacetedProject facetedProject = context
- .mock(IFacetedProject.class);
- final IProjectFacet projectFacet = context.mock(IProjectFacet.class);
- // define/check jpaPlatform.getJpaFactory().buildPersistenceUnit,
- // pu.update and jpaPostInstallFasetListener.handleEvent expectations
- context.checking(new Expectations() {
- {
- allowing(xmlPersistenceUnit).getName();
- will(returnValue(className));
-
- oneOf(xmlPersistenceUnit).setName(className);
-
- allowing(xmlPersistenceUnit).getClasses();
- will(returnValue(classes));
-
- allowing(persistence).getJpaProject();
- will(returnValue(jpaProject));
-
- allowing(jpaProject).getJavaResourcePersistentType(classFullName);
- will(returnValue(javaResourcePersistentType));
-
- allowing(jpaProject).getJavaResourcePersistentType(null);
- will(returnValue(null));
-
- allowing(javaResourcePersistentType).getSupportingAnnotation(
- Hibernate.GENERIC_GENERATOR);
- will(returnValue(genericGeneratorAnnotation));
-
- allowing(javaResourcePersistentType)
- .getSuperclassQualifiedName();
- will(returnValue(null));
-
- allowing(javaResourcePersistentType).getAccess();
- will(returnValue(org.eclipse.jpt.core.resource.java.AccessType.PROPERTY));
-
- allowing(javaResourcePersistentType).getQualifiedName();
- will(returnValue(classFullName));
-
- allowing(javaResourcePersistentType).getMappingAnnotation();
- will(returnValue(null));
-
- allowing(javaResourcePersistentType).persistableProperties();
- will(returnValue(resourceAttributesList2.iterator()));
-
- allowing(xmlPersistenceUnit).getMappingFiles();
- will(returnValue(mappingFiles));
-
- allowing(jpaProject).getDefaultOrmXmlResource();
- will(returnValue(null));
-
- allowing(xmlPersistenceUnit).getProperties();
- will(returnValue(null));
-
- allowing(xmlPersistenceUnit).getJarFiles();
- will(returnValue(jarFiles));
-
- allowing(xmlPersistenceUnit).getTransactionType();
- will(returnValue(XmlPersistenceUnitTransactionType.JTA));
-
- allowing(xmlPersistenceUnit).getDescription();
- will(returnValue("description")); //$NON-NLS-1$
-
- allowing(xmlPersistenceUnit).getProvider();
- will(returnValue("provider")); //$NON-NLS-1$
-
- allowing(xmlPersistenceUnit).getJtaDataSource();
- will(returnValue("jtaDataSource")); //$NON-NLS-1$
-
- allowing(xmlPersistenceUnit).getNonJtaDataSource();
- will(returnValue("nonJtaDataSource")); //$NON-NLS-1$
-
- allowing(xmlPersistenceUnit).getExcludeUnlistedClasses();
- will(returnValue(true));
-
- oneOf(xmlPersistenceUnit).setTransactionType(
- XmlPersistenceUnitTransactionType.JTA);
-
- oneOf(xmlPersistenceUnit).setDescription("description"); //$NON-NLS-1$
-
- oneOf(xmlPersistenceUnit).setProvider("provider"); //$NON-NLS-1$
-
- oneOf(xmlPersistenceUnit).setJtaDataSource("jtaDataSource"); //$NON-NLS-1$
-
- oneOf(xmlPersistenceUnit).setNonJtaDataSource(
- "nonJtaDataSource"); //$NON-NLS-1$
-
-
- oneOf(javaResourcePersistentType).getFile();
- will(returnValue(file));
-
- oneOf(jpaProject).getJpaFile(file);
- will(returnValue(jpaFile));
-
- oneOf(xmlPersistenceUnit).setExcludeUnlistedClasses(true);
-
- allowing(jpaProject).getDefaultSchema();
- will(returnValue("schemaName")); //$NON-NLS-1$
-
- allowing(jpaProject).getDefaultCatalog();
- will(returnValue("catalogName")); //$NON-NLS-1$
-
- oneOf(projectFacetActionEvent).getType();
- will(returnValue(Type.POST_INSTALL));
-
- oneOf(projectFacetActionEvent).getProject();
- will(returnValue(facetedProject));
-
- oneOf(facetedProject).getProject();
- will(returnValue(project));
-
- oneOf(projectFacetActionEvent).getProjectFacet();
- will(returnValue(projectFacet));
-
- oneOf(projectFacet).getId();
- will(returnValue(JptCorePlugin.FACET_ID));
- }
- });
- // SECOND TEST:
- // build pu via hibernate jpa factory
- PersistenceUnit pu = jpaPlatform.getJpaFactory().buildPersistenceUnit(
- persistence, xmlPersistenceUnit);
- // THIRD TEST:
- // update persistence unit and check number of class refs
- int classRefSizeOld = pu.classRefsSize();
- pu.update(xmlPersistenceUnit);
- int classRefSizeNew = pu.classRefsSize();
- // check is the old number of ref classes remain the same after
- // pu.update call - should be the same
- assertTrue(classRefSizeOld == classRefSizeNew);
- // FOURTH TEST:
- // check for handleEvent of JPAPostInstallFasetListener
- JPAPostInstallFasetListener jpaPostInstallFasetListener = new
JPAPostInstallFasetListener();
- jpaPostInstallFasetListener.handleEvent(projectFacetActionEvent);
- // GENERAL TEST:
- // check for all expectations
- context.assertIsSatisfied();
- }
-
-}
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaAllTests.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaAllTests.java
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaAllTests.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJpaAllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.jboss.tools.hibernate.jpt.core.test"); //$NON-NLS-1$
+ suite.addTestSuite(HibernateJpaModelTests.class);
+ suite.addTestSuite(HibernateJpaModelTests.class);
+ return suite;
+ }
+
+}
Added:
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaModelTests.java
===================================================================
---
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaModelTests.java
(rev 0)
+++
branches/3.2.helios/hibernatetools/tests/org.jboss.tools.hibernate.jpt.core.test/src/org/jboss/tools/hibernate/jpt/core/test/HibernateJpaModelTests.java 2010-05-28
09:06:52 UTC (rev 22403)
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.context.JpaRootContextNode;
+import org.eclipse.jpt.core.context.java.JavaJoinTable;
+import org.eclipse.jpt.core.context.java.JavaJoinTableJoiningStrategy;
+import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
+import org.eclipse.jpt.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.core.context.java.JavaTypeMapping;
+import org.eclipse.jpt.core.context.persistence.ClassRef;
+import org.eclipse.jpt.core.context.persistence.Persistence;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaBasicMapping;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaColumn;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaIdMapping;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaJoinTable;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaManyToManyMapping;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaTable;
+import org.jboss.tools.test.util.ResourcesUtils;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJpaModelTests extends TestCase {
+
+ private static final String PROJECT_NAME = "testHibernateJpaProject";
+ private static final String PROJECT_PATH = "res/" + PROJECT_NAME;
+
+ IProject project = null;
+ JpaProject jpaProject = null;
+
+ public void setUp() throws Exception {
+ project =
ResourcesUtils.importProject(Platform.getBundle("org.jboss.tools.hibernate.jpt.core.test"),
+ PROJECT_PATH, new NullProgressMonitor());
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ }
+
+ public void testDefaultMapping(){
+ assertNotNull(jpaProject);
+ JpaRootContextNode rootContextNode = jpaProject.getRootContextNode();
+ Persistence p = rootContextNode.getPersistenceXml().getPersistence();
+ assertTrue(p.persistenceUnits().hasNext());
+ assertTrue(p.persistenceUnits().next() instanceof HibernatePersistenceUnit);
+ HibernatePersistenceUnit hpu = (HibernatePersistenceUnit) p.persistenceUnits().next();
+ List<ClassRef> crs = CollectionTools.list(hpu.classRefs());
+ assertTrue(crs.size() == 2);
+ if (crs.get(0).isFor("entity.ManyToMany1")){
+ checkManyToMany1(crs.get(0));
+ checkManyToMany2(crs.get(1));
+ } else {
+ checkManyToMany1(crs.get(1));
+ checkManyToMany2(crs.get(0));
+ }
+ }
+
+ public void testNamigStrategyMapping(){
+ ConsoleConfiguration cc = KnownConfigurations.getInstance().find(PROJECT_NAME);
+ assertNotNull("Console configuration not foun for project " + PROJECT_NAME,
cc);
+ cc.build();
+ assertNotNull("Console configuration build problem", cc.getConfiguration());
+ assertNotNull("Naming Strategy not found",
cc.getConfiguration().getNamingStrategy());
+ assertEquals("ns.NamingStrategy",
cc.getConfiguration().getNamingStrategy().getClass().getName());
+
+ jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ assertNotNull(jpaProject);
+ JpaRootContextNode rootContextNode = jpaProject.getRootContextNode();
+ Persistence p = rootContextNode.getPersistenceXml().getPersistence();
+ assertTrue(p.persistenceUnits().hasNext());
+ assertTrue(p.persistenceUnits().next() instanceof HibernatePersistenceUnit);
+ HibernatePersistenceUnit hpu = (HibernatePersistenceUnit) p.persistenceUnits().next();
+ List<ClassRef> crs = CollectionTools.list(hpu.classRefs());
+ assertTrue(crs.size() == 2);
+ if (crs.get(0).isFor("entity.ManyToMany1")){
+ checkManyToManyNS1(crs.get(0));
+ checkManyToManyNS2(crs.get(1));
+ } else {
+ checkManyToManyNS1(crs.get(1));
+ checkManyToManyNS2(crs.get(0));
+ }
+ cc.reset();
+ }
+
+ public void checkManyToMany1(ClassRef crs){
+ JavaPersistentType javaPersistentType = crs.getJavaPersistentType();
+ JavaTypeMapping mapping = javaPersistentType.getMapping();
+ assertTrue(mapping instanceof HibernateJavaEntity);
+ HibernateJavaEntity entity = (HibernateJavaEntity) mapping;
+ HibernateJavaTable table = entity.getTable();
+ assertEquals("ManyToMany1", table.getDBTableName());
+
+ ArrayList<JavaPersistentAttribute> attrs =
CollectionTools.list(javaPersistentType.attributes());
+ assertTrue(attrs.size() == 3);
+
+ //id
+ assertTrue(attrs.get(0).getMapping() instanceof HibernateJavaIdMapping);
+ HibernateJavaIdMapping hjidm = (HibernateJavaIdMapping)attrs.get(0).getMapping();
+ HibernateJavaColumn hjc = (HibernateJavaColumn)hjidm.getColumn();
+ assertEquals("id1", hjc.getDBColumnName());
+
+ //justData
+ assertTrue(attrs.get(1).getMapping() instanceof HibernateJavaBasicMapping);
+ HibernateJavaBasicMapping hjbm = (HibernateJavaBasicMapping)attrs.get(1).getMapping();
+ hjc = (HibernateJavaColumn)hjbm.getColumn();
+ assertEquals("justData1", hjc.getDBColumnName());
+
+ //mtm
+ assertTrue(attrs.get(2).getMapping() instanceof HibernateJavaManyToManyMapping);
+ HibernateJavaManyToManyMapping hjmtmm =
(HibernateJavaManyToManyMapping)attrs.get(2).getMapping();
+ assertEquals("entity.ManyToMany2", hjmtmm.getTargetEntity());
+ }
+
+ public void checkManyToMany2(ClassRef crs){
+ JavaPersistentType javaPersistentType = crs.getJavaPersistentType();
+ JavaTypeMapping mapping = javaPersistentType.getMapping();
+ assertTrue(mapping instanceof HibernateJavaEntity);
+ HibernateJavaEntity entity = (HibernateJavaEntity) mapping;
+ HibernateJavaTable table = entity.getTable();
+ assertEquals("ManyToMany22", table.getDBTableName());
+
+ ArrayList<JavaPersistentAttribute> attrs =
CollectionTools.list(javaPersistentType.attributes());
+ assertTrue(attrs.size() == 3);
+ //id
+ assertTrue(attrs.get(0).getMapping() instanceof HibernateJavaIdMapping);
+ HibernateJavaIdMapping hjidm = (HibernateJavaIdMapping)attrs.get(0).getMapping();
+ HibernateJavaColumn hjc = (HibernateJavaColumn)hjidm.getColumn();
+ assertEquals("id", hjc.getDBColumnName());
+
+ //justData
+ assertTrue(attrs.get(1).getMapping() instanceof HibernateJavaBasicMapping);
+ HibernateJavaBasicMapping hjbm = (HibernateJavaBasicMapping)attrs.get(1).getMapping();
+ hjc = (HibernateJavaColumn)hjbm.getColumn();
+ assertEquals("justData", hjc.getDBColumnName());
+
+ //mtm
+ assertTrue(attrs.get(2).getMapping() instanceof HibernateJavaManyToManyMapping);
+ HibernateJavaManyToManyMapping hjmtmm =
(HibernateJavaManyToManyMapping)attrs.get(2).getMapping();
+ assertEquals("entity.ManyToMany1", hjmtmm.getTargetEntity());
+ JavaJoinTableJoiningStrategy jtJoiningStrategy =
hjmtmm.getRelationshipReference().getJoinTableJoiningStrategy();
+ JavaJoinTable joinTable = jtJoiningStrategy.getJoinTable();
+ assertTrue(joinTable instanceof HibernateJavaJoinTable);
+ HibernateJavaJoinTable hjjt = (HibernateJavaJoinTable)joinTable;
+ assertEquals("ManyToMany22_ManyToMany1", hjjt.getDBTableName());
+ }
+
+ public void checkManyToManyNS1(ClassRef crs){
+ JavaPersistentType javaPersistentType = crs.getJavaPersistentType();
+ JavaTypeMapping mapping = javaPersistentType.getMapping();
+ assertTrue(mapping instanceof HibernateJavaEntity);
+ HibernateJavaEntity entity = (HibernateJavaEntity) mapping;
+ HibernateJavaTable table = entity.getTable();
+ assertEquals("ctn_ManyToMany1", table.getDBTableName());
+
+ ArrayList<JavaPersistentAttribute> attrs =
CollectionTools.list(javaPersistentType.attributes());
+ assertTrue(attrs.size() == 3);
+
+ //id
+ assertTrue(attrs.get(0).getMapping() instanceof HibernateJavaIdMapping);
+ HibernateJavaIdMapping hjidm = (HibernateJavaIdMapping)attrs.get(0).getMapping();
+ HibernateJavaColumn hjc = (HibernateJavaColumn)hjidm.getColumn();
+ assertEquals("pc_id1", hjc.getDBColumnName());
+
+ //justData
+ assertTrue(attrs.get(1).getMapping() instanceof HibernateJavaBasicMapping);
+ HibernateJavaBasicMapping hjbm = (HibernateJavaBasicMapping)attrs.get(1).getMapping();
+ hjc = (HibernateJavaColumn)hjbm.getColumn();
+ assertEquals("pc_justData1", hjc.getDBColumnName());
+
+ //mtm
+ assertTrue(attrs.get(2).getMapping() instanceof HibernateJavaManyToManyMapping);
+ HibernateJavaManyToManyMapping hjmtmm =
(HibernateJavaManyToManyMapping)attrs.get(2).getMapping();
+ assertEquals("entity.ManyToMany2", hjmtmm.getTargetEntity());
+ }
+
+ public void checkManyToManyNS2(ClassRef crs){
+ JavaPersistentType javaPersistentType = crs.getJavaPersistentType();
+ JavaTypeMapping mapping = javaPersistentType.getMapping();
+ assertTrue(mapping instanceof HibernateJavaEntity);
+ HibernateJavaEntity entity = (HibernateJavaEntity) mapping;
+ HibernateJavaTable table = entity.getTable();
+ assertEquals("tn_ManyToMany22", table.getDBTableName());
+
+ ArrayList<JavaPersistentAttribute> attrs =
CollectionTools.list(javaPersistentType.attributes());
+ assertTrue(attrs.size() == 3);
+ //id
+ assertTrue(attrs.get(0).getMapping() instanceof HibernateJavaIdMapping);
+ HibernateJavaIdMapping hjidm = (HibernateJavaIdMapping)attrs.get(0).getMapping();
+ HibernateJavaColumn hjc = (HibernateJavaColumn)hjidm.getColumn();
+ assertEquals("cn_id", hjc.getDBColumnName());
+
+ //justData
+ assertTrue(attrs.get(1).getMapping() instanceof HibernateJavaBasicMapping);
+ HibernateJavaBasicMapping hjbm = (HibernateJavaBasicMapping)attrs.get(1).getMapping();
+ hjc = (HibernateJavaColumn)hjbm.getColumn();
+ assertEquals("cn_justData", hjc.getDBColumnName());
+
+ //mtm
+ assertTrue(attrs.get(2).getMapping() instanceof HibernateJavaManyToManyMapping);
+ HibernateJavaManyToManyMapping hjmtmm =
(HibernateJavaManyToManyMapping)attrs.get(2).getMapping();
+ assertEquals("entity.ManyToMany1", hjmtmm.getTargetEntity());
+ JavaJoinTableJoiningStrategy jtJoiningStrategy =
hjmtmm.getRelationshipReference().getJoinTableJoiningStrategy();
+ JavaJoinTable joinTable = jtJoiningStrategy.getJoinTable();
+ assertTrue(joinTable instanceof HibernateJavaJoinTable);
+ HibernateJavaJoinTable hjjt = (HibernateJavaJoinTable)joinTable;
+ hjjt.getDbTable();
+ assertEquals("col_entity.ManyToMany2_entity.ManyToMany1_ManyToMany1_entity.ManyToMany1_mtm1",
hjjt.getDBTableName());
+ }
+
+ protected void tearDown() throws Exception {
+ if(project != null) {
+ boolean saveAutoBuild = ResourcesUtils.setBuildAutomatically(false);
+ try {
+ project.delete(true,true, null);
+ } finally {
+ ResourcesUtils.setBuildAutomatically(saveAutoBuild);
+ }
+ }
+ }
+
+}