You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2006/01/26 20:50:44 UTC

svn commit: r372596 - in /incubator/tuscany/java/sdo/impl/src/test: java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java java/org/apache/tuscany/sdo/test/TestUtil.java resources/simplechangesummary.xml

Author: jboynes
Date: Thu Jan 26 11:50:40 2006
New Revision: 372596

URL: http://svn.apache.org/viewcvs?rev=372596&view=rev
Log:
applied patch for TUSCANY-10 from Fuhwei Lwo

Added:
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java   (with props)
    incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml   (with props)
Modified:
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java?rev=372596&r1=372595&r2=372596&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java (original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java Thu Jan 26 11:50:40 2006
@@ -17,6 +17,10 @@
 package org.apache.tuscany.sdo.test;
 
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
@@ -32,7 +36,9 @@
 
 
 public class ChangeSummaryTestCase extends TestCase {
-    private static final String TEST_MODEL = "/simple.xsd";
+    private final String TEST_MODEL = "/simple.xsd";
+    private final String TEST_DATA = "/simplechangesummary.xml";
+    private File tmpFile;
 
     /**
      * Simple ChangeSummary test.
@@ -40,6 +46,7 @@
     public void testChangeSummary() throws IOException {
         // Create an empty data graph and add a root object, an instance of type Quote
         //
+      
         DataGraph dataGraph = SDOUtil.createDataGraph();
         DataObject quote = dataGraph.createRootObject("http://www.example.com/simple", "Quote");
 
@@ -65,9 +72,11 @@
         // Stop logging changes and print the resulting data graph to stdout
         //
         changeSummary.endLogging();
-        SDOUtil.saveDataGraph(dataGraph, System.out, null);
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        SDOUtil.saveDataGraph(dataGraph, baos, null);
 
-        // TODO verify that what was saved was correct
+        assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
     }
 
     protected void setUp() throws Exception {

Added: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java?rev=372596&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java (added)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java Thu Jan 26 11:50:40 2006
@@ -0,0 +1,168 @@
+/**
+ *
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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.tuscany.sdo.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class TestUtil
+{
+  private static void getAllNodes(NodeList nodeList, List<Node> nodes)
+  {
+    int length = nodeList.getLength();
+    if (length == 0)
+    {
+      return;
+    }
+    
+    for (int i=0; i<length; i++)
+    {
+      Node node = nodeList.item(i);
+      nodes.add(node);
+      getAllNodes(node.getChildNodes(), nodes);
+    } // for
+  }
+  
+  private static boolean equalNodes(NodeList sourceNodeList, NodeList targetNodeList)
+  {
+    ArrayList<Node> sourceNodes = new ArrayList<Node>();
+    ArrayList<Node> targetNodes = new ArrayList<Node>();
+    
+    getAllNodes(sourceNodeList, sourceNodes);
+    getAllNodes(targetNodeList, targetNodes);
+    
+    int sourceLength = sourceNodes.size();
+    int targetLength = targetNodes.size();
+    
+    if (sourceLength != targetLength)
+    {
+      return false;
+    }
+    
+    for (int i=0; i<sourceLength; i++)
+    {
+      Node sourceNode = sourceNodes.get(i);
+      Node targetNode = targetNodes.get(i);
+      
+      if (!sourceNode.isEqualNode(targetNode))
+      {
+        return false;
+      }
+    } // for
+    
+    return true;
+  }
+  
+  public static boolean equalXmlFiles(URL source, URL target)
+  { 
+    try {
+      return equalXmlFiles(source.openStream(), target.openStream());
+    }
+    catch (IOException e)
+    {
+      return false;
+    }
+  }
+  
+  public static boolean equalXmlFiles(InputStream sourceStream, URL target)
+  {
+    try {
+      return equalXmlFiles(sourceStream, target.openStream());
+    }
+    catch (IOException e)
+    {
+      return false;
+    }
+  }
+  
+  public static boolean equalXmlFiles(URL source, InputStream targetStream)
+  {
+    try {
+      return equalXmlFiles(source.openStream(), targetStream);
+    }
+    catch (IOException e)
+    {
+      return false;
+    }
+  }
+  
+  public static boolean equalXmlFiles(InputStream sourceStream, InputStream targetStream)
+  {
+    DocumentBuilder builder;
+    Document sourceDocument;
+    Document targetDocument;
+    
+    try {
+      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+      sourceDocument = builder.parse(sourceStream);
+      targetDocument = builder.parse(targetStream);
+    }
+    catch (FactoryConfigurationError fce) {
+      return false;
+    }
+    catch (ParserConfigurationException ce) {
+      return false;
+    }
+    catch (SAXException se)
+    {
+      return false;
+    }
+    catch (IOException ie)
+    {
+      return false;
+    }
+
+    sourceDocument.normalizeDocument();
+    targetDocument.normalizeDocument();
+    
+    if (!sourceDocument.getXmlVersion().equals(targetDocument.getXmlVersion()))
+    {
+      return false;
+    }
+    
+    String sourceXmlEncoding = sourceDocument.getXmlEncoding();
+    String targetXmlEncoding = targetDocument.getXmlEncoding();
+    
+    if (sourceXmlEncoding != null && targetXmlEncoding != null &&
+        sourceXmlEncoding.equalsIgnoreCase(targetXmlEncoding))
+    {
+      // continue
+    }
+    else
+    {
+      return false;
+    }
+
+    NodeList sourceNodes = sourceDocument.getChildNodes();
+    NodeList targetNodes = targetDocument.getChildNodes();
+    
+    return equalNodes(sourceNodes, targetNodes);
+  }
+}

Propchange: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml?rev=372596&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml (added)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml Thu Jan 26 11:50:40 2006
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdo="commonj.sdo"
+    xmlns:sdo_1="http://www.apache.org/tuscany/2005/SDO" xmlns:simple="http://www.example.com/simple">
+  <changeSummary xmlns="">
+    <objectChanges key="#//@eRootObject">
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="symbol" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="companyName" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="price" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="open1" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="high" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="low" set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="volume" dataValue="0.0"
+          set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="change1" dataValue="0.0"
+          set="false"/>
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="quotes" set="false"/>
+    </objectChanges>
+    <objectChanges key="#//@eRootObject/@quotes.0">
+      <value xsi:type="sdo_1:ChangeSummarySetting" featureName="price" set="false"/>
+    </objectChanges>
+  </changeSummary>
+  <simple:Quote>
+    <symbol>fbnt</symbol>
+    <companyName>FlyByNightTechnology</companyName>
+    <price>1000.0</price>
+    <open1>1000.0</open1>
+    <high>1000.0</high>
+    <low>1000.0</low>
+    <volume>1000.0</volume>
+    <change1>1000.0</change1>
+    <quotes>
+      <price>2000.0</price>
+    </quotes>
+  </simple:Quote>
+</sdo:datagraph>

Propchange: incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sdo/impl/src/test/resources/simplechangesummary.xml
------------------------------------------------------------------------------
    svn:keywords = Rev,Date