You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/03/06 23:57:38 UTC

svn commit: r515340 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/util/ example/ example/testdef/ example/testdef/assertdata/ testtools/src/org/ofbiz/testtools/

Author: jonesde
Date: Tue Mar  6 14:57:38 2007
New Revision: 515340

URL: http://svn.apache.org/viewvc?view=rev&rev=515340
Log:
Applied patch from Joe Eckard which implements the entity-xml-assert type of test and adds a small example test file for it that just validates against seed data; small change to reorganize, but mostly as-is

Added:
    ofbiz/trunk/framework/example/testdef/
    ofbiz/trunk/framework/example/testdef/assertdata/
    ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml   (with props)
    ofbiz/trunk/framework/example/testdef/tests.xml   (with props)
Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
    ofbiz/trunk/framework/example/ofbiz-component.xml
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java?view=diff&rev=515340&r1=515339&r2=515340
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntityDataAssert.java Tue Mar  6 14:57:38 2007
@@ -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 @@
 
 /**
  * Some utility routines for loading seed data.
- *
  */
 public class EntityDataAssert {
 
@@ -43,7 +42,7 @@
 
     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 @@
             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 @@
                     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);

Modified: ofbiz/trunk/framework/example/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/ofbiz-component.xml?view=diff&rev=515340&r1=515339&r2=515340
==============================================================================
--- ofbiz/trunk/framework/example/ofbiz-component.xml (original)
+++ ofbiz/trunk/framework/example/ofbiz-component.xml Tue Mar  6 14:57:38 2007
@@ -46,6 +46,8 @@
     <service-resource type="group" loader="main" location="servicedef/groups.xml"/>
     -->
 
+    <test-suite loader="main" location="testdef/tests.xml"/>
+
     <!-- web applications; will be mounted when using the embedded Jetty container -->
     <webapp name="example"
         title="Example"
@@ -53,4 +55,5 @@
         location="webapp/example"
         base-permission="OFBTOOLS"
         mount-point="/example"/>
+
 </ofbiz-component>

Added: ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml?view=auto&rev=515340
==============================================================================
--- ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml (added)
+++ ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml Tue Mar  6 14:57:38 2007
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-engine-xml>
+    <UserLogin userLoginId="system" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" />
+    <UserLogin userLoginId="anonymous" currentPassword="anonymous" />
+    <UserLogin userLoginId="admin" currentPassword="47ca69ebb4bdc9ae0adec130880165d2cc05db1a" partyId="admin" />
+</entity-engine-xml>
+

Propchange: ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/example/testdef/assertdata/TestUserLoginData.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ofbiz/trunk/framework/example/testdef/tests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/testdef/tests.xml?view=auto&rev=515340
==============================================================================
--- ofbiz/trunk/framework/example/testdef/tests.xml (added)
+++ ofbiz/trunk/framework/example/testdef/tests.xml Tue Mar  6 14:57:38 2007
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+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
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<test-suite suite-name="example-tests"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/test-suite.xsd">
+
+    <test-case case-name="userLoginEntityXmlAssert">
+        <entity-xml-assert entity-xml-url="component://example/testdef/assertdata/TestUserLoginData.xml"/>
+    </test-case>
+</test-suite>

Propchange: ofbiz/trunk/framework/example/testdef/tests.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/example/testdef/tests.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/example/testdef/tests.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java?view=diff&rev=515340&r1=515339&r2=515340
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java Tue Mar  6 14:57:38 2007
@@ -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 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);
     }
 }