KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > runtime > cmpmapping > ASCmpMappingTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.verifier.tests.ejb.runtime.cmpmapping;
25
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
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 JavaDoc col = null;
46                 if(getVerifierContext().getJDOException()!=null){
47                     result.addErrorDetails(smh.getLocalString
48                             ("tests.componentNameConstructor",
49                                     "For [ {0} ]",
50                                     new Object JavaDoc[] {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 JavaDoc[] {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 JavaDoc ex){
61                         result.addErrorDetails(smh.getLocalString
62                                 ("tests.componentNameConstructor",
63                                         "For [ {0} ]",
64                                         new Object JavaDoc[] {compName.toString()}));
65                         result.failed (smh.getLocalString(getClass().getName() + ".failed",
66                                 "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
67                                 new Object JavaDoc[] {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 JavaDoc[] {compName.toString()}));
76                     result.passed(smh.getLocalString(getClass().getName() + ".passed",
77                             "The mappings for the cmp beans (if any) are correct."));
78                 }else {
79                     // collect all the cmpmapping related errors
80
String JavaDoc allErrors = null;
81                     Iterator JavaDoc it = col.iterator();
82                     while (it.hasNext()) {
83                         Exception JavaDoc e = (Exception JavaDoc)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 JavaDoc[] {compName.toString()}));
93                         result.failed(smh.getLocalString(getClass().getName() + ".parseError",
94                                 "Error: Entity bean [ {0} ] has the following error(s) [ {1} ]."
95                                 , new Object JavaDoc[] {descriptor.getEjbClassName(), "\n" + allErrors} ));
96                     }
97                     else {
98                         result.addGoodDetails(smh.getLocalString
99                                 ("tests.componentNameConstructor",
100                                         "For [ {0} ]",
101                                         new Object JavaDoc[] {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 JavaDoc[] {compName.toString()}));
112                 result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable",
113                         "Not applicable: Test only applies to container managed EJBs"));
114             }
115         } catch(Exception JavaDoc e) {
116             result.addErrorDetails(smh.getLocalString
117                     ("tests.componentNameConstructor",
118                             "For [ {0} ]",
119                             new Object JavaDoc[] {compName.toString()}));
120             result.failed (smh.getLocalString(getClass().getName() + ".failed",
121                     "Error: Exception [ {0} ] when calling JDOCodeGenerator.validate().",
122                     new Object JavaDoc[] {e.getMessage()}));
123         }
124         return result;
125     }
126 }
127
Popular Tags