diff --git a/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java b/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
index 0958073b6e..1c53416b78 100644
--- a/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
+++ b/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -35,7 +35,6 @@ import org.xml.sax.SAXException;
/**
* Some utility routines for loading seed data.
- *
*/
public class EntityDataAssert {
@@ -43,7 +42,7 @@ public class EntityDataAssert {
public static int assertData(URL dataUrl, GenericDelegator delegator, List errorMessages) throws GenericEntityException, SAXException, ParserConfigurationException, IOException {
int rowsChecked = 0;
-
+
if (dataUrl == null) {
String errMsg = "Cannot assert/check data, dataUrl was null";
errorMessages.add(errMsg);
@@ -51,18 +50,18 @@ public class EntityDataAssert {
return 0;
}
- Debug.logVerbose("[install.loadData] Loading XML Resource: \"" + dataUrl.toExternalForm() + "\"", module);
+ Debug.logVerbose("Loading XML Resource: " + dataUrl.toExternalForm(), module);
try {
List checkValueList = delegator.readXmlDocument(dataUrl);
Iterator checkValueIter = checkValueList.iterator();
while (checkValueIter.hasNext()) {
GenericValue checkValue = (GenericValue) checkValueIter.next();
-
+
// to check get the PK, find by that, compare all fields
GenericPK checkPK = checkValue.getPrimaryKey();
GenericValue currentValue = delegator.findByPrimaryKey(checkPK);
-
+
ModelEntity modelEntity = currentValue.getModelEntity();
List nonpkFieldNameList = modelEntity.getNoPkFieldNames();
Iterator nonpkFieldNameIter = nonpkFieldNameList.iterator();
@@ -70,29 +69,18 @@ public class EntityDataAssert {
String nonpkFieldName = (String) nonpkFieldNameIter.next();
Object checkField = checkValue.get(nonpkFieldName);
Object currentField = currentValue.get(nonpkFieldName);
-
- boolean matches = false;
- if (checkField == null) {
- if (currentField == null) {
- matches = true;
- }
- } else {
- if (checkField.equals(currentField)) {
- matches = true;
- }
- }
-
- if (!matches) {
+
+ if (checkField != null && !checkField.equals(currentField)) {
StringBuffer matchError = new StringBuffer();
- matchError.append("Field [" + modelEntity.getEntityName() + "." + nonpkFieldName + "] did not match; file value [" + checkField + "], db value [" + currentField + "] pk [" + checkPK + "]");
+ matchError.append("Field [" + modelEntity.getEntityName() + "." + nonpkFieldName + "] did not match; file value [" + checkField + "], db value [" + currentField + "] pk [" + checkPK + "]");
errorMessages.add(matchError.toString());
}
}
-
+
rowsChecked++;
}
} catch (GenericEntityException e) {
- String xmlError = "Error checking/asserting XML Resource \"" + dataUrl.toExternalForm() + "\"; Error was: " + e.getMessage();
+ String xmlError = "Error checking/asserting XML Resource: " + dataUrl.toExternalForm() + "; Error was: " + e.getMessage();
Debug.logError(e, xmlError, module);
// instead of adding this as a message, throw the real exception; then caller has more control
//errorMessages.add(xmlError);
diff --git a/framework/example/ofbiz-component.xml b/framework/example/ofbiz-component.xml
index 44dd67391f..3b995de246 100644
--- a/framework/example/ofbiz-component.xml
+++ b/framework/example/ofbiz-component.xml
@@ -46,6 +46,8 @@ under the License.
-->
+
+
+
diff --git a/framework/example/testdef/assertdata/TestUserLoginData.xml b/framework/example/testdef/assertdata/TestUserLoginData.xml
new file mode 100644
index 0000000000..514290ff7c
--- /dev/null
+++ b/framework/example/testdef/assertdata/TestUserLoginData.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/framework/example/testdef/tests.xml b/framework/example/testdef/tests.xml
new file mode 100644
index 0000000000..595bc8af0a
--- /dev/null
+++ b/framework/example/testdef/tests.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java b/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
index aea6074379..128f512eae 100644
--- a/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
+++ b/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,14 +19,26 @@
package org.ofbiz.testtools;
import junit.framework.TestResult;
+import junit.framework.AssertionFailedError;
import org.w3c.dom.Element;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.util.EntityDataAssert;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.location.FlexibleLocation;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.net.URL;
public class EntityXmlAssertTest extends TestCaseBase {
public static final String module = ServiceTest.class.getName();
-
+
protected String entityXmlUrlString;
+ protected int testCaseCount;
/**
* @param modelTestSuite
@@ -34,15 +46,43 @@ public class EntityXmlAssertTest extends TestCaseBase {
public EntityXmlAssertTest(String caseName, ModelTestSuite modelTestSuite, Element mainElement) {
super(caseName, modelTestSuite);
this.entityXmlUrlString = mainElement.getAttribute("entity-xml-url");
+ this.testCaseCount = 0;
+ try {
+ URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
+ List checkValueList = modelTestSuite.getDelegator().readXmlDocument(entityXmlURL);
+ this.testCaseCount = checkValueList.size();
+ } catch (Exception e) {
+ Debug.logError(e, "Error getting test case count", module);
+ }
}
public int countTestCases() {
- return 1;
+ return this.testCaseCount;
}
public void run(TestResult result) {
- // TODO Auto-generated method stub
-
- // NOTE: use EntityDataAssert.java
+
+ result.startTest(this);
+
+ try {
+
+ URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
+ GenericDelegator delegator = modelTestSuite.getDelegator();
+ List errorMessages = new ArrayList();
+
+ EntityDataAssert.assertData(entityXmlURL, delegator, errorMessages);
+
+ if (UtilValidate.isNotEmpty(errorMessages)) {
+ for (Iterator failureIterator = errorMessages.iterator(); failureIterator.hasNext();) {
+ String failureMessage = (String) failureIterator.next();
+ result.addFailure(this, new AssertionFailedError(failureMessage));
+ }
+ }
+
+ } catch (Exception e) {
+ result.addError(this, e);
+ }
+
+ result.endTest(this);
}
}