1 19 20 package org.netbeans.test.j2ee.multiview; 21 import java.io.File ; 22 import java.io.IOException ; 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 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 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 filename) throws IOException { 114 int dot=filename.lastIndexOf("."); 115 if (dot<0) dot=filename.length(); 116 String diffFilename=filename.substring(0,dot)+"diff"; 117 try { 118 assertFile(FileUtil.toFile(ddFo),getGoldenFile(getName()+"_"+filename), new File (getWorkDir(), getName()+"_ejb-jar.diff")); 119 } catch (org.netbeans.junit.AssertionFileFailedError ex) { 120 copyFile(FileUtil.toFile(ddFo), new File (getWorkDir(), getName()+"_"+filename)); 121 throw ex; 122 } 123 } 124 125 protected static void copyFile(java.io.File source, java.io.File destination) throws RuntimeException { 126 try { 127 java.io.FileInputStream inStream=new java.io.FileInputStream (source); 128 java.io.FileOutputStream outStream=new java.io.FileOutputStream (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 e) { 135 throw new RuntimeException ("Can't copy file "+source+" -> "+destination+".",e); 136 } 137 } 138 139 } | Popular Tags |