001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xsl.settings;
042:
043: import java.util.*;
044: import java.io.*;
045: import java.rmi.MarshalledObject;
046:
047: import junit.framework.*;
048: import org.netbeans.junit.*;
049:
050: import org.openide.filesystems.FileObject;
051:
052: import org.netbeans.modules.xsl.utils.TransformUtil;
053:
054: /**
055: *
056: * @author Libor Kramolis
057: */
058: public class TransformHistoryTest extends NbTestCase {
059:
060: public TransformHistoryTest(java.lang.String testName) {
061: super (testName);
062: }
063:
064: public static void main(java.lang.String[] args) {
065: junit.textui.TestRunner.run(suite());
066: }
067:
068: public static Test suite() {
069: TestSuite suite = new NbTestSuite(TransformHistoryTest.class);
070:
071: return suite;
072: }
073:
074: public void testIt() {
075: System.out.println("testIt");
076:
077: TransformHistory history = new TransformHistory();
078:
079: // current max number of items in history is 5!
080: assertTrue("[1/5][1/5] OK!", checkHistory(history, 1, 1,
081: "in.xml", "trans.xsl", "out.put"));
082: assertTrue("[1/5][1/5] OK!", checkHistory(history, 1, 1,
083: "in.xml", null, null));
084: assertTrue("[2/5][1/5] OK!", checkHistory(history, 2, 1,
085: "in2.xml", null, "out2.put"));
086: assertTrue("[3/5][1/5] OK!", checkHistory(history, 3, 1,
087: "in3.xml", null, "out3.put"));
088: assertTrue("[4/5][1/5] OK!", checkHistory(history, 4, 1,
089: "in4.xml", null, "out4.put"));
090: assertTrue("[5/5][1/5] OK!", checkHistory(history, 5, 1,
091: "in5.xml", null, "out5.put"));
092: assertTrue("[6/5][1/5] OK!", checkHistory(history, 5, 1,
093: "in6.xml", null, "out6.put"));
094: assertTrue("Output for in6.xml is out6.put!", "out6.put"
095: .equals(history.getXMLOutput("in6.xml")));
096: assertTrue("Output for in.xml is null!", (history
097: .getXMLOutput("in.xml") == null));
098: }
099:
100: private boolean checkHistory(TransformHistory history, int xi,
101: int ti, String xml, String xsl, String output) {
102: // modify history
103: history.setOverwriteOutput(!history.isOverwriteOutput()); // negate
104: history.setProcessOutput((history.getProcessOutput() + 1) % 3); // rotate
105: if (xml != null) {
106: history.addXML(xml, output);
107: }
108: if (xsl != null) {
109: history.addXSL(xsl, output);
110: }
111:
112: // test number of XMLs
113: if (history.getXMLs().length != xi) {
114: System.out.println(" history.getXMLs().length: "
115: + history.getXMLs().length);
116: return false;
117: }
118: // test number of XSLs
119: if (history.getXSLs().length != ti) {
120: System.out.println(" history.getXSLs().length: "
121: + history.getXSLs().length);
122: return false;
123: }
124:
125: // (de)marshal
126: TransformHistory newHistory = null;
127: try {
128: MarshalledObject marshalled = new MarshalledObject(history);
129: newHistory = (TransformHistory) marshalled.get();
130: } catch (Exception exc) {
131: System.err.println("!!! " + exc);
132: return false;
133: }
134:
135: // test if equals
136: return (history.equals(newHistory));
137: }
138:
139: }
|