1 23 24 package com.sun.enterprise.tools.verifier.tests.ejb.ias; 25 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 27 import java.io.*; 28 import java.util.jar.*; 29 import java.util.zip.*; 30 31 import com.sun.enterprise.deployment.*; 32 import com.sun.enterprise.tools.verifier.*; 33 import org.xml.sax.*; 34 import org.w3c.dom.*; 35 36 import com.sun.enterprise.tools.verifier.tests.*; 37 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 38 39 import com.sun.enterprise.deployment.xml.IASEjbRuntimeDescriptorNode; 40 46 public class ASEjbJarPublicID extends EjbTest implements EjbCheck { 47 48 57 public Result check(EjbDescriptor descriptor) { 58 59 Result result = getInitializedResult(); 60 61 String acceptablePubidLiterals[] = { 62 IASEjbRuntimeDescriptorNode.PUBLIC_DTD_ID}; 63 String acceptableURLs[] = {IASEjbRuntimeDescriptorNode.SYSTEM_ID}; 64 65 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 66 67 if(!descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName())) 69 { 70 descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName()); 71 File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName()); 72 JarFile jarFile = null; 73 try { 74 jarFile = new JarFile(f); 75 ZipEntry deploymentEntry = 76 jarFile.getEntry(EjbBundleArchivist.IAS_DEPLOYMENT_DESCRIPTOR_ENTRY); 77 if (deploymentEntry != null) { 78 BufferedReader in = new BufferedReader(new InputStreamReader(jarFile.getInputStream(deploymentEntry))); 79 String s = in.readLine(); 80 boolean foundDOCTYPE = false, foundPubid = false, foundURL = false; 81 82 while(s != null) { 83 if(s.indexOf("DOCTYPE") > -1) 84 foundDOCTYPE = true; 85 if(foundDOCTYPE){ 86 for (int i=0;i<acceptablePubidLiterals.length;i++) { 87 if (s.indexOf(acceptablePubidLiterals[i]) > -1) { 88 foundPubid = true; 89 result.addGoodDetails(smh.getLocalString 90 ("tests.componentNameConstructor", 91 "For [ {0} ]", 92 new Object [] {compName.toString()})); 93 result.addGoodDetails 94 (smh.getLocalString 95 (getClass().getName() + ".passed1", 96 "PASSED [AS-EJB ] : The iAS deployment descriptor has the proper PubidLiteral: {0}", 97 new Object [] {acceptablePubidLiterals[i]})); 98 } 99 if (s.indexOf(acceptableURLs[i]) > -1) { 101 foundURL = true; 102 result.addGoodDetails(smh.getLocalString 103 ("tests.componentNameConstructor", 104 "For [ {0} ]", 105 new Object [] {compName.toString()})); 106 result.addGoodDetails 107 (smh.getLocalString 108 (getClass().getName() + ".passed2", 109 "PASSED [AS-EJB] : The iAS deployment descriptor has the proper URL corresponding the the PubIdLiteral: {0}", 110 new Object [] {acceptableURLs[i]})); 111 } 112 } 113 } 114 if(foundPubid && foundURL) { 115 result.setStatus(Result.PASSED); 116 break; 117 } else if(foundDOCTYPE && s.endsWith(">")) break; s = in.readLine(); 119 } 120 121 if(!foundDOCTYPE){ 122 result.addErrorDetails(smh.getLocalString 123 ("tests.componentNameConstructor", 124 "For [ {0} ]", 125 new Object [] {compName.toString()})); 126 result.failed 127 (smh.getLocalString 128 (getClass().getName() + ".failed1", 129 "FAILED [AS-EJB] : No document type declaration found in the deployment descriptor for {0}", 130 new Object [] {descriptor.getName()})); 131 } else if(!foundPubid) { 132 result.addErrorDetails(smh.getLocalString 133 ("tests.componentNameConstructor", 134 "For [ {0} ]", 135 new Object [] {compName.toString()})); 136 result.failed 137 (smh.getLocalString 138 (getClass().getName() + ".failed2", 139 "FAILED [AS-EJB ejb] : The deployment descriptor for {0} does not have an expected PubidLiteral ", 140 new Object [] {descriptor.getName()})); 141 } else if (!foundURL){ 142 result.addErrorDetails(smh.getLocalString 143 ("tests.componentNameConstructor", 144 "For [ {0} ]", 145 new Object [] {compName.toString()})); 146 result.failed(smh.getLocalString 147 (getClass().getName() + ".failed", 148 "The deployment descriptor {0} doesnot have the right URL corresponding to the PubIdLiteral", 149 new Object [] {descriptor.getName()})); 150 } 151 } 152 jarFile.close(); 153 154 } catch (IOException e) { 155 result.addErrorDetails(smh.getLocalString 156 ("tests.componentNameConstructor", 157 "For [ {0} ]", 158 new Object [] {compName.toString()})); 159 result.failed(smh.getLocalString 160 (getClass().getName() + ".IOException", 161 "Error: I/O error trying to open {0}", new Object [] {f.getAbsolutePath()})); 162 } 163 } 164 else 165 { 166 result.setStatus(Result.NOT_RUN); 167 result.addGoodDetails(smh.getLocalString(getClass().getName(), 168 "[AS-EJB] JAR Level test. Already done")); 169 } 170 return result; 171 } 172 } 173 174 | Popular Tags |