Author: dgeraskov
Date: 2008-01-16 05:36:39 -0500 (Wed, 16 Jan 2008)
New Revision: 5732
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
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
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java 2008-01-16
08:19:43 UTC (rev 5731)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingDiagrammTest.java 2008-01-16
10:36:39 UTC (rev 5732)
@@ -10,15 +10,12 @@
******************************************************************************/
package org.hibernate.eclipse.console.test.mappingproject;
-import java.lang.reflect.Field;
-
import junit.framework.TestCase;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.internal.ErrorEditorPart;
+import org.hibernate.InvalidMappingException;
+import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
@@ -32,25 +29,37 @@
*
*/
public class OpenMappingDiagrammTest extends TestCase {
- public void testOpenMappingDiagramm() throws Throwable{
+ public void testOpenMappingDiagramm() {
KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
final ConsoleConfiguration consCFG =
knownConfigurations.find(ProjectUtil.ConsoleCFGName);
assertNotNull(consCFG);
consCFG.reset();
- Object[] configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
- Object[] persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ Object[] configs = null;
+ Object[] persClasses = null;
+ try {
+ configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
+ assertTrue(configs[0] instanceof Configuration);
+ persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ } catch (InvalidMappingException ex){
+ fail("Mapping Diagramms for package " +
HibernateAllMappingTests.getActivePackage().getElementName()
+ + " can't be opened:\n " + ex.getMessage());
+ }
+
if (persClasses.length > 0){
for (int i = 0; i < persClasses.length; i++) {
assertTrue(persClasses[0] instanceof PersistentClass);
PersistentClass persClass = (PersistentClass) persClasses[i];
+
+ IEditorPart editor = null;
+ Throwable ex = null;
try {
- IEditorPart editor = new OpenDiagramActionDelegate().openEditor(persClass,
consCFG);
- ProjectUtil.throwExceptionIfItOccured(editor);
+ editor = new OpenDiagramActionDelegate().openEditor(persClass, consCFG);
} catch (PartInitException e) {
- fail("Error opening Mapping Diagramm for class " +
persClass.getNodeName()
- + ".\n"+ e.getMessage());
- }
+ ex = e;
+ }
+ if (ex == null ) ex = ProjectUtil.getExceptionIfItOccured(editor);
+ if (ex != null) fail("Mapping Diagramm for " + persClass.getClassName()
+ + " not opened:\n" + ex.getMessage());
}
}
//close all editors
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-16
08:19:43 UTC (rev 5731)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenMappingFileTest.java 2008-01-16
10:36:39 UTC (rev 5732)
@@ -10,16 +10,18 @@
******************************************************************************/
package org.hibernate.eclipse.console.test.mappingproject;
+import java.io.FileNotFoundException;
+
import junit.framework.TestCase;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
+import org.hibernate.InvalidMappingException;
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;
import org.hibernate.mapping.PersistentClass;
@@ -30,21 +32,39 @@
*/
public class OpenMappingFileTest extends TestCase {
- public void testOpenMappingFileTest() throws Throwable{
+ public void testOpenMappingFileTest() {
KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
final ConsoleConfiguration consCFG =
knownConfigurations.find(ProjectUtil.ConsoleCFGName);
assertNotNull(consCFG);
consCFG.reset();
- Object[] configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
- Object[] persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ Object[] configs = null;
+ Object[] persClasses = null;
+ try {
+ configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
+ assertTrue(configs[0] instanceof Configuration);
+ persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ } catch (InvalidMappingException ex){
+ fail("Mapping Files for package " +
HibernateAllMappingTests.getActivePackage().getElementName()
+ + " can't be opened:\n " + ex.getMessage());
+ }
if (persClasses.length > 0){
for (int i = 0; i < persClasses.length; i++) {
assertTrue(persClasses[0] instanceof PersistentClass);
PersistentClass persClass = (PersistentClass) persClasses[i];
- IEditorPart editor = OpenMappingAction.run(persClass, consCFG);
- if (editor == null) fail("Editor not opened.");
- ProjectUtil.throwExceptionIfItOccured(editor);
+ IEditorPart editor = null;
+ Throwable ex = null;
+ try {
+ editor = OpenMappingAction.run(persClass, consCFG);
+ } catch (PartInitException e) {
+ ex = e;
+ } catch (JavaModelException e) {
+ ex = e;
+ } catch (FileNotFoundException e) {
+ ex = e;
+ }
+ if (ex == null ) ex = ProjectUtil.getExceptionIfItOccured(editor);
+ if (ex != null) fail("Mapping file for " + persClass.getClassName()
+ + " not opened:\n" + ex.getMessage());
}
}
//close all editors
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-16
08:19:43 UTC (rev 5731)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/OpenSourceFileTest.java 2008-01-16
10:36:39 UTC (rev 5732)
@@ -10,44 +10,63 @@
******************************************************************************/
package org.hibernate.eclipse.console.test.mappingproject;
+import java.io.FileNotFoundException;
+
+import junit.framework.TestCase;
+
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
+import org.hibernate.InvalidMappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
-import org.hibernate.console.execution.ExecutionContext;
-import org.hibernate.eclipse.console.actions.OpenFileActionUtils;
import org.hibernate.eclipse.console.actions.OpenSourceAction;
import org.hibernate.eclipse.console.workbench.ConfigurationWorkbenchAdapter;
import org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter;
import org.hibernate.mapping.PersistentClass;
-import junit.framework.TestCase;
-
/**
* @author Dmitry Geraskov
*
*/
public class OpenSourceFileTest extends TestCase {
- public void testOpenSourceFileTest() throws Throwable{
+ public void testOpenSourceFileTest() {
//fail("test fail");
KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
final ConsoleConfiguration consCFG =
knownConfigurations.find(ProjectUtil.ConsoleCFGName);
assertNotNull(consCFG);
consCFG.reset();
- Object[] configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
- assertTrue(configs[0] instanceof Configuration);
- Object[] persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ Object[] configs = null;
+ Object[] persClasses = null;
+ try {
+ configs = new ConsoleConfigurationWorkbenchAdapter().getChildren(consCFG);
+ assertTrue(configs[0] instanceof Configuration);
+ persClasses = new ConfigurationWorkbenchAdapter().getChildren(configs[0]);
+ } catch (InvalidMappingException ex){
+ fail("Source files for package " +
HibernateAllMappingTests.getActivePackage().getElementName()
+ + " can't be opened:\n " + ex.getMessage());
+ }
if (persClasses.length > 0){
for (int i = 0; i < persClasses.length; i++) {
assertTrue(persClasses[0] instanceof PersistentClass);
PersistentClass persClass = (PersistentClass) persClasses[i];
- IEditorPart editor = new OpenSourceAction().run(persClass,
MappingTestProject.getTestProject().getIJavaProject(),
- persClass.getClassName());
- if (editor == null) fail("Editor not opened.");
- ProjectUtil.throwExceptionIfItOccured(editor);
+ IEditorPart editor = null;
+ Throwable ex = null;
+ try {
+ editor = new OpenSourceAction().run(persClass,
MappingTestProject.getTestProject().getIJavaProject(),
+ persClass.getClassName());
+ } catch (PartInitException e) {
+ ex = e;
+ } catch (JavaModelException e) {
+ ex = e;
+ } catch (FileNotFoundException e) {
+ ex = e;
+ }
+ if (ex == null ) ex = ProjectUtil.getExceptionIfItOccured(editor);
+ if (ex != null) fail("Source file for " + persClass.getClassName()
+ + " not opened:\n" + ex.getMessage());
}
}
//close all editors
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-16
08:19:43 UTC (rev 5731)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/mappingproject/ProjectUtil.java 2008-01-16
10:36:39 UTC (rev 5732)
@@ -119,9 +119,10 @@
* It gets occurred exception from the editor if it was and passes it up.
*
* @param editor
+ * @return
* @throws Throwable
*/
- public static void throwExceptionIfItOccured(IEditorPart editor) throws Throwable {
+ public static Throwable getExceptionIfItOccured(IEditorPart editor){
if (editor instanceof ErrorEditorPart){
Class<ErrorEditorPart> clazz = ErrorEditorPart.class;
Field field;
@@ -134,20 +135,21 @@
if (error instanceof IStatus) {
IStatus err_status = (IStatus) error;
if (err_status.getSeverity() == Status.ERROR){
- throw err_status.getException();
+ return err_status.getException();
}
}
// catch close means that exception occurred but we can't get it
} catch (SecurityException e) {
- throw new RuntimeException("Can't get exception from ErrorEditorPart. "
+ e.getMessage());
+ return new RuntimeException("Can't get exception from ErrorEditorPart.
" + e.getMessage());
} catch (NoSuchFieldException e) {
- throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ return new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
} catch (IllegalArgumentException e) {
- throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ return new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
} catch (IllegalAccessException e) {
- throw new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
+ return new RuntimeException("Can't get error field from ErrorEditorPart.
" + e.getMessage());
}
}
+ return null;
}
}