001: /*
002: Copyright (c) 2003-2005, Dennis M. Sosnoski
003: All rights reserved.
004:
005: Redistribution and use in source and binary forms, with or without modification,
006: are permitted provided that the following conditions are met:
007:
008: * Redistributions of source code must retain the above copyright notice, this
009: list of conditions and the following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice,
011: this list of conditions and the following disclaimer in the documentation
012: and/or other materials provided with the distribution.
013: * Neither the name of JiBX nor the names of its contributors may be used
014: to endorse or promote products derived from this software without specific
015: prior written permission.
016:
017: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
018: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
019: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
021: ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028:
029: package org.jibx.extras;
030:
031: import java.io.File;
032:
033: /**
034: * Test program for the JiBX framework. Works with three or four command line
035: * arguments: mapped-class, binding-name, in-file, and out-file (optional, only
036: * needed if different from in-file). You can also supply a multiple of four
037: * input arguments, in which case each set of four is processed in turn (in this
038: * case the out-file is required). Unmarshals documents from files using the
039: * specified bindings for the mapped classes, then marshals them back out using
040: * the same bindings and compares the results. In case of a comparison error the
041: * output file is left as <i>temp.xml </i>.
042: *
043: * @author Dennis M. Sosnoski
044: * @version 1.0
045: */
046: public class TestMultRoundtrip {
047:
048: public static void main(String[] args) {
049: if (args.length == 3
050: || (args.length > 0 && args.length % 4 == 0)) {
051:
052: // delete generated output file if present
053: File temp = new File("temp.xml");
054: if (temp.exists()) {
055: temp.delete();
056: }
057:
058: // process input arguments
059: int base = 0;
060: boolean err = false;
061: String fin = null;
062: String fout = null;
063: while (base < args.length) {
064:
065: // run test with one argument set
066: fin = args[base + 2];
067: fout = (args.length < base + 4) ? fin : args[base + 3];
068: try {
069: if (!TestRoundtrip.runTest(args[base],
070: args[base + 1], fin, fout)) {
071: err = true;
072: }
073: } catch (Exception ex) {
074: ex.printStackTrace();
075: // System.err.println(ex.getMessage());
076: err = true;
077: }
078:
079: // take error exit if difference found
080: if (err) {
081: System.err.println("Error round-tripping class: "
082: + args[base] + "\n with input file " + fin
083: + " and output compared to " + fout);
084: System.err
085: .println("Saved output document file path "
086: + temp.getAbsolutePath());
087: System.exit(1);
088: }
089:
090: // advance to next argument set
091: base += 4;
092: }
093:
094: } else {
095: System.err
096: .println("Usage: java TestMultRoundtrip mapped-class"
097: + " binding-name in-file [out-file]\n where out-file is only"
098: + " required if the output document is different from\nthe"
099: + " input document. Leaves output as temp.xml in case of error");
100: System.exit(1);
101: }
102: }
103: }
|