KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > multiview > MultiViewCloneableTopComponentTest


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
20
21 package org.netbeans.core.multiview;
22
23 import org.netbeans.core.api.multiview.MultiViewHandler;
24 import org.netbeans.core.api.multiview.MultiViews;
25 import org.netbeans.core.spi.multiview.MultiViewDescription;
26 import org.netbeans.core.spi.multiview.MultiViewFactory;
27
28 import java.awt.Image JavaDoc;
29 import java.io.DataOutputStream JavaDoc;
30 import java.io.File JavaDoc;
31 import java.io.FileInputStream JavaDoc;
32 import java.io.FileOutputStream JavaDoc;
33 import java.io.IOException JavaDoc;
34 import java.io.ObjectInputStream JavaDoc;
35 import java.io.ObjectOutputStream JavaDoc;
36 import java.io.Serializable JavaDoc;
37 import java.util.Collection JavaDoc;
38 import javax.swing.Action JavaDoc;
39 import javax.swing.JPanel JavaDoc;
40 import javax.swing.JToolBar JavaDoc;
41 import javax.swing.SwingUtilities JavaDoc;
42 import junit.framework.*;
43 import org.netbeans.core.api.multiview.MultiViewPerspective;
44 import org.netbeans.core.spi.multiview.CloseOperationHandler;
45 import org.netbeans.core.spi.multiview.MultiViewElement;
46 import org.netbeans.junit.*;
47 import org.openide.awt.UndoRedo;
48 import org.openide.util.HelpCtx;
49 import org.openide.util.io.NbMarshalledObject;
50 import org.openide.util.lookup.Lookups;
51
52 import org.openide.windows.*;
53
54
55 /**
56  *
57  * @author Milos Kleint
58  */

59 public class MultiViewCloneableTopComponentTest extends AbstractMultiViewTopComponentTestCase {
60     
61     /** Creates a new instance of SFSTest */
62     public MultiViewCloneableTopComponentTest(String JavaDoc name) {
63         super (name);
64     }
65     
66     /**
67      * @param args the command line arguments
68      */

69     public static void main(java.lang.String JavaDoc[] args) {
70         junit.textui.TestRunner.run(suite());
71     }
72     
73     public static Test suite() {
74         TestSuite suite = new NbTestSuite(MultiViewCloneableTopComponentTest.class);
75         
76         return suite;
77     }
78
79     protected TopComponent callFactory(MultiViewDescription[] desc, MultiViewDescription def) {
80         return MultiViewFactory.createCloneableMultiView(desc, def);
81     }
82     
83     protected TopComponent callFactory(MultiViewDescription[] desc, MultiViewDescription def, CloseOperationHandler close) {
84         return MultiViewFactory.createCloneableMultiView(desc, def, close);
85     }
86     
87     protected Class JavaDoc getTopComponentClass() {
88         return MultiViewCloneableTopComponent.class;
89     }
90     
91     public void testPersistence() throws Exception JavaDoc {
92         MVElem elem1 = new MVElem(new Action JavaDoc[] {new Act1("act1")} );
93         SerMVElem elem2 = new SerMVElem();
94         SerMVElem elem3 = new SerMVElem();
95         elem2.deserializeTest = "testtesttest - 2";
96         elem3.deserializeTest = "testtesttest - 3";
97         
98         MultiViewDescription desc1 = new SerMVDesc("desc1", null, TopComponent.PERSISTENCE_NEVER, elem1);
99         MultiViewDescription desc2 = new SerMVDesc("desc2", null, TopComponent.PERSISTENCE_ONLY_OPENED, elem2);
100         MultiViewDescription desc3 = new SerMVDesc("desc3", null, TopComponent.PERSISTENCE_ALWAYS, elem3);
101         
102         MultiViewDescription[] descs = new MultiViewDescription[] { desc1, desc2 };
103         SerCloseHandler close = new SerCloseHandler("serializedvalue");
104         
105         TopComponent tc = callFactory(descs, desc2, close);
106         tc.open();
107         tc.requestActive();
108         // testing closehandler here..
109
tc.close();
110         
111         NbMarshalledObject mars = new NbMarshalledObject(tc);
112         Object JavaDoc obj = mars.get();
113         assertNotNull(obj);
114         assertEquals(getTopComponentClass(), obj.getClass());
115         tc = (MultiViewCloneableTopComponent)obj;
116         
117         
118         MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
119         MultiViewPerspective[] descsAfter = handler.getPerspectives();
120         assertNotNull(descsAfter);
121         assertEquals(2, descsAfter.length);
122         MultiViewPerspective selDesc = handler.getSelectedPerspective();
123         assertNotNull(selDesc);
124         assertEquals("desc2", selDesc.getDisplayName());
125         tc.open();
126         tc.requestActive();
127         MultiViewCloneableTopComponent mvtc = (MultiViewCloneableTopComponent)tc;
128         Collection JavaDoc cold = mvtc.getModel().getCreatedElements();
129         // expected number of elements is one, because the elem3 was not initialized at all..
130
assertEquals(1, cold.size());
131         
132         // test if the deserialized instance is there..
133
SerMVElem elSelecto = (SerMVElem)mvtc.getModel().getActiveElement();
134         assertEquals("testtesttest - 2", elSelecto.deserializeTest);
135         assertEquals("componentOpened-componentShowing-componentActivated-", elSelecto.getLog());
136         
137         //testing if closehandler was correctly deserialized..
138
tc.close();
139         
140         
141     }
142     
143     
144 }
145
146
Popular Tags