KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > j2ee > multiview > DDTestCase


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 package org.netbeans.test.j2ee.multiview;
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.jellytools.JellyTestCase;
25 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
26 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
27 import org.netbeans.modules.j2ee.ddloaders.multiview.BeanDetailNode;
28 import org.netbeans.modules.j2ee.ddloaders.multiview.BeanDetailsPanel;
29 import org.netbeans.modules.j2ee.ddloaders.multiview.CmpRelationShipsNode;
30 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesNode;
31 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbImplementationAndInterfacesPanel;
32 import org.netbeans.modules.j2ee.ddloaders.multiview.EjbJarMultiViewDataObject;
33 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewNode;
34 import org.netbeans.modules.j2ee.ddloaders.multiview.EntityOverviewPanel;
35 import org.netbeans.modules.j2ee.ddloaders.multiview.InnerTablePanel;
36 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement;
37 import org.netbeans.modules.xml.multiview.ui.SectionNodePanel;
38 import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
39 import org.openide.filesystems.FileUtil;
40 import org.netbeans.test.j2ee.multiview.Utils;
41 import org.openide.filesystems.FileObject;
42 import org.openide.nodes.Children;
43 import org.openide.nodes.Node;
44
45 /**
46  *
47  * @author jhorvath
48  */

49 public abstract class DDTestCase extends JellyTestCase {
50     
51     protected static Project project;
52     protected static EjbJarMultiViewDataObject ddObj;
53     protected static FileObject ddFo;
54     protected static Entity bean;
55     protected static EjbJar ejbJar;
56     
57     public DDTestCase(String JavaDoc name) {
58         super(name);
59     }
60     
61     protected EntityOverviewPanel getEntityGeneralPanel(){
62         Node[] nnChild = Utils.getChildrenNodes(Utils.getEntityNode(ddObj));
63         for(int k = 0; k < nnChild.length; k++){
64             if(nnChild[k] instanceof EntityOverviewNode){
65                 SectionNodePanel overviewPanel = ((EntityOverviewNode)nnChild[k]).getSectionNodePanel();
66                 overviewPanel.open();
67                 EntityOverviewPanel entityPanel = (EntityOverviewPanel)overviewPanel.getInnerPanel();
68                 return entityPanel;
69             }
70         }
71         return null;
72     }
73     
74     protected EjbImplementationAndInterfacesPanel getClassAndInterfacePanel(){
75         assertNotNull(ddObj);
76         Node[] nnChild = Utils.getChildrenNodes(Utils.getEntityNode(ddObj));
77         for(int k = 0; k < nnChild.length; k++){
78             if(nnChild[k] instanceof EjbImplementationAndInterfacesNode){
79                 SectionNodePanel overviewPanel = ((EjbImplementationAndInterfacesNode)nnChild[k]).getSectionNodePanel();
80                 overviewPanel.open();
81                 return (EjbImplementationAndInterfacesPanel)overviewPanel.getInnerPanel();
82             }
83         }
84         return null;
85     }
86     
87     protected InnerTablePanel getDetailPanel(){
88         ToolBarMultiViewElement toolBar = ddObj.getActiveMVElement();
89         assertNotNull("ToolBarMultiViewElement is null",toolBar);
90         SectionNodeView sectionView = (SectionNodeView)toolBar.getSectionView();
91         
92         Children nodes = sectionView.getRootNode().getChildren();
93         Node[] n = nodes.getNodes();
94         if(n[0] instanceof CmpRelationShipsNode){
95             CmpRelationShipsNode detailNode = (CmpRelationShipsNode)n[0];
96             return (InnerTablePanel)detailNode.getSectionNodePanel().getInnerPanel();
97         }
98         return null;
99     }
100     
101     protected BeanDetailsPanel getBeanDetailPanel(){
102         Node[] nnChild = Utils.getChildrenNodes(Utils.getEntityNode(ddObj));
103         for(int k = 0; k < nnChild.length; k++){
104             if(nnChild[k] instanceof BeanDetailNode){
105                 SectionNodePanel overviewPanel = ((BeanDetailNode)nnChild[k]).getSectionNodePanel();
106                 overviewPanel.open();
107                 return (BeanDetailsPanel)overviewPanel.getInnerPanel();
108             }
109         }
110         return null;
111     }
112     
113     protected void assertFile(String JavaDoc filename) throws IOException JavaDoc {
114         int dot=filename.lastIndexOf(".");
115         if (dot<0) dot=filename.length();
116         String JavaDoc diffFilename=filename.substring(0,dot)+"diff";
117         try {
118             assertFile(FileUtil.toFile(ddFo),getGoldenFile(getName()+"_"+filename), new File JavaDoc(getWorkDir(), getName()+"_ejb-jar.diff"));
119         } catch (org.netbeans.junit.AssertionFileFailedError ex) {
120             copyFile(FileUtil.toFile(ddFo), new File JavaDoc(getWorkDir(), getName()+"_"+filename));
121             throw ex;
122         }
123     }
124     
125     protected static void copyFile(java.io.File JavaDoc source, java.io.File JavaDoc destination) throws RuntimeException JavaDoc {
126         try {
127             java.io.FileInputStream JavaDoc inStream=new java.io.FileInputStream JavaDoc(source);
128             java.io.FileOutputStream JavaDoc outStream=new java.io.FileOutputStream JavaDoc(destination);
129             int len;
130             byte[] buf=new byte[2048];
131             while ((len=inStream.read(buf))!=-1) {
132                 outStream.write(buf,0,len);
133             }
134         } catch (Exception JavaDoc e) {
135             throw new RuntimeException JavaDoc("Can't copy file "+source+" -> "+destination+".",e);
136         }
137     }
138     
139 }
Popular Tags