Author: max.andersen(a)jboss.com
Date: 2008-01-17 15:14:50 -0500 (Thu, 17 Jan 2008)
New Revision: 5781
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.classpath
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.project
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/build.properties
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/ELTransformerTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateJDTuiTestPlugin.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JDTuiAllTests.java
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/testresources/
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/testresources/ejb3-persistence.jar
Modified:
trunk/hibernatetools/features/org.hibernate.eclipse.test.feature/feature.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLExpressionCompilerParticipant.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLProblem.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1533
HQL validation now "ignores" EL expressions by replacing #{bla blah} with
:_bla_bla_ so it looks like a named parameter.
+ proper tests.
Modified: trunk/hibernatetools/features/org.hibernate.eclipse.test.feature/feature.xml
===================================================================
---
trunk/hibernatetools/features/org.hibernate.eclipse.test.feature/feature.xml 2008-01-17
20:13:53 UTC (rev 5780)
+++
trunk/hibernatetools/features/org.hibernate.eclipse.test.feature/feature.xml 2008-01-17
20:14:50 UTC (rev 5781)
@@ -23,4 +23,11 @@
install-size="0"
version="0.0.0"/>
+ <plugin
+ id="org.hibernate.eclipse.jdt.ui.test"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/META-INF/MANIFEST.MF 2008-01-17
20:13:53 UTC (rev 5780)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/META-INF/MANIFEST.MF 2008-01-17
20:14:50 UTC (rev 5781)
@@ -18,3 +18,5 @@
org.hibernate.eclipse,
org.hibernate.eclipse.console
Eclipse-LazyStart: true
+Export-Package: org.hibernate.eclipse.jdt.ui,
+ org.hibernate.eclipse.jdt.ui.internal
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/ELTransformer.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,27 @@
+package org.hibernate.eclipse.jdt.ui.internal;
+
+public class ELTransformer {
+
+ /**
+ * transform any #{el expressions} into named parameters so HQL validation won't
fail on it.
+ * @param hql
+ * @return
+ */
+ static public String removeEL(String hql) {
+ int elStart = hql.indexOf("#{");
+ int next = hql.indexOf("}", elStart);
+
+ while(elStart!=-1 && next!=-1) {
+ String result = hql.substring(0, elStart);
+ result += ":_" + hql.substring(elStart+2,
next).replaceAll("[^\\p{javaJavaIdentifierStart}]","_") +
"_";
+ result += hql.substring(next+1);
+
+ hql = result;
+
+ elStart = hql.indexOf("#{");
+ next = hql.indexOf("}", elStart);
+ }
+
+ return hql;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java 2008-01-17
20:13:53 UTC (rev 5780)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLDetector.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -43,7 +43,7 @@
if(value instanceof StringLiteral) {
StringLiteral sl = (StringLiteral)value;
try {
- checkQuery( consoleConfiguration, sl.getLiteralValue() );
+ checkQuery( consoleConfiguration, sl.getLiteralValue(), true );
} catch(RuntimeException re) {
problems.add(new HQLProblem(re.getLocalizedMessage(), true, resource,
sl.getStartPosition(), sl.getStartPosition()+sl.getLength()-1,
getLineNumber(sl.getStartPosition())));
}
@@ -81,7 +81,7 @@
StringLiteral sl = (StringLiteral) object;
String literalValue = sl.getLiteralValue();
try {
- checkQuery( consoleConfiguration, literalValue );
+ checkQuery( consoleConfiguration, literalValue, true );
} catch(RuntimeException re) {
problems.add(new HQLProblem(re.getLocalizedMessage(), true, resource,
sl.getStartPosition(), sl.getStartPosition()+sl.getLength()-1, getLineNumber(
sl.getStartPosition() )));
}
@@ -96,14 +96,25 @@
}
}
- private void checkQuery(ConsoleConfiguration cc, String query) {
+ /**
+ * Given a ConsoleConfiguration and a query this method validates the query through
hibernate if a sessionfactory is available.
+ * @param cc
+ * @param query
+ * @param allowEL if true, EL syntax will be replaced as a named variable
+ * @throws HibernteException if something is wrong with the query
+ */
+ public static void checkQuery(ConsoleConfiguration cc, String query, boolean allowEL) {
if(cc!=null && cc.isSessionFactoryCreated()) {
+ if(allowEL) {
+ query = ELTransformer.removeEL(query);
+ }
new HQLQueryPlan(query, false, Collections.EMPTY_MAP,
(SessionFactoryImpl)cc.getSessionFactory());
} else {
//messager.printWarning( annoValue.getPosition(), "Could not verify syntax.
SessionFactory not created." );
}
}
+
public List getProblems() {
return problems;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLExpressionCompilerParticipant.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLExpressionCompilerParticipant.java 2008-01-17
20:13:53 UTC (rev 5780)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLExpressionCompilerParticipant.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -1,9 +1,5 @@
package org.hibernate.eclipse.jdt.ui.internal;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.compiler.BuildContext;
@@ -15,15 +11,13 @@
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.ProjectUtils;
-import org.hibernate.eclipse.jdt.ui.Activator;
import org.hibernate.eclipse.nature.HibernateNature;
public class HQLExpressionCompilerParticipant extends CompilationParticipant {
public HQLExpressionCompilerParticipant() {
- // TODO Auto-generated constructor stub
+
}
protected CompilationUnit parse(ICompilationUnit unit) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLProblem.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLProblem.java 2008-01-17
20:13:53 UTC (rev 5780)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.jdt.ui/src/org/hibernate/eclipse/jdt/ui/internal/HQLProblem.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -5,7 +5,7 @@
import org.eclipse.jdt.core.compiler.IProblem;
import org.hibernate.eclipse.jdt.ui.Activator;
-class HQLProblem extends CategorizedProblem implements IProblem
+public class HQLProblem extends CategorizedProblem implements IProblem
{
private int startingOffset;
private int endingOffset;
Property changes on: trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test
___________________________________________________________________
Name: svn:ignore
+ bin
Added: trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.classpath
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.classpath
(rev 0)
+++ trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.classpath 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="**/internal/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.project
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.project
(rev 0)
+++ trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/.project 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.hibernate.eclipse.jdt.ui.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/META-INF/MANIFEST.MF 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Hibernate Tools JDT integration Test Plug-in
+Bundle-SymbolicName: org.hibernate.eclipse.jdt.ui.test
+Bundle-Version: 1.0.0
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.hibernate.eclipse.console.test,
+ org.hibernate.eclipse.console,
+ org.hibernate.eclipse.jdt.ui,
+ org.hibernate.eclipse,
+ org.junit,
+ org.eclipse.core.resources,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.launching
+Eclipse-LazyStart: true
+Export-Package: org.hibernate.eclipse.jdt.ui.test
+Bundle-Activator: org.hibernate.eclipse.jdt.ui.test.HibernateJDTuiTestPlugin
Added: trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/build.properties
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/build.properties
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/build.properties 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ testresources/
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/ELTransformerTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/ELTransformerTest.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/ELTransformerTest.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,18 @@
+package org.hibernate.eclipse.jdt.ui.test;
+
+import org.hibernate.eclipse.jdt.ui.internal.ELTransformer;
+
+import junit.framework.TestCase;
+
+public class ELTransformerTest extends TestCase {
+
+ public void testTransformer() {
+
+ assertEquals("from Test", ELTransformer.removeEL("from Test"));
+ assertEquals("from Test where t.x = :_customer_id_",
ELTransformer.removeEL("from Test where t.x = #{customer.id}"));
+ assertEquals("from Test where t.x = #{customer.id",
ELTransformer.removeEL("from Test where t.x = #{customer.id"));
+ assertEquals("from Test where t.x = :_customer_id_ and x = :_id_ ",
ELTransformer.removeEL("from Test where t.x = #{customer.id} and x = #{id} "));
+ assertEquals("from Test where t.x = :_customer_id_and_x_____id_ ",
ELTransformer.removeEL("from Test where t.x = #{customer.id and x = #{id} "));
+ assertEquals("from Test where t.x = :_id_______",
ELTransformer.removeEL("from Test where t.x = #{id+-&*()}"));
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HQLQueryValidatorTest.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,175 @@
+package org.hibernate.eclipse.jdt.ui.test;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.internal.core.JavaProject;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.hibernate.HibernateException;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.KnownConfigurations;
+import
org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
+import org.hibernate.eclipse.console.EclipseConsoleConfiguration;
+import org.hibernate.eclipse.console.EclipseConsoleConfigurationPreferences;
+import org.hibernate.eclipse.console.test.HibernateConsoleTest;
+import org.hibernate.eclipse.console.test.HibernateConsoleTestPlugin;
+import org.hibernate.eclipse.console.test.SimpleTestProject;
+import org.hibernate.eclipse.console.test.xpl.JavaProjectHelper;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+import org.hibernate.eclipse.jdt.ui.internal.HQLDetector;
+import org.hibernate.eclipse.jdt.ui.internal.HQLProblem;
+
+public class HQLQueryValidatorTest extends HibernateConsoleTest {
+
+
+ private ConsoleConfiguration ccfg;
+
+ public HQLQueryValidatorTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected SimpleTestProject createTestProject() {
+ return new SimpleTestProject("hqlquerytest") {
+
+ @Override
+ protected void buildSimpleTestProject() throws JavaModelException,
+ CoreException, IOException {
+ super.buildSimpleTestProject();
+
+
+ //set up project #3: file system structure with project as source folder
+ //add an internal jar
+ File ejb3lib= HibernateJDTuiTestPlugin.getDefault().getFileInPlugin(new
Path("testresources/ejb3-persistence.jar")); //$NON-NLS-1$
+ assertTrue("ejb3 lib not found", ejb3lib != null &&
ejb3lib.exists()); //$NON-NLS-1$
+
+ JavaProjectHelper.addToClasspath(getIJavaProject(),
JavaRuntime.getDefaultJREContainerEntry());
+
+ IPackageFragmentRoot addLibraryWithImport =
JavaProjectHelper.addLibraryWithImport(getIJavaProject(),
Path.fromOSString(ejb3lib.getPath()), null, null);
+
+ assertEquals(3,getIJavaProject().getRawClasspath().length);
+
+ getIProject().getFolder("src/META-INF").create(true, true, new
NullProgressMonitor());
+ getIProject().getFile("src/META-INF/persistence.xml").create(
+ new ByteArrayInputStream(("<persistence>\n" +
+ " <persistence-unit name=\"manager1\"
transaction-type=\"RESOURCE_LOCAL\">\n" +
+ " <class>test.TestClass</class>\n" +
+ " <properties>\n" +
+ " <property name=\"hibernate.dialect\"
value=\"org.hibernate.dialect.HSQLDialect\"/>\n" +
+ " <property
name=\"hibernate.connection.driver_class\"
value=\"org.hsqldb.jdbcDriver\"/>\n" +
+ " <property
name=\"hibernate.connection.username\" value=\"sa\"/>\n" +
+ " <property
name=\"hibernate.connection.password\" value=\"\"/>\n" +
+ " <property
name=\"hibernate.connection.url\" value=\"jdbc:hsqldb:.\"/>\n"
+
+ " <property
name=\"hibernate.query.startup_check\" value=\"false\"/>\n"
+
+ " </properties>\n" +
+ " </persistence-unit>\n" +
+ "</persistence>").getBytes()),
+ false /* force */, new NullProgressMonitor());
+
+ getIProject().findMember("src/META-INF/persistence.xml");
+ getIProject().build(IncrementalProjectBuilder.FULL_BUILD, new
NullProgressMonitor());
+ }
+
+ @Override
+ protected IType buildType(IPackageFragment pack, String cuName)
+ throws JavaModelException {
+ ICompilationUnit cu = pack.createCompilationUnit(cuName,
+ "", false, null);
+
+ cu.createPackageDeclaration(pack.getElementName(),null);
+ IType type = cu.createType(
+ "(a)javax.persistence.NamedQuery(name=\"fromUnknown\",
query=\"from Unknown\")\n" +
+ "(a)javax.persistence.Entity\n" +
+ "public class " + TYPE_NAME + " {}",null,false,null);
+ type.createField("(a)javax.persistence.Id private int id;",null,false,null);
+ type.createField("private String testField;",null,false,null);
+ type.createMethod("public String getTestField() {return
this.testField;}",null,false,null);
+ type.createMethod("public void setTestField(String testField) {this.testField =
testField;}",null,false,null);
+ return type;
+ }
+ };
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+
+ super.setUp();
+
+ String prjName = getProject().getIProject().getName();
+
+ EclipseConsoleConfigurationPreferences preferences = new
EclipseConsoleConfigurationPreferences(prjName,
+ ConfigurationMode.JPA, prjName, true, null, null, null, new IPath[0], new IPath[0],
null, null);
+
+ ccfg = KnownConfigurations.getInstance().addConfiguration(new
EclipseConsoleConfiguration(preferences), false);
+
+ assertTrue(ProjectUtils.toggleHibernateOnProject(getProject().getIProject(), true,
prjName));
+
+ ccfg.build();
+ ccfg.buildSessionFactory();
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ ccfg.reset();
+ super.tearDown();
+ }
+ public void testHQLDetector() throws JavaModelException {
+
+ ASTParser parser = ASTParser.newParser( AST.JLS3 );
+ parser.setKind( ASTParser.K_COMPILATION_UNIT );
+ parser.setSource( getProject().getTestClassType().getSource().toCharArray() );
+ parser.setResolveBindings( false );
+ ASTNode node = parser.createAST( null );
+ CompilationUnit cu = null;
+ if(node instanceof CompilationUnit) {
+ cu = (CompilationUnit) node;
+ }
+ HQLDetector hqlDetector = new HQLDetector(cu, ccfg,
getProject().getTestClassType().getResource());
+ node.accept(hqlDetector);
+
+ assertEquals(1, hqlDetector.getProblems().size());
+
+ HQLProblem hqlProblem = (HQLProblem) hqlDetector.getProblems().get(0);
+ assertTrue(hqlProblem.getMessage().contains("from Unknown"));
+
+ }
+
+ public void testCheckQueryEL() {
+
+ HQLDetector.checkQuery(ccfg, "from java.lang.Object", false);
+ HQLDetector.checkQuery(ccfg, "from TestClass", false);
+
+ try {
+ HQLDetector.checkQuery(ccfg, "from TestClass where id = #{some.id.field}",
false);
+ fail("should have failed with EL expressions!");
+ } catch (HibernateException he) {
+ // ok
+ }
+
+ HQLDetector.checkQuery(ccfg, "from TestClass where id = #{some.id.field}",
true);
+ HQLDetector.checkQuery(ccfg, "from TestClass where id = #{some.id.field=}",
true);
+ HQLDetector.checkQuery(ccfg, "from TestClass where id = #{some.id and
field=}", true);
+ }
+
+
+}
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateJDTuiTestPlugin.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateJDTuiTestPlugin.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/HibernateJDTuiTestPlugin.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,68 @@
+package org.hibernate.eclipse.jdt.ui.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class HibernateJDTuiTestPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.hibernate.eclipse.jdt.ui.test";
+
+ // The shared instance
+ private static HibernateJDTuiTestPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public HibernateJDTuiTestPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static HibernateJDTuiTestPlugin getDefault() {
+ return plugin;
+ }
+
+ public File getFileInPlugin(IPath path) throws CoreException {
+ try {
+ URL installURL= new URL(getBundle().getEntry("/"), path.toString());
+ URL localURL= FileLocator.toFileURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, getBundle().getSymbolicName(),
IStatus.ERROR, e.getMessage(), e));
+ }
+ }
+}
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JDTuiAllTests.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JDTuiAllTests.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/src/org/hibernate/eclipse/jdt/ui/test/JDTuiAllTests.java 2008-01-17
20:14:50 UTC (rev 5781)
@@ -0,0 +1,18 @@
+package org.hibernate.eclipse.jdt.ui.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class JDTuiAllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Test for org.hibernate.eclipse.jdt.ui.test");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(HQLQueryValidatorTest.class);
+ suite.addTestSuite(ELTransformerTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/testresources/ejb3-persistence.jar
===================================================================
(Binary files differ)
Property changes on:
trunk/hibernatetools/tests/org.hibernate.eclipse.jdt.ui.test/testresources/ejb3-persistence.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream