Author: dgeraskov
Date: 2008-01-21 05:29:48 -0500 (Mon, 21 Jan 2008)
New Revision: 5821
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1571
Test that highlight region length more then zero.
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2008-01-21
09:38:48 UTC (rev 5820)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2008-01-21
10:29:48 UTC (rev 5821)
@@ -11,12 +11,18 @@
package org.hibernate.eclipse.console.test.mappingproject;
import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.TestCase;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.hibernate.InvalidMappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
@@ -77,6 +83,8 @@
Throwable ex = null;
try {
editor = OpenMappingAction.run(compositeProperty, parentProperty, consCFG);
+ boolean highlighted = ProjectUtil.checkHighlighting(editor);
+ if (!highlighted) fail("Highlighted region for " +
compositeProperty.getNodeName() + " is empty.");
Object[] compProperties = new
PropertyWorkbenchAdapter().getChildren(compositeProperty);
for (int k = 0; k < compProperties.length; k++) {
//test Composite properties
@@ -101,7 +109,8 @@
Throwable ex = null;
try {
editor = OpenMappingAction.run(selection, consCFG);
- //checkSelectionMade(editor);
+ boolean highlighted = ProjectUtil.checkHighlighting(editor);
+ if (!highlighted) fail("Highlighted region for " + selection + " is
empty.");
} catch (PartInitException e) {
ex = e;
} catch (JavaModelException e) {
@@ -113,6 +122,8 @@
if (ex != null) fail("Mapping file for " + selection/*.getClassName()*/
+ " not opened:\n" + ex.getMessage());
}
+
+
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2008-01-21
09:38:48 UTC (rev 5820)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2008-01-21
10:29:48 UTC (rev 5821)
@@ -21,7 +21,6 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
-import org.hibernate.eclipse.console.actions.OpenMappingAction;
import org.hibernate.eclipse.console.actions.OpenSourceAction;
import org.hibernate.eclipse.console.workbench.ConfigurationWorkbenchAdapter;
import org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter;
@@ -91,6 +90,8 @@
try {
editor = new OpenSourceAction().run(selection,
MappingTestProject.getTestProject().getIJavaProject(),
fullyQualifiedName);
+ boolean highlighted = ProjectUtil.checkHighlighting(editor);
+ if (!highlighted) fail("Highlighted region for " + selection + " is
empty.");
} catch (PartInitException e) {
ex = e;
} catch (JavaModelException e) {
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java 2008-01-21
09:38:48 UTC (rev 5820)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java 2008-01-21
10:29:48 UTC (rev 5821)
@@ -11,6 +11,8 @@
package org.hibernate.eclipse.console.test.mappingproject;
import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.tools.ant.filters.StringInputStream;
import org.eclipse.core.resources.IFile;
@@ -22,8 +24,12 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.internal.ErrorEditorPart;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.wizards.ConsoleConfigurationCreationWizard;
import org.hibernate.mapping.PersistentClass;
@@ -152,5 +158,41 @@
}
return null;
}
+
+ public static boolean checkHighlighting(IEditorPart editor){
+ ITextEditor[] tEditors = getTextEditors(editor);
+ boolean highlighted = false;
+ for (int i = 0; i < tEditors.length && !highlighted; i++) {
+ ITextEditor textEditor = tEditors[i];
+ ISelection selection = textEditor.getSelectionProvider().getSelection();
+ if (selection instanceof TextSelection){
+ TextSelection tSelection = (TextSelection)selection;
+ highlighted = tSelection.getLength() > 0;
+ }
+ }
+ return highlighted;
+ }
+
+
+ /**
+ * Should be identical with OpenMappingAction.getTextEditors()
+ * @param editorPart
+ * @return
+ */
+ public static ITextEditor[] getTextEditors(IEditorPart editorPart) {
+ if (editorPart instanceof MultiPageEditorPart) {
+ List testEditors = new ArrayList();
+ IEditorPart[] editors = ((MultiPageEditorPart)
editorPart).findEditors(editorPart.getEditorInput());
+ for (int i = 0; i < editors.length; i++) {
+ if (editors[i] instanceof ITextEditor){
+ testEditors.add(editors[i]);
+ }
+ }
+ return (ITextEditor[])testEditors.toArray(new ITextEditor[0]);
+ } else if (editorPart instanceof ITextEditor){
+ return new ITextEditor[]{(ITextEditor) editorPart};
+ }
+ return new ITextEditor[0];
+ }
}