svn commit: r1762079 - in /ofbiz/trunk: ./ framework/entity/src/main/java/org/apache/ofbiz/entity/test/ framework/entity/src/main/java/org/apache/ofbiz/entity/util/ framework/entity/src/test/java/org/apache/ofbiz/entity/util/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1762079 - in /ofbiz/trunk: ./ framework/entity/src/main/java/org/apache/ofbiz/entity/test/ framework/entity/src/main/java/org/apache/ofbiz/entity/util/ framework/entity/src/test/java/org/apache/ofbiz/entity/util/

jacopoc
Author: jacopoc
Date: Fri Sep 23 18:23:23 2016
New Revision: 1762079

URL: http://svn.apache.org/viewvc?rev=1762079&view=rev
Log:
Implemented: converted EntitySaxReader to use the default Sax reader instead
of the legacy implementation from Javolution; removed a bunch of unused or
deprecated methods; created some unit tests to test the EntitySaxReader in
isolation. Removed the dependency from Javolution since this was the last class
dependent on it.
(OFBIZ-5169)

Added:
    ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/
    ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java   (with props)
Modified:
    ofbiz/trunk/build.gradle
    ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java
    ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java

Modified: ofbiz/trunk/build.gradle
URL: http://svn.apache.org/viewvc/ofbiz/trunk/build.gradle?rev=1762079&r1=1762078&r2=1762079&view=diff
==============================================================================
--- ofbiz/trunk/build.gradle (original)
+++ ofbiz/trunk/build.gradle Fri Sep 23 18:23:23 2016
@@ -99,7 +99,6 @@ dependencies {
     compile 'javax.el:javax.el-api:3.0.1-b04'
     compile 'javax.servlet:javax.servlet-api:3.1.0'
     compile 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.0'
-    compile 'javolution:javolution:5.4.3'
     compile 'junit:junit-dep:4.10'
     compile 'net.fortuna.ical4j:ical4j:1.0-rc3-atlassian-11'
     compile 'org.apache.ant:ant-junit:1.9.0'

Modified: ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java?rev=1762079&r1=1762078&r2=1762079&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/test/EntityTestSuite.java Fri Sep 23 18:23:23 2016
@@ -1041,13 +1041,15 @@ public class EntityTestSuite extends Ent
      * Tests EntitySaxReader, verification loading data with tag create, create-update, create-replace, delete
      */
     public void testEntitySaxReaderCreation() throws Exception {
-        String xmlContentLoad =
+        String xmlContentLoad =
+                "<entity-engine-xml>" +
                 "<TestingType testingTypeId=\"JUNIT-TEST\" description=\"junit test\"/>" +
                 "<create>" +
                 "    <TestingType testingTypeId=\"JUNIT-TEST2\" description=\"junit test\"/>" +
                 "    <Testing testingId=\"T1\" testingTypeId=\"JUNIT-TEST\" testingName=\"First test\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" +
                 "</create>" +
-                "<Testing testingId=\"T2\" testingTypeId=\"JUNIT-TEST2\" testingName=\"Second test\" testingSize=\"20\" testingDate=\"2010-02-01 00:00:00\"/>";
+                "<Testing testingId=\"T2\" testingTypeId=\"JUNIT-TEST2\" testingName=\"Second test\" testingSize=\"20\" testingDate=\"2010-02-01 00:00:00\"/>" +
+                "</entity-engine-xml>";
         EntitySaxReader reader = new EntitySaxReader(delegator);
         long numberLoaded = reader.parse(xmlContentLoad);
         assertEquals("Create Entity loaded ", 4, numberLoaded);
@@ -1068,8 +1070,10 @@ public class EntityTestSuite extends Ent
 
     public void testEntitySaxReaderCreateSkip() throws Exception {
         String xmlContentLoad =
+                "<entity-engine-xml>" +
                 "<TestingType testingTypeId=\"reader-create-skip\" description=\"reader create skip\"/>" +
-                "<Testing testingId=\"reader-create-skip\" testingTypeId=\"reader-create-skip\" testingName=\"reader create skip\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>";
+                "<Testing testingId=\"reader-create-skip\" testingTypeId=\"reader-create-skip\" testingName=\"reader create skip\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" +
+                "</entity-engine-xml>";
         EntitySaxReader reader = new EntitySaxReader(delegator);
         long numberLoaded = reader.parse(xmlContentLoad);
         xmlContentLoad =
@@ -1089,13 +1093,15 @@ public class EntityTestSuite extends Ent
 
     public void testEntitySaxReaderUpdate() throws Exception {
         String xmlContentLoad =
+                "<entity-engine-xml>" +
                 "<TestingType testingTypeId=\"create-update\" description=\"create update\"/>" +
                 "<TestingType testingTypeId=\"create-updated\" description=\"create update updated\"/>" +
                 "<Testing testingId=\"create-update-T3\" testingTypeId=\"create-update\" testingName=\"Test 3\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" +
                 "<create-update>" +
                 "    <Testing testingId=\"create-update-T1\" testingTypeId=\"create-update\" testingName=\"First test update\" testingSize=\"20\" testingDate=\"2010-01-01 00:00:00\"/>" +
                 "    <Testing testingId=\"create-update-T3\" testingTypeId=\"create-updated\" testingName=\"Third test\" testingSize=\"30\" testingDate=\"2010-03-01 00:00:00\"/>" +
-                "</create-update>";
+                "</create-update>" +
+                "</entity-engine-xml>";
         EntitySaxReader reader = new EntitySaxReader(delegator);
         long numberLoaded = reader.parse(xmlContentLoad);
         assertEquals("Update Entity loaded ", 5, numberLoaded);
@@ -1116,12 +1122,14 @@ public class EntityTestSuite extends Ent
 
     public void testEntitySaxReaderReplace() throws Exception {
         String xmlContentLoad =
+                "<entity-engine-xml>" +
                 "<TestingType testingTypeId=\"create-replace\" description=\"reader create skip\"/>" +
                 "<Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T1\" testingName=\"First test\" testingSize=\"10\" testingDate=\"2010-01-01 00:00:00\"/>" +
                 "<create-replace>" +
                 "    <Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T1\" testingName=\"First test replace\" />" +
                 "</create-replace>" +
-                "<Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T2\" testingName=\"Second test update\" testingSize=\"20\" testingDate=\"2010-02-01 00:00:00\"/>";
+                "<Testing testingTypeId=\"create-replace\" testingId=\"create-replace-T2\" testingName=\"Second test update\" testingSize=\"20\" testingDate=\"2010-02-01 00:00:00\"/>" +
+                "</entity-engine-xml>";
         EntitySaxReader reader = new EntitySaxReader(delegator);
         long numberLoaded = reader.parse(xmlContentLoad);
         assertEquals("Replace Entity loaded ", 4, numberLoaded);

Modified: ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java?rev=1762079&r1=1762078&r2=1762079&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java (original)
+++ ofbiz/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntitySaxReader.java Fri Sep 23 18:23:23 2016
@@ -27,10 +27,14 @@ import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Base64;
@@ -53,24 +57,20 @@ import org.apache.ofbiz.entity.transacti
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
-import org.xml.sax.ErrorHandler;
+import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 import freemarker.ext.dom.NodeModel;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 import freemarker.template.TemplateException;
 import freemarker.template.TemplateHashModel;
-import javolution.text.CharArray;
-import javolution.text.Text;
-import javolution.xml.sax.Attributes;
-import javolution.xml.sax.XMLReaderImpl;
 
 /**
  * SAX XML Parser Content Handler for Entity Engine XML files
  */
-public class EntitySaxReader implements javolution.xml.sax.ContentHandler, ErrorHandler {
-
+public class EntitySaxReader extends DefaultHandler {
     public static final String module = EntitySaxReader.class.getName();
     public static final int DEFAULT_TX_TIMEOUT = 7200;
 
@@ -79,7 +79,7 @@ public class EntitySaxReader implements
     protected EntityEcaHandler<?> ecaHandler = null;
     protected GenericValue currentValue = null;
     protected CharSequence currentFieldName = null;
-    protected CharSequence currentFieldValue = null;
+    private char[] currentFieldValue = null;
     protected long numberRead = 0;
     protected long numberCreated = 0;
     protected long numberUpdated = 0;
@@ -94,16 +94,14 @@ public class EntitySaxReader implements
     protected boolean maintainTxStamps = false;
     protected boolean createDummyFks = false;
     protected boolean checkDataOnly = false;
-    @Deprecated
-    protected boolean doCacheClear = true;
     protected boolean disableEeca = false;
     protected enum Action {CREATE, CREATE_UPDATE, CREATE_REPLACE, DELETE};
     protected List<String> actionTags = UtilMisc.toList("create", "create-update", "create-replace", "delete");
     protected Action currentAction = Action.CREATE_UPDATE;
     protected List<Object> messageList = null;
 
-    protected List<GenericValue> valuesToWrite = new ArrayList<GenericValue>(valuesPerWrite);
-    protected List<GenericValue> valuesToDelete = new ArrayList<GenericValue>(valuesPerWrite);
+    protected List<GenericValue> valuesToWrite = new ArrayList<>(valuesPerWrite);
+    protected List<GenericValue> valuesToDelete = new ArrayList<>(valuesPerWrite);
 
     protected boolean isParseForTemplate = false;
     protected CharSequence templatePath = null;
@@ -124,22 +122,6 @@ public class EntitySaxReader implements
         this(delegator, DEFAULT_TX_TIMEOUT);
     }
 
-    public int getValuesPerWrite() {
-        return this.valuesPerWrite;
-    }
-
-    public void setValuesPerWrite(int valuesPerWrite) {
-        this.valuesPerWrite = valuesPerWrite;
-    }
-
-    public int getValuesPerMessage() {
-        return this.valuesPerMessage;
-    }
-
-    public void setValuesPerMessage(int valuesPerMessage) {
-        this.valuesPerMessage = valuesPerMessage;
-    }
-
     public int getTransactionTimeout() {
         return this.transactionTimeout;
     }
@@ -155,26 +137,14 @@ public class EntitySaxReader implements
         }
     }
 
-    public boolean getMaintainTxStamps() {
-        return this.maintainTxStamps;
-    }
-
     public void setMaintainTxStamps(boolean maintainTxStamps) {
         this.maintainTxStamps = maintainTxStamps;
     }
 
-    public boolean getCreateDummyFks() {
-        return this.createDummyFks;
-    }
-
     public void setCreateDummyFks(boolean createDummyFks) {
         this.createDummyFks = createDummyFks;
     }
 
-    public boolean getCheckDataOnly() {
-        return this.checkDataOnly;
-    }
-
     public void setCheckDataOnly(boolean checkDataOnly) {
         this.checkDataOnly = checkDataOnly;
     }
@@ -183,20 +153,6 @@ public class EntitySaxReader implements
         this.placeholderValues = placeholderValues;
     }
 
-    @Deprecated
-    public boolean getDoCacheClear() {
-        return this.doCacheClear;
-    }
-
-    @Deprecated
-    public void setDoCacheClear(boolean doCacheClear) {
-        this.doCacheClear = doCacheClear;
-    }
-
-    public boolean getDisableEeca() {
-        return this.disableEeca;
-    }
-
     public List<Object> getMessageList() {
         if (this.checkDataOnly && this.messageList == null) {
             messageList = new LinkedList<Object>();
@@ -204,10 +160,6 @@ public class EntitySaxReader implements
         return this.messageList;
     }
 
-    public void setMessageList(List<Object> messageList) {
-        this.messageList = messageList;
-    }
-
     public void setDisableEeca(boolean disableEeca) {
         this.disableEeca = disableEeca;
         if (disableEeca) {
@@ -262,34 +214,12 @@ public class EntitySaxReader implements
     }
 
     public long parse(InputStream is, String docDescription) throws SAXException, java.io.IOException {
-
-        /* NOTE: this method is not used because it doesn't work with various parsers...
-         String orgXmlSaxDriver = System.getProperty("org.xml.sax.driver");
-         if (UtilValidate.isEmpty(orgXmlSaxDriver)) orgXmlSaxDriver = "org.apache.xerces.parsers.SAXParser";
-         XMLReader reader = XMLReaderFactory.createXMLReader(orgXmlSaxDriver);
-         */
-
-        /* This code is for a standard SAXParser and XMLReader like xerces or such; for speed we are using the Javolution reader
-        XMLReader reader = null;
-
+        SAXParser parser;
         try {
-            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
-            SAXParser parser = parserFactory.newSAXParser();
-
-            reader = parser.getXMLReader();
-        } catch (javax.xml.parsers.ParserConfigurationException e) {
-            Debug.logError(e, "Failed to get a SAX XML parser", module);
-            throw new IllegalStateException("Failed to get a SAX XML parser");
-        }
-        */
-
-        XMLReaderImpl parser = new XMLReaderImpl();
-
-        parser.setContentHandler(this);
-        parser.setErrorHandler(this);
-        // LocalResolver lr = new UtilXml.LocalResolver(new DefaultHandler());
-        // reader.setEntityResolver(lr);
-
+            parser = SAXParserFactory.newInstance().newSAXParser();
+        } catch(ParserConfigurationException pce) {
+            throw new SAXException("Unable to create the SAX parser", pce);
+        }
         numberRead = 0;
         try {
             boolean beganTransaction = false;
@@ -298,7 +228,7 @@ public class EntitySaxReader implements
                 Debug.logImportant("Transaction Timeout set to " + transactionTimeout / 3600 + " hours (" + transactionTimeout + " seconds)", module);
             }
             try {
-                parser.parse(is);
+                parser.parse(is, this);
                 // make sure all of the values to write got written...
                 if (! valuesToWrite.isEmpty()) {
                     writeValues(valuesToWrite);
@@ -335,6 +265,16 @@ public class EntitySaxReader implements
         }
     }
 
+    private void countValue(boolean skip, boolean exist) {
+        if (skip) numberSkipped++;
+        else if (Action.DELETE == currentAction) numberDeleted++;
+        else if (Action.CREATE == currentAction || ! exist) numberCreated++;
+        else if (Action.CREATE_REPLACE == currentAction) numberReplaced++;
+        else numberUpdated++;
+    }
+
+    // ======== ContentHandler interface implementation ========
+
     public void characters(char[] values, int offset, int count) throws org.xml.sax.SAXException {
         if (isParseForTemplate) {
             // if null, don't worry about it
@@ -346,22 +286,22 @@ public class EntitySaxReader implements
         }
 
         if (currentValue != null && currentFieldName != null) {
-            Text value = Text.valueOf(values, offset, count);
-
-            // Debug.logInfo("characters: value=" + value, module);
+            char[] newChunk = Arrays.copyOfRange(values, offset, offset + count);
             if (currentFieldValue == null) {
-                currentFieldValue = value;
+                // this is the first chunk
+                currentFieldValue = newChunk;
             } else {
-                currentFieldValue = Text.valueOf(currentFieldValue).concat(value);
+                // append the new chunk to currentFieldValue
+                char[] combined = new char[currentFieldValue.length + newChunk.length];
+                System.arraycopy(currentFieldValue, 0, combined, 0, currentFieldValue.length);
+                System.arraycopy(newChunk, 0, combined, currentFieldValue.length, newChunk.length);
+                currentFieldValue = combined;
             }
         }
     }
 
-    public void endDocument() throws org.xml.sax.SAXException {}
-
-    public void endElement(CharArray namespaceURI, CharArray localName, CharArray fullName) throws org.xml.sax.SAXException {
-        if (Debug.verboseOn()) Debug.logVerbose("endElement: localName=" + localName + ", fullName=" + fullName + ", numberRead=" + numberRead, module);
-        String fullNameString = fullName.toString();
+    public void endElement(String namespaceURI, String localName, String fullNameString) throws org.xml.sax.SAXException {
+        if (Debug.verboseOn()) Debug.logVerbose("endElement: localName=" + localName + ", fullName=" + fullNameString + ", numberRead=" + numberRead, module);
         if ("entity-engine-xml".equals(fullNameString)) {
             return;
         }
@@ -435,13 +375,10 @@ public class EntitySaxReader implements
                         ModelField modelField = modelEntity.getField(currentFieldName.toString());
                         String type = modelField.getType();
                         if (type != null && type.equals("blob")) {
-                            byte strData[] = new byte[currentFieldValue.length()];
-                            strData = currentFieldValue.toString().getBytes();
-                            byte binData[] = new byte[currentFieldValue.length()];
-                            binData = Base64.base64Decode(strData);
+                            byte[] binData = Base64.base64Decode((new String(currentFieldValue)).getBytes());
                             currentValue.setBytes(currentFieldName.toString(), binData);
                         } else {
-                            currentValue.setString(currentFieldName.toString(), currentFieldValue.toString());
+                            currentValue.setString(currentFieldName.toString(), new String(currentFieldValue));
                         }
                     } else {
                         Debug.logWarning("Ignoring invalid field name [" + currentFieldName + "] found for the entity: " + currentValue.getEntityName() + " with value=" + currentFieldValue, module);
@@ -465,7 +402,7 @@ public class EntitySaxReader implements
                     boolean exist = true;
                     boolean skip = false;
                     //if verbose on, check if entity exist on database for count each action
-                    //It's necessay to check also for specific action CREATE and DELETE to ensure it's ok
+                    //It's necessary to check also for specific action CREATE and DELETE to ensure it's ok
                     if (Action.CREATE == currentAction || Action.DELETE == currentAction || Debug.verboseOn()) {
                         GenericHelper helper = delegator.getEntityHelper(currentValue.getEntityName());
                         if (currentValue.containsPrimaryKey()) {
@@ -527,35 +464,12 @@ public class EntitySaxReader implements
         }
     }
 
-    //Use for detail the loading entities
-    protected void countValue(boolean skip, boolean exist) {
-        if (skip) numberSkipped++;
-        else if (Action.DELETE == currentAction) numberDeleted++;
-        else if (Action.CREATE == currentAction || ! exist) numberCreated++;
-        else if (Action.CREATE_REPLACE == currentAction) numberReplaced++;
-        else numberUpdated++;
-    }
-
-    public void endPrefixMapping(CharArray prefix) throws org.xml.sax.SAXException {}
-
-    public void ignorableWhitespace(char[] values, int offset, int count) throws org.xml.sax.SAXException {
-        // String value = new String(values, offset, count);
-        // Debug.logInfo("ignorableWhitespace: value=" + value, module);
-    }
-
-    public void processingInstruction(CharArray target, CharArray instruction) throws org.xml.sax.SAXException {}
-
     public void setDocumentLocator(org.xml.sax.Locator locator) {
         this.locator = locator;
     }
 
-    public void skippedEntity(CharArray name) throws org.xml.sax.SAXException {}
-
-    public void startDocument() throws org.xml.sax.SAXException {}
-
-    public void startElement(CharArray namepsaceURI, CharArray localName, CharArray fullName, Attributes attributes) throws org.xml.sax.SAXException {
-        if (Debug.verboseOn()) Debug.logVerbose("startElement: localName=" + localName + ", fullName=" + fullName + ", attributes=" + attributes, module);
-        String fullNameString = fullName.toString();
+    public void startElement(String namepsaceURI, String localName, String fullNameString, Attributes attributes) throws org.xml.sax.SAXException {
+        if (Debug.verboseOn()) Debug.logVerbose("startElement: localName=" + localName + ", fullName=" + fullNameString + ", attributes=" + attributes, module);
         if ("entity-engine-xml".equals(fullNameString)) {
             // check the maintain-timestamp flag
             CharSequence maintainTx = attributes.getValue("maintain-timestamps");
@@ -563,13 +477,6 @@ public class EntitySaxReader implements
                 this.setMaintainTxStamps("true".equalsIgnoreCase(maintainTx.toString()));
             }
 
-            // check the do-cache-clear flag
-            @Deprecated
-            CharSequence doCacheClear = attributes.getValue("do-cache-clear");
-            if (doCacheClear != null) {
-                this.setDoCacheClear("true".equalsIgnoreCase(doCacheClear.toString()));
-            }
-
             // check the disable-eeca flag
             CharSequence ecaDisable = attributes.getValue("disable-eeca");
             if (ecaDisable != null) {
@@ -626,7 +533,7 @@ public class EntitySaxReader implements
 
         if (currentValue != null) {
             // we have a nested value/CDATA element
-            currentFieldName = fullName;
+            currentFieldName = fullNameString;
         } else {
             String entityName = fullNameString;
 
@@ -694,10 +601,7 @@ public class EntitySaxReader implements
         }
     }
 
-    //public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException {}
-    public void startPrefixMapping(CharArray arg0, CharArray arg1) throws SAXException {}
-
-    // ======== ErrorHandler interface implementations ========
+    // ======== ErrorHandler interface implementation ========
 
     public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException {
         Debug.logWarning(exception, "Error reading XML on line " + exception.getLineNumber() + ", column " + exception.getColumnNumber(), module);

Added: ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java?rev=1762079&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java (added)
+++ ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java Fri Sep 23 18:23:23 2016
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.
+ *******************************************************************************/
+package org.apache.ofbiz.entity.util;
+
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericValue;
+import org.apache.ofbiz.entity.model.ModelEntity;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+public class EntitySaxReaderTests {
+    @Test
+    public void constructorWithDefaultTimeout() {
+        Delegator delegator = mock(Delegator.class);
+        EntitySaxReader esr = new EntitySaxReader(delegator); // create a reader with default tx timeout
+        verify(delegator).cloneDelegator();
+        verifyNoMoreInteractions(delegator);
+        assertEquals(esr.DEFAULT_TX_TIMEOUT, esr.getTransactionTimeout());
+    }
+
+    @Test
+    public void constructorWithTimeout() {
+        Delegator delegator = mock(Delegator.class);
+        EntitySaxReader esr = new EntitySaxReader(delegator, 14400); // create a reader with a non default tx timeout
+        verify(delegator).cloneDelegator();
+        verifyNoMoreInteractions(delegator);
+        assertEquals(14400, esr.getTransactionTimeout());
+    }
+
+    @Test
+    public void parse() throws Exception {
+        Delegator delegator = mock(Delegator.class);
+        Delegator clonedDelegator = mock(Delegator.class);
+        GenericValue genericValue = mock(GenericValue.class);
+        ModelEntity modelEntity = mock(ModelEntity.class);
+        when(delegator.cloneDelegator()).thenReturn(clonedDelegator);
+        when(clonedDelegator.makeValue("EntityName")).thenReturn(genericValue);
+        when(genericValue.getModelEntity()).thenReturn(modelEntity);
+        when(genericValue.containsPrimaryKey()).thenReturn(true);
+        when(modelEntity.isField("fieldName")).thenReturn(true);
+
+        EntitySaxReader esr = new EntitySaxReader(delegator);
+        String input = "<entity-engine-xml><EntityName fieldName=\"field value\"/></entity-engine-xml>";
+        long recordsProcessed = esr.parse(input);
+        verify(clonedDelegator).makeValue("EntityName");
+        assertEquals(1, recordsProcessed);
+    }
+}

Propchange: ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/entity/src/test/java/org/apache/ofbiz/entity/util/EntitySaxReaderTests.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain