[190496] Java EE JUnit improvements.
diff --git a/tests/org.eclipse.wst.common.tests/.classpath b/tests/org.eclipse.wst.common.tests/.classpath
index aca3569..02c53bf 100644
--- a/tests/org.eclipse.wst.common.tests/.classpath
+++ b/tests/org.eclipse.wst.common.tests/.classpath
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="commontests/"/>
- <classpathentry kind="src" path="frameworktests/"/>
- <classpathentry kind="src" path="apitools/"/>
+ <classpathentry kind="src" path="commontests"/>
+ <classpathentry kind="src" path="frameworktests"/>
+ <classpathentry kind="src" path="apitools"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.jst.j2ee"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java
new file mode 100644
index 0000000..1b7e79a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java
@@ -0,0 +1,286 @@
+package org.eclipse.wst.common.tests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+
+public class AssertWarn extends Assert {
+ private static List<AssertionFailedError> warnings = new ArrayList<AssertionFailedError>();
+
+ public static void warnEquals(boolean expected, boolean actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(byte expected, byte actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(char expected, char actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(double expected, double actual, double delta) {
+ try{
+ assertEquals(expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(float expected, float actual, float delta) {
+ try{
+ assertEquals(expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(int expected, int actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(Object expected, Object actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(long expected, long actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(short expected, short actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, boolean expected, boolean actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, byte expected, byte actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, char expected, char actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, double expected, double actual, double delta) {
+ try{
+ assertEquals(message, expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, float expected, float actual, float delta) {
+ try{
+ assertEquals(message, expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, int expected, int actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, Object expected, Object actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, String expected, String actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, long expected, long actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, short expected, short actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnFalse(boolean condition){
+ try{
+ assertFalse(condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnFalse(String message, boolean condition){
+ try{
+ assertFalse(message, condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotNull(Object object) {
+ try{
+ assertNotNull(object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotNull(String message, Object object) {
+ try{
+ assertNotNull(message, object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotSame(Object expected, Object actual) {
+ try{
+ assertNotSame(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotSame(String message, Object expected, Object actual) {
+ try{
+ assertNotSame(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNull(Object object) {
+ try{
+ assertNull(object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNull(String message, Object object) {
+ try{
+ assertNull(message, object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnSame(Object expected, Object actual) {
+ try{
+ assertSame(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnSame(String message, Object expected, Object actual) {
+ try{
+ assertSame(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnTrue(boolean condition){
+ try{
+ assertTrue(condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnTrue(String message, boolean condition){
+ try{
+ assertTrue(message, condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warn() {
+ try{
+ fail();
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warn(String message) {
+ try{
+ fail(message);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void clearWarnings(){
+ warnings.clear();
+ }
+
+ public static List <AssertionFailedError> getWarnings() {
+ return Collections.unmodifiableList(warnings);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java
index 35748e8..2b78954 100644
--- a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java
@@ -5,7 +5,16 @@
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.eclipse.wst.common.tests;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import junit.framework.TestFailure;
+import junit.framework.TestResult;
public class BaseTestCase extends TestCase {
@@ -45,4 +54,84 @@
runTest();
}
+ @Override
+ public void run(TestResult result) {
+ try{
+ AssertWarn.clearWarnings();
+ super.run(result);
+
+ } finally {
+ List <StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
+ List <AssertionFailedError> warnings = null;
+
+ //check to see if this test already failed with an error
+ //if so add error to stack trace
+ Enumeration errorsEnum = result.errors();
+ TestFailure errorOrFailure = null;
+ boolean errorForTestExists = false;
+ for(int i = 0; errorsEnum.hasMoreElements() && !errorForTestExists; i++) {
+ Object o = errorsEnum.nextElement();
+ errorOrFailure = (TestFailure)o;
+ if(errorOrFailure.failedTest() == this) {
+ errorForTestExists = true;
+
+ Throwable thrown = errorOrFailure.thrownException();
+ List<StackTraceElement> errorTrace = Arrays.asList(thrown.getStackTrace());
+ stackTrace.addAll(errorTrace);
+ }
+ }
+
+ //check to see if this test already failed with a failure if it didn't
+ // fail with an error. if so add failure to stack trace
+ boolean failureForTestExists = false;
+ if(!errorForTestExists) {
+ Enumeration failuresEnum = result.failures();
+ for(int i = 0; failuresEnum.hasMoreElements() && !failureForTestExists; i++) {
+ Object o = failuresEnum.nextElement();
+ errorOrFailure = (TestFailure)o;
+ if(errorOrFailure.failedTest() == this) {
+ failureForTestExists = true;
+
+ Throwable thrown = errorOrFailure.thrownException();
+ List<StackTraceElement> failureTrace = Arrays.asList(thrown.getStackTrace());
+ stackTrace.addAll(failureTrace);
+ }
+ }
+ }
+
+ //add any warnings to the stack trace and deal with if this test already failed
+ warnings = AssertWarn.getWarnings();
+ if(warnings.size() != 0) {
+ int warningNum = 1;
+ List<StackTraceElement> warningTrace = null;
+ for(AssertionFailedError e : warnings){
+ stackTrace.add(new StackTraceElement("---------->","", "WARNING MESSAGE: " + e.getMessage() + ") (WARNING NUMBER", warningNum++));
+
+ warningTrace = Arrays.asList(e.getStackTrace());
+ stackTrace.addAll(warningTrace);
+ }
+
+ //deal with making a new formated failure and added it to the result
+ String message = "";
+ if((errorForTestExists || failureForTestExists)) {
+ message = errorOrFailure.exceptionMessage();
+ message += " (Test also had " + warnings.size() + " warnings occure.)";
+ } else {
+ message = "Test had " + warnings.size() + " warnings occure.";
+ }
+
+ AssertionFailedError error = new AssertionFailedError(message);
+ StackTraceElement[] stackTraceArray = stackTrace.toArray(new StackTraceElement[stackTrace.size()]);
+ error.setStackTrace(stackTraceArray);
+
+ if(errorForTestExists) {
+ result.addError(this, error);
+ } else {
+ result.addFailure(this, error);
+ }
+
+ }
+ }
+ }
+
}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java
index e8e2cd2..a9b6501 100644
--- a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java
@@ -15,6 +15,7 @@
/**
* @author Administrator
+ * @author Ian Tewksbury (ictewksb@us.ibm.com)
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Generation - Code and Comments
@@ -27,7 +28,7 @@
private DataModelVerifier defaultDataModelVerifier = new DataModelVerifier();
public DataModelVerifierFactory() {
- super(CommonTestsPlugin.PLUGIN_ID, "DataModelVerifier"); //$NON-NLS-1$
+ super(CommonTestsPlugin.PLUGIN_ID, "DataModelVerifier");//$NON-NLS-1$
}
public static DataModelVerifierFactory getInstance() {
@@ -54,7 +55,7 @@
}
- protected void addToDataModelVerifiersMap(Map dataModelVerifiers){
+ public void addToDataModelVerifiersMap(Map dataModelVerifiers){
if (dataModelVerifiersMap == null)
dataModelVerifiersMap = initDataModelVerifiersMap();
dataModelVerifiersMap.putAll(dataModelVerifiers);
@@ -105,13 +106,17 @@
public DataModelVerifier createVerifier(IDataModel model) {
DataModelVerifier verifier = getDefaultDataModelVerifier();
- String verifierClassName = null;
+
if (model != null) {
- verifierClassName = (String) getDataModelVerifiersMap().get(model.getClass().getName());
- if (verifierClassName != null) {
+ Object verifierObject = getDataModelVerifiersMap().get(model.getID());
+ if(verifierObject != null){
try {
- Class verifierClass = Class.forName(verifierClassName);
- verifier = (DataModelVerifier) verifierClass.newInstance();
+ if(verifierObject instanceof Class){
+ return (DataModelVerifier)((Class)verifierObject).newInstance();
+ } else if(verifierObject instanceof String){
+ Class verifierClass = Class.forName((String)verifierObject);
+ verifier = (DataModelVerifier) verifierClass.newInstance();
+ }
} catch (Exception e) {
verifier = getDefaultDataModelVerifier();
}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java
index d4743b9..d9654c4 100644
--- a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java
@@ -27,6 +27,7 @@
/**
* @author jsholl
+ * @author itewk
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
@@ -34,24 +35,18 @@
public abstract class OperationTestCase extends BaseTestCase {
public static final String VALIDATOR_JOB_FAMILY = "validators";
-
public static String fileSep = System.getProperty("file.separator"); //$NON-NLS-1$
-
public static IStatus OK_STATUS = new Status(IStatus.OK, "org.eclipse.jem.util", 0, "OK", null); //$NON-NLS-1$ //$NON-NLS-2$
-
- // public abstract void testBVT() throws Exception;
-
+
protected void setUp() throws Exception {
super.setUp();
try{
deleteAllProjects();
- } catch (Exception e) {
- // TODO: handle exception
} finally {
RendererFactory.getDefaultRendererFactory().setValidating(false);
}
- // LogUtility.getInstance().resetLogging();
}
+
public static void deleteAllProjects() {
IWorkspaceRunnableWithStatus workspaceRunnable = new IWorkspaceRunnableWithStatus(null) {
public void run(IProgressMonitor pm) throws CoreException {
@@ -126,22 +121,27 @@
}
if (checkLog)
LogUtility.getInstance().resetLogging();
- //verifyValidDataModel(dataModel);
+
IStatus operationStatus = dataModel.getDefaultOperation().execute(new NullProgressMonitor(), null);
- // TODO Verification to be fixed to use IDataModel
- // verifyDataModel(dataModel);
+
if (waitForBuildToComplete) {
desc.setAutoBuilding(true);
ResourcesPlugin.getWorkspace().setDescription(desc);
while (!listener.isBuildComplete()) {
- Thread.sleep(3000);// do nothing till all the jobs are completeled
+ Thread.sleep(3000);// do nothing till all the jobs are completed
}
}
- // bug 173933 - runAndVerify() fails to check return IStatus
- if (operationStatus.getSeverity() == IStatus.ERROR)
- {
+
+ // bug 173933 - runAndVerify() fails to check return IStatushe
+ if (operationStatus.getSeverity() == IStatus.ERROR) {
Assert.fail(operationStatus.getMessage());
}
+
+ //run data model verifications
+ DataModelVerifierFactory verifierFactory = DataModelVerifierFactory.getInstance();
+ DataModelVerifier verifier = verifierFactory.createVerifier(dataModel);
+ verifier.verify(dataModel);
+
if (checkTasks && (errorOKList == null || errorOKList.isEmpty())) {
checkTasksList();
} else if (checkTasks && errorOKList != null && !errorOKList.isEmpty()) {