KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > verifier > tests > TransactionServiceTest


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 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31
32 package com.sun.enterprise.admin.verifier.tests;
33
34 /* Test Case which validates the Transaction Service Fields
35  * Author : srini@sun.com
36  **/

37
38 import java.io.File JavaDoc;
39
40 // 8.0 XML Verifier
41
//import com.sun.enterprise.tools.verifier.Result;
42
import com.sun.enterprise.config.serverbeans.Server;
43 import com.sun.enterprise.config.serverbeans.*;
44 import com.sun.enterprise.config.serverbeans.Resources;
45 import com.sun.enterprise.config.serverbeans.Applications;
46 import com.sun.enterprise.config.ConfigContext;
47 import com.sun.enterprise.config.ConfigContextEvent;
48 import com.sun.enterprise.config.ConfigException;
49 import com.sun.enterprise.config.serverbeans.*;
50
51 import com.sun.enterprise.admin.verifier.*;
52 // Logging
53
import java.util.logging.Logger JavaDoc;
54 import java.util.logging.Level JavaDoc;
55 import com.sun.logging.LogDomains;
56
57 public class TransactionServiceTest extends ServerXmlTest implements ServerCheck {
58     // Logging
59
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.APPVERIFY_LOGGER);
60     
61     public TransactionServiceTest() {
62     }
63  
64     // check method called by command line verifier
65
public Result check(ConfigContext context) {
66         Result result;
67         result = super.getInitializedResult();
68         // 8.0 XML Verifier
69
/*try {
70             Server server = (Server)context.getRootConfigBean();
71             TransactionService txn = server.getTransactionService();
72             String file = txn.getTxLogDir();
73             // <addition> srini@sun.com Bug : 4698904
74             if(file==null || file.equals(""))
75                 result.failed("File Name cannot be Null");
76             else {
77                 File f = new File(file);
78                 if(f.exists())
79                     result.passed("Transaction Log Dir valid");
80                 else
81                     result.failed("Invalid Transaction Log Directory - " + file);
82             }
83             String heuDecision = txn.getHeuristicDecision();
84             if(heuDecision.equals("rollback") || heuDecision.equals("commit"))
85                 result.passed("Heurisitic Decision Valid");
86             else
87                 result.failed("Invalid Heuristic Decision - " + heuDecision );
88             // Bug : 4713369 <addition>
89             try {
90                 String resTime = txn.getTimeoutInSeconds();
91                 if(Integer.parseInt(resTime) < 0) {
92                     result.failed(smh.getLocalString(getClass().getName()+".resTimeoutNegative","Response Timeout cannot be negative number"));
93                 }
94                 else
95                     result.passed("Passed ***");
96             }catch(NumberFormatException e) {
97                 result.failed(smh.getLocalString(getClass().getName()+".resTimeoutInvalid","Response Timeout : invalid number"));
98             }
99             try {
100                 String keyPointInterval = txn.getKeypointInterval();
101                 if(Integer.parseInt(keyPointInterval) < 0) {
102                     result.failed(smh.getLocalString(getClass().getName()+".keyPointNegative","Key Point Interval cannot be negative number"));
103                 }
104                 else
105                     result.passed("Passed ***");
106             }catch(NumberFormatException e) {
107                 result.failed(smh.getLocalString(getClass().getName()+".keyPointInvalid","Key Point Interval : invalid number"));
108             }
109             // Bug : 4713369 </addition>
110         }
111         catch(Exception ex) {
112             //<addition author="irfan@sun.com" [bug/rfe]-id="logging" >
113             /*ex.printStackTrace();
114             result.failed("Exception : " + ex.getMessage());*/

115             /*_logger.log(Level.FINE, "serverxmlverifier.exception", ex);
116             result.failed("Exception : " + ex.getMessage());
117             //</addition>
118         }*/

119         return result;
120     }
121     
122     // check method called by iasadmin and adminGUI
123
public Result check(ConfigContextEvent ccce) {
124         Result result;
125         result = new Result();
126         Object JavaDoc value = ccce.getObject();
127         String JavaDoc beanName = ccce.getBeanName();
128         if(beanName!=null) {
129             String JavaDoc name = ccce.getName();
130             return testSave(name,(String JavaDoc)value);
131         }
132         
133         TransactionService txn = (TransactionService)value;
134         // <addition> srini@sun.com Bug : 4698904
135
String JavaDoc file = txn.getTxLogDir();
136         if(file==null || file.equals("")) {
137                 result.failed("File Name cannot be Null");
138                 return result;
139         }
140         // </addition>
141
File JavaDoc f = new File JavaDoc(txn.getTxLogDir());
142         if(f.exists())
143             result.passed("Transaction Log Dir valid");
144         else
145             result.failed("Invalid Transaction Log Directory");
146         String JavaDoc heuDecision = txn.getHeuristicDecision();
147         if(heuDecision.equals("rollback") || heuDecision.equals("commit"))
148             result.passed("Heurisitic Decision Valid");
149         else
150             result.failed("Invalid Heuristic Decision");
151         return result;
152     }
153     
154     public Result testSave(String JavaDoc name, String JavaDoc value) {
155         Result result = new Result();
156             result.passed("Passed **");
157         if(name.equals(ServerTags.TX_LOG_DIR)){
158                 // <addition> srini@sun.com Bug : 4698904
159
if(value==null || value.equals("")) {
160                     result.failed("File Name cannot be Null");
161                     return result;
162                 }
163                 // </addition>
164
File JavaDoc f = new File JavaDoc(value);
165                 if(f.exists())
166                     result.passed("Transaction Log Dir valid");
167                 else
168                     result.failed("Invalid Transaction Log Directory");
169             }
170             else if(name.equals(ServerTags.HEURISTIC_DECISION)){
171                 if(value.equals("rollback") || value.equals("commit"))
172                     result.passed("Heurisitic Decision Valid");
173                 else
174                     result.failed("Invalid Heuristic Decision");
175             }
176             // Bug : 4713369 <addition>
177
else if(name.equals(ServerTags.TIMEOUT_IN_SECONDS)) {
178                 try {
179                     if(Integer.parseInt(value) < 0)
180                         result.failed(smh.getLocalString(getClass().getName()+".resTimeoutNegative","Response Timeout cannot be negative number"));
181                     else
182                         result.passed("Passed ***");
183                 } catch(NumberFormatException JavaDoc e) {
184                     result.failed(smh.getLocalString(getClass().getName()+".resTimeoutInvalid","Response Timeout : invalid number"));
185                 }
186             }
187             else if(name.equals(ServerTags.KEYPOINT_INTERVAL)) {
188                 try {
189                     if(Integer.parseInt(value) < 0)
190                         result.failed(smh.getLocalString(getClass().getName()+".keyPointNegative","Key Point Interval cannot be negative number"));
191                     else
192                         result.passed("Passed ***");
193                 } catch(NumberFormatException JavaDoc e) {
194                     result.failed(smh.getLocalString(getClass().getName()+".keyPointInvalid","Key Point Interval : invalid number"));
195                 }
196             }
197            // Bug : 4713369 </addition>
198

199             return result;
200     }
201 }
202
Popular Tags