KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xsl > settings > TransformHistoryTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xsl.settings;
20
21 import java.util.*;
22 import java.io.*;
23 import java.rmi.MarshalledObject JavaDoc;
24
25 import junit.framework.*;
26 import org.netbeans.junit.*;
27
28 import org.openide.filesystems.FileObject;
29
30 import org.netbeans.modules.xsl.utils.TransformUtil;
31
32 /**
33  *
34  * @author Libor Kramolis
35  */

36 public class TransformHistoryTest extends NbTestCase {
37
38     public TransformHistoryTest(java.lang.String JavaDoc testName) {
39         super(testName);
40     }
41
42     public static void main(java.lang.String JavaDoc[] args) {
43         junit.textui.TestRunner.run(suite());
44     }
45     
46     public static Test suite() {
47         TestSuite suite = new NbTestSuite(TransformHistoryTest.class);
48         
49         return suite;
50     }
51     
52     
53     public void testIt () {
54         System.out.println("testIt");
55         
56         TransformHistory history = new TransformHistory();
57         
58         // current max number of items in history is 5!
59
assertTrue ("[1/5][1/5] OK!", checkHistory (history, 1, 1, "in.xml", "trans.xsl", "out.put"));
60         assertTrue ("[1/5][1/5] OK!", checkHistory (history, 1, 1, "in.xml", null, null));
61         assertTrue ("[2/5][1/5] OK!", checkHistory (history, 2, 1, "in2.xml", null, "out2.put"));
62         assertTrue ("[3/5][1/5] OK!", checkHistory (history, 3, 1, "in3.xml", null, "out3.put"));
63         assertTrue ("[4/5][1/5] OK!", checkHistory (history, 4, 1, "in4.xml", null, "out4.put"));
64         assertTrue ("[5/5][1/5] OK!", checkHistory (history, 5, 1, "in5.xml", null, "out5.put"));
65         assertTrue ("[6/5][1/5] OK!", checkHistory (history, 5, 1, "in6.xml", null, "out6.put"));
66         assertTrue ("Output for in6.xml is out6.put!", "out6.put".equals (history.getXMLOutput("in6.xml")));
67         assertTrue ("Output for in.xml is null!", (history.getXMLOutput("in.xml") == null));
68     }
69     
70     
71     private boolean checkHistory (TransformHistory history, int xi, int ti, String JavaDoc xml, String JavaDoc xsl, String JavaDoc output) {
72         // modify history
73
history.setOverwriteOutput (!history.isOverwriteOutput()); // negate
74
history.setProcessOutput ((history.getProcessOutput()+1)%3); // rotate
75
if ( xml != null ) {
76             history.addXML (xml, output);
77         }
78         if ( xsl != null ) {
79             history.addXSL (xsl, output);
80         }
81
82         // test number of XMLs
83
if ( history.getXMLs().length != xi ) {
84             System.out.println(" history.getXMLs().length: " + history.getXMLs().length);
85             return false;
86         }
87         // test number of XSLs
88
if ( history.getXSLs().length != ti ) {
89             System.out.println(" history.getXSLs().length: " + history.getXSLs().length);
90             return false;
91         }
92         
93         // (de)marshal
94
TransformHistory newHistory = null;
95         try {
96             MarshalledObject JavaDoc marshalled = new MarshalledObject JavaDoc (history);
97             newHistory = (TransformHistory) marshalled.get();
98         } catch (Exception JavaDoc exc) {
99             System.err.println("!!! " + exc);
100             return false;
101         }
102         
103         // test if equals
104
return (history.equals (newHistory));
105     }
106     
107 }
108
Popular Tags