1 23 24 package com.sun.enterprise.tools.verifier.tests.ejb.runtime.cmpmapping; 25 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import com.sun.enterprise.deployment.EjbDescriptor; 29 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 30 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 31 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor; 32 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 33 import com.sun.enterprise.tools.verifier.Result; 34 import com.sun.jdo.spi.persistence.support.ejb.ejbc.JDOCodeGenerator; 35 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException; 36 37 public class ASCmpMappingTest extends EjbTest implements EjbCheck { 38 39 public Result check(EjbDescriptor descriptor) 40 { 41 Result result = getInitializedResult(); 42 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 43 try { 44 if (descriptor instanceof IASEjbCMPEntityDescriptor) { 45 Collection col = null; 46 if(getVerifierContext().getJDOException()!=null){ 47 result.addErrorDetails(smh.getLocalString 48 ("tests.componentNameConstructor", 49 "For [ {0} ]", 50 new Object [] {compName.toString()})); 51 result.failed (smh.getLocalString(getClass().getName() + ".failed1", 52 "Error: Exception [ {0} ] while initializing JDOCodeGenerator. Please check your descriptors and mapping files for consistency ", 53 new Object [] {getVerifierContext().getJDOException().getMessage()})); 54 55 return result; 56 }else{ 57 try{ 58 JDOCodeGenerator jdc= getVerifierContext().getJDOCodeGenerator(); 59 col = jdc.validate((IASEjbCMPEntityDescriptor)descriptor); 60 }catch(Exception ex){ 61 result.addErrorDetails(smh.getLocalString 62 ("tests.componentNameConstructor", 63 "For [ {0} ]", 64 new Object [] {compName.toString()})); 65 result.failed (smh.getLocalString(getClass().getName() + ".failed", 66 "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", 67 new Object [] {ex.getMessage()})); 68 return result; 69 } 70 } 71 if (col.isEmpty()){ 72 result.addGoodDetails(smh.getLocalString 73 ("tests.componentNameConstructor", 74 "For [ {0} ]", 75 new Object [] {compName.toString()})); 76 result.passed(smh.getLocalString(getClass().getName() + ".passed", 77 "The mappings for the cmp beans (if any) are correct.")); 78 }else { 79 String allErrors = null; 81 Iterator it = col.iterator(); 82 while (it.hasNext()) { 83 Exception e = (Exception )it.next(); 84 if (!(e instanceof EJBQLException)) { 85 allErrors = e.getMessage() + "\n\n"; 86 } 87 } 88 if (allErrors != null) { 89 result.addErrorDetails(smh.getLocalString 90 ("tests.componentNameConstructor", 91 "For [ {0} ]", 92 new Object [] {compName.toString()})); 93 result.failed(smh.getLocalString(getClass().getName() + ".parseError", 94 "Error: Entity bean [ {0} ] has the following error(s) [ {1} ]." 95 , new Object [] {descriptor.getEjbClassName(), "\n" + allErrors} )); 96 } 97 else { 98 result.addGoodDetails(smh.getLocalString 99 ("tests.componentNameConstructor", 100 "For [ {0} ]", 101 new Object [] {compName.toString()})); 102 result.passed(smh.getLocalString(getClass().getName() + ".passed", 103 "The mappings for the cmp beans (if any) are correct.")); 104 } 105 } 106 } else 107 { 108 result.addNaDetails(smh.getLocalString 109 ("tests.componentNameConstructor", 110 "For [ {0} ]", 111 new Object [] {compName.toString()})); 112 result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", 113 "Not applicable: Test only applies to container managed EJBs")); 114 } 115 } catch(Exception e) { 116 result.addErrorDetails(smh.getLocalString 117 ("tests.componentNameConstructor", 118 "For [ {0} ]", 119 new Object [] {compName.toString()})); 120 result.failed (smh.getLocalString(getClass().getName() + ".failed", 121 "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().", 122 new Object [] {e.getMessage()})); 123 } 124 return result; 125 } 126 } 127 | Popular Tags |