KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > services > T_Diagnosticable


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.services.T_Diagnosticable
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.unitTests.services;
23
24 import org.apache.derby.iapi.services.context.ContextService;
25 import org.apache.derby.iapi.services.diag.Diagnosticable;
26 import org.apache.derby.iapi.services.diag.DiagnosticUtil;
27 import org.apache.derby.iapi.services.monitor.Monitor;
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29 import org.apache.derby.iapi.error.StandardException;
30 import org.apache.derby.iapi.store.access.AccessFactory;
31 import org.apache.derby.iapi.store.access.ConglomerateController;
32 import org.apache.derby.iapi.store.access.TransactionController;
33 import org.apache.derby.iapi.store.raw.ContainerHandle;
34 import org.apache.derby.iapi.store.raw.ContainerKey;
35 import org.apache.derby.iapi.store.raw.Page;
36 import org.apache.derby.iapi.store.raw.Transaction;
37 import org.apache.derby.iapi.store.raw.RawStoreFactory;
38
39
40 import org.apache.derbyTesting.unitTests.harness.T_MultiIterations;
41 import org.apache.derbyTesting.unitTests.harness.T_Fail;
42 import org.apache.derby.iapi.reference.Property;
43
44 import java.util.Properties JavaDoc;
45
46 // DEBUGGING:
47

48 /**
49
50   This T_Diagnosticable class provides a sample of how to use the "Diagnostic"
51   facility. The classes methods are built to be called by a "values" or
52   a "call" statement from "ij". Eventually there will be some sort of
53   diagnostic monitor which will be used to call the various "D_*" routines.
54
55 **/

56
57
58 public class T_Diagnosticable extends T_MultiIterations
59 {
60     private static final String JavaDoc testService = "DiagnosticableTest";
61
62
63     /* Constructors for This class: */
64
65     /**
66      * No arg Constructor.
67      **/

68     public T_Diagnosticable()
69     {
70     }
71
72     /* Private/Protected methods of This class: */
73
74     /**
75      * Simple test of DiagnosticUtil interfaces.
76      * <p>
77      * Simple test of DiagnosticUtil.toDiagString() and
78      * DiagnosticUtil.findDiagnostic() interfaces.
79      *
80      * @exception T_Fail If test fails for some reason.
81      **/

82     private void t_001()
83         throws T_Fail
84     {
85         // Create object with also has a diagnostic interface:
86
Object JavaDoc diag_obj = new T_DiagTestClass1("object with diag interface");
87
88         // Create an object in a sub-class that doesn't have a D_ class, but
89
// its super-class does.
90
Object JavaDoc diagSubObj = new T_DiagTestClass1Sub("sub-class");
91
92         // Create object with neither Diagnosticable:
93
Object JavaDoc obj = new Long JavaDoc(5);
94
95         // Test just getting a single string back, from each type of object.
96
String JavaDoc str = null;
97         String JavaDoc expected_str = null;
98         Diagnosticable helper_class = null;
99
100         // Here the string should come from the Diagnostic object's diag().
101
str = DiagnosticUtil.toDiagString(diag_obj);
102         expected_str = "D_T_DiagTestClass1: object with diag interface";
103
104         if (str.compareTo(expected_str) != 0)
105         {
106             throw T_Fail.testFailMsg(
107                 "DiagnosticUtil.toDiagString() failed, got: (" + str +
108                 "), expected: (" + expected_str + ").");
109         }
110
111
112         // make sure right class was found.
113

114         helper_class = DiagnosticUtil.findDiagnostic(diag_obj);
115         
116         if (!(helper_class instanceof D_T_DiagTestClass1))
117             throw T_Fail.testFailMsg("Bad helper class lookup.");
118
119         // make sure helper class gives right string.
120

121         try
122         {
123             str = helper_class.diag();
124         }
125         catch (Throwable JavaDoc t)
126         {
127             throw T_Fail.testFailMsg(
128                 "Unexpected exception from helper_class.diag() call");
129         }
130
131         if (!str.equals(expected_str))
132         {
133             throw T_Fail.testFailMsg(
134                 "DiagnosticUtil.toDiagString() failed, got: (" + str +
135                 "), expected: (" + expected_str + ").");
136         }
137
138         // make sure the Diagnostic class picks up a super-version of the D_ class
139
str = DiagnosticUtil.toDiagString(diagSubObj);
140         expected_str = "D_T_DiagTestClass1: sub-class";
141         if (!str.equals(expected_str))
142         {
143             throw T_Fail.testFailMsg(
144                 "DiagnosticUtil.toDiagString() failed, got: (" + str +
145                 "), expected: (" + expected_str + ").");
146         }
147         
148         // Here the string should just be the system's default toString.
149
str = DiagnosticUtil.toDiagString(obj);
150         expected_str = "5";
151
152         if (str.compareTo(expected_str) != 0)
153         {
154             throw T_Fail.testFailMsg(
155                 "DiagnosticUtil.toDiagString() failed, got: (" + str +
156                 "), expected: (" + expected_str + ").");
157         }
158
159         // check that lookup for this class return correctly returns null,
160
// since help class does not exist.
161
helper_class = DiagnosticUtil.findDiagnostic(obj);
162
163         if (helper_class != null)
164             throw T_Fail.testFailMsg("Bad helper class - should be null.");
165     }
166
167
168     /* Public Methods of T_MultiIterations class: */
169
170     /**
171      * Routine one once per invocation of the test by the driver.
172      * <p>
173      * Do work that should only be done once, no matter how many times
174      * runTests() may be executed.
175      *
176      * @exception T_Fail Thrown on any error.
177      **/

178     protected void setupTest()
179         throws T_Fail
180     {
181         // don't automatic boot this service if it gets left around
182
if (startParams == null) {
183             startParams = new Properties JavaDoc();
184         }
185         startParams.put(Property.NO_AUTO_BOOT, Boolean.TRUE.toString());
186         // remove the service directory to ensure a clean run
187
startParams.put(Property.DELETE_ON_CREATE, Boolean.TRUE.toString());
188     }
189
190     /*
191     ** Methods required by T_Generic
192     */

193
194     public String JavaDoc getModuleToTestProtocolName() {
195         return("org.apache.derby.iapi.services.diag.DiagnosticUtil");
196     }
197
198     /**
199      * Driver routine for the btree secondary index tests.
200      * <p>
201      *
202      * @exception T_Fail Throws T_Fail on any test failure.
203      **/

204     protected void runTestSet() throws T_Fail
205     {
206         out.println("Executing " + testService + " test.");
207
208         t_001();
209
210         out.println("Finished Executing " + testService + " test.");
211     }
212 }
213
Popular Tags