Author: vyemialyanchyk
Date: 2010-12-27 11:54:36 -0500 (Mon, 27 Dec 2010)
New Revision: 27751
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7938 - try to fix
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/project/SimpleTestProjectWithMapping.java 2010-12-27
16:54:36 UTC (rev 27751)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.hibernate.eclipse.console.test.project;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.JavaModelException;
+
+public class SimpleTestProjectWithMapping extends SimpleTestProject {
+
+ public static final String HMB_CONTENT =
+ "<?xml version=\"1.0\"?>\n" + //$NON-NLS-1$
+ "<!DOCTYPE hibernate-mapping PUBLIC\n" + //$NON-NLS-1$
+ "\"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n" + //$NON-NLS-1$
+ "\"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd\">\n"
+ //$NON-NLS-1$
+ "<hibernate-mapping package=\"" + PACKAGE_NAME +
"\">\n" + //$NON-NLS-1$ //$NON-NLS-2$
+ "<class name=\"" + TYPE_NAME + "\">\n" +
//$NON-NLS-1$ //$NON-NLS-2$
+ "<id type=\"java.lang.Long\"/>\n" + //$NON-NLS-1$
+ "<property name=\"testField\"/>\n" + //$NON-NLS-1$
+ "</class>\n" + //$NON-NLS-1$
+ "</hibernate-mapping>\n"; //$NON-NLS-1$
+
+ public SimpleTestProjectWithMapping(String projName) {
+ super(projName);
+ }
+
+ @Override
+ protected void buildProject() throws JavaModelException, CoreException, IOException {
+ super.buildProject();
+ final String path = SRC_FOLDER + "/" + //$NON-NLS-1$
+ PACKAGE_NAME + "/" + //$NON-NLS-1$
+ TYPE_NAME + ".hbm.xml"; //$NON-NLS-1$
+ getIProject().getFile(path).create(
+ new ByteArrayInputStream(HMB_CONTENT.getBytes()),
+ false, new NullProgressMonitor());
+ getIProject().findMember(path);
+ getIProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
+
+}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorTest.java 2010-12-27
14:56:16 UTC (rev 27750)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorTest.java 2010-12-27
16:54:36 UTC (rev 27751)
@@ -12,6 +12,8 @@
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
@@ -19,13 +21,15 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.ui.IEditorPart;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.QueryInputModel;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
-import org.hibernate.eclipse.console.test.project.ConfigurableTestProject;
+import org.hibernate.eclipse.console.test.project.SimpleTestProject;
+import org.hibernate.eclipse.console.test.project.SimpleTestProjectWithMapping;
import org.hibernate.eclipse.console.test.project.TestProject;
import org.hibernate.eclipse.console.test.utils.ConsoleConfigUtils;
@@ -35,53 +39,60 @@
*/
public class CriteriaEditorTest extends TestCase {
- private static final String PROJ_NAME = "CriteriaTest";
+ private static final String PROJ_NAME = "CriteriaTest"; //$NON-NLS-1$
private static final String CONSOLE_NAME = PROJ_NAME;
- private ConfigurableTestProject project = null;
+ private SimpleTestProjectWithMapping project = null;
protected void setUp() throws Exception {
- project = new ConfigurableTestProject(PROJ_NAME);
}
protected void tearDown() throws Exception {
- project.deleteIProject();
- project = null;
+ cleanUpProject();
}
+ protected void cleanUpProject() {
+ if (project != null) {
+ project.deleteIProject();
+ project = null;
+ }
+ }
+
public void testCriteriaEditorOpen(){
IEditorPart editorPart = HibernateConsolePlugin.getDefault()
- .openCriteriaEditor(null, "");
- assertNotNull("Criteria Editor was not opened", editorPart);
- assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof
CriteriaEditor);
+ .openCriteriaEditor(null, ""); //$NON-NLS-1$
+ assertNotNull("Criteria Editor was not opened", editorPart); //$NON-NLS-1$
+ assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof
CriteriaEditor); //$NON-NLS-1$
CriteriaEditor editor = (CriteriaEditor)editorPart;
QueryInputModel model = editor.getQueryInputModel();
- assertNotNull("Model is NULL", model);
+ assertNotNull("Model is NULL", model); //$NON-NLS-1$
}
public void testCriteriaCodeCompletion() throws CoreException, NoSuchFieldException,
IllegalAccessException, IOException{
+ cleanUpProject();
+ project = new SimpleTestProjectWithMapping(PROJ_NAME);
+
+ IPackageFragmentRoot sourceFolder = project.createSourceFolder();
+ IPackageFragment pf =
sourceFolder.createPackageFragment(SimpleTestProject.PACKAGE_NAME, false, null);
+ ConsoleConfigUtils.customizeCfgXmlForPack(pf);
+ List<IPath> libs = new ArrayList<IPath>();
+ project.generateClassPath(libs, sourceFolder);
+ project.fullBuild();
+
//setup console configuration
IPath cfgFilePath = new Path(project.getIProject().getName() + File.separator +
- TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
+ TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
ConsoleConfigUtils.createConsoleConfig(PROJ_NAME, cfgFilePath, CONSOLE_NAME);
- boolean createListRes = project.createTestFoldersList();
- assertTrue(createListRes);
- project.setupNextTestFolder();
-
- IPackageFragment packFragment = project.getCurrentPackage();
- assertNotNull(packFragment);
- ConsoleConfigUtils.customizeCfgXmlForPack(packFragment);
- project.fullBuild();
-
ConsoleConfiguration cc = KnownConfigurations.getInstance().find(CONSOLE_NAME);
- assertNotNull("Console Configuration not found", cc);
+ assertNotNull("Console Configuration not found", cc); //$NON-NLS-1$
+ cc.build();
- String query = "Object o = new Object();\n" +
- "System.out.print(o.toString());";
+ String query = "Object o = new Object();\n" + //$NON-NLS-1$
+ "System.out.print(o.toString());"; //$NON-NLS-1$
IEditorPart editorPart = HibernateConsolePlugin.getDefault()
.openCriteriaEditor(CONSOLE_NAME, query);
- assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof
CriteriaEditor);
+ assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof
CriteriaEditor); //$NON-NLS-1$
CriteriaEditor editor = (CriteriaEditor)editorPart;
assertEquals(editor.getEditorText(), query);
@@ -89,12 +100,14 @@
QueryInputModel model = editor.getQueryInputModel();
assertTrue(model.getParameterCount() == 0);
+ editor.setConsoleConfigurationName(CONSOLE_NAME);
+
JavaCompletionProcessor processor = new JavaCompletionProcessor(editor);
- int position = query.indexOf("toString()");
+ int position = query.indexOf("toString()"); //$NON-NLS-1$
ICompletionProposal[] proposals = processor.computeCompletionProposals(null,
position);
- assertTrue("Class java.lang.Object has at least 9 methods. But " +
proposals.length
- + " code completion proposals where provided.", proposals.length >= 9);
+ assertTrue("Class java.lang.Object has at least 9 methods. But " +
proposals.length //$NON-NLS-1$
+ + " code completion proposals where provided.", proposals.length >= 9);
//$NON-NLS-1$
cc.reset();
}