KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > monitor > CallFlowMonitorTest


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.management.monitor;
25
26 import java.util.Set JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import com.sun.appserv.management.base.XTypes;
31
32 import com.sun.appserv.management.DomainRoot;
33
34 import com.sun.appserv.management.monitor.ServerRootMonitor;
35 import com.sun.appserv.management.monitor.CallFlowMonitor;
36
37 import com.sun.enterprise.management.AMXTestBase;
38 import com.sun.enterprise.management.Capabilities;
39
40 public final class CallFlowMonitorTest extends AMXMonitorTestBase
41 {
42     private String JavaDoc IP_FILTER_NAME = "129.129.129.129";
43     private String JavaDoc PRINCIPAL_FILTER_NAME = "Harry";
44         public CallFlowMonitorTest()
45     {
46     }
47     
48     public void testCallFlowOn()
49     {
50         final CallFlowMonitor cfm = getCallFlowMonitor();
51         try
52         {
53             cfm.setEnabled ( true );
54             assertTrue( cfm.getEnabled() );
55         }
56         catch( Throwable JavaDoc t )
57         {
58             warning( "testCallFlowOn: " +
59                 "Can't enable callflow...has the callflow database been started?" );
60         }
61      }
62     
63     public void testIPFilter () {
64             final CallFlowMonitor cfm = getCallFlowMonitor();
65             cfm.setCallerIPFilter(IP_FILTER_NAME);
66             final String JavaDoc filter = cfm.getCallerIPFilter();
67             boolean val = filter.equals(IP_FILTER_NAME);
68             assertTrue(val);
69     }
70         
71     public void testPrincipalFilter () {
72             final CallFlowMonitor cfm = getCallFlowMonitor();
73             cfm.setCallerPrincipalFilter(PRINCIPAL_FILTER_NAME);
74             final String JavaDoc filter = cfm.getCallerPrincipalFilter();
75             boolean val = filter.equals(PRINCIPAL_FILTER_NAME);
76             assertTrue(val);
77     }
78         
79     /*
80      * Disable CallFlow
81      */

82     public void testCallFlowOff() {
83         final CallFlowMonitor cfm = getCallFlowMonitor();
84         cfm.setEnabled( false );
85         assertFalse( cfm.getEnabled() );
86     }
87
88     public void testQueryRequestInformation (){
89         final CallFlowMonitor cfm = getCallFlowMonitor();
90         final List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> list = cfm.queryRequestInformation ();
91         if(list == null)
92     // int resultSize = list.size ();
93
// int CORRECT_RESULT_SIZE = 0;
94
// if (resultSize == CORRECT_RESULT_SIZE)
95
assertTrue (true);
96     }
97     public void testQueryCallStackInformation(){
98         final CallFlowMonitor cfm = getCallFlowMonitor();
99         final List JavaDoc<Map JavaDoc<String JavaDoc, String JavaDoc>> list = cfm.queryCallStackForRequest ("RequestID_1");
100         if(list == null)
101     // int resultSize = list.size ();
102
// int CORRECT_RESULT_SIZE = 0;
103
// if (resultSize == CORRECT_RESULT_SIZE)
104
assertTrue (true);
105     }
106       public void testQueryPieInformation(){
107         final CallFlowMonitor cfm = getCallFlowMonitor();
108         final Map JavaDoc<String JavaDoc, String JavaDoc> map = cfm.queryPieInformation ("RequestID_1");
109         if(map != null)
110     // int resultSize = list.size ();
111
// int CORRECT_RESULT_SIZE = 0;
112
// if (resultSize == CORRECT_RESULT_SIZE)
113
assertTrue (true);
114     }
115       
116
117     public void testClearData () {
118             final CallFlowMonitor cfm = getCallFlowMonitor();
119             cfm.clearData();
120     }
121
122     public void testQueryRequestTypeKeys (){
123         final CallFlowMonitor cfm = getCallFlowMonitor();
124         final String JavaDoc[] rT = cfm.queryRequestTypeKeys();
125         if (rT.length == 5)
126             assertTrue(true);
127         else
128             assertTrue (false);
129     }
130     public void testQueryComponentTypeKeys (){
131         final CallFlowMonitor cfm = getCallFlowMonitor();
132         final String JavaDoc[] rT = cfm.queryComponentTypeKeys();
133         assert rT.length == 7;
134     }
135     public void testQueryContainerTypeOrApplicationTypeKeys (){
136         final CallFlowMonitor cfm = getCallFlowMonitor();
137         final String JavaDoc[] rT = cfm.queryContainerTypeOrApplicationTypeKeys();
138         assert rT.length == 6;
139     }
140
141         
142
143     private CallFlowMonitor getCallFlowMonitor() {
144         Map JavaDoc<String JavaDoc,ServerRootMonitor> serverRootMonitorMap =
145                 getDomainRoot().getMonitoringRoot().getServerRootMonitorMap();
146         // Get the server name from some MBean. Using the default value for now
147
ServerRootMonitor serverRootMonitor = serverRootMonitorMap.get("server");
148         return serverRootMonitor.getCallFlowMonitor();
149     }
150
151     public void testExactlyOneDASCallFlowMonitor()
152     {
153         final Set JavaDoc<CallFlowMonitor> cfms =
154             getQueryMgr().queryJ2EETypeSet( XTypes.CALL_FLOW_MONITOR );
155         
156         int numDAS = 0;
157         int numNonDAS = 0;
158         for( final CallFlowMonitor cfm : cfms )
159         {
160             if ( cfm.isDAS() )
161             {
162                 ++numDAS;
163             }
164             else
165             {
166                 ++numNonDAS;
167             }
168         }
169         
170         if ( numNonDAS == 0 )
171         {
172             warning( "testExactlyOneDASCallFlowMonitor: no instances other than DAS are running" );
173         }
174         
175         assert numDAS == 1 :
176             "There must be exactly one CallFlowMonitor in the DAS, but there are " + numDAS +
177             " and there are " + numNonDAS + " non-DAS CallFlowMonitor.";
178         
179     }
180 }
181
182
183     
184
Popular Tags