KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > DanglingRefsTest


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 package com.sun.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27
28
29 import com.sun.appserv.management.helper.RefHelper;
30 import com.sun.appserv.management.base.Util;
31
32 import com.sun.appserv.management.config.*;
33
34
35 import com.sun.enterprise.management.AMXTestBase;
36 import com.sun.enterprise.management.Capabilities;
37
38
39
40 /**
41     This test should normally be run before the generic tests
42     so that it can set up default items for many of the config elements
43     so that the generic tests will actually test them. Otherwise,
44     when the generic tests are run, they won't see any instances
45     of many of the AMXConfig MBeans.
46     <p>
47     If there are errors doing this, disable this test in amxtest.classes,
48     fix the error in the specific place it's occurring, then re-enabled
49     this test.
50  */

51 public final class DanglingRefsTest extends AMXTestBase
52 {
53         public
54     DanglingRefsTest( )
55     {
56     }
57         public void
58     testAllDangling()
59         throws ClassNotFoundException JavaDoc
60     {
61         _testDanglingResourceRefConfigs();
62         //_testDanglingDeployedItemRefConfigs();
63
}
64     
65         private void
66     _testDanglingResourceRefConfigs()
67         throws ClassNotFoundException JavaDoc
68     {
69         final DomainConfig domainConfig = getDomainConfig();
70         final Set JavaDoc<ResourceConfig> resourcesSet =
71             getQueryMgr().queryInterfaceSet( ResourceConfig.class.getName(), null );
72         
73         final Set JavaDoc<ResourceRefConfig>
74             refs = RefHelper.findAllResourceRefConfigs( getQueryMgr() );
75         
76         final Map JavaDoc<String JavaDoc,ResourceConfig> resourcesMap = Util.createNameMap( resourcesSet );
77         
78         for( final ResourceRefConfig ref : refs )
79         {
80             final String JavaDoc name = ref.getName();
81             
82             final ResourceConfig resourceConfig = resourcesMap.get( name );
83             if ( resourceConfig == null )
84             {
85                 String JavaDoc msg =
86                  "Resource reference '" +
87                     Util.getObjectName( ref ) + "' refers to a non-existent resource";
88                 
89                 boolean removedOK = false;
90                 try
91                 {
92                    final ResourceRefConfigCR container =
93                         (ResourceRefConfigCR)ref.getContainer();
94                         
95                    container.removeResourceRefConfig( name );
96                    removedOK = true;
97                 }
98                 catch( Exception JavaDoc e )
99                 {
100                     msg = msg + ", and trying to remove it throws an Exception " +
101                     "(remove it manually from domain.xml)" +
102                     ", see bug #6298512";
103                 }
104                 
105                 if ( ! removedOK )
106                 {
107                     warning( msg );
108                 }
109             }
110             else
111             {
112                 //printVerbose( "ResourceRefConfig '" + name + "' is OK" );
113
}
114         }
115     }
116     
117     /*
118        private void
119     _testDanglingDeployedItemRefConfigs()
120         throws ClassNotFoundException
121     {
122         final DomainConfig domainConfig = getDomainConfig();
123         
124         final Set<DeployedItemRefConfig> s = (Set<DeployedItemRefConfig>)
125             getQueryMgr().queryInterfaceSet( DeployedItemRefConfig.class.getName(), null );
126         
127         final Set<DeployedItemRefConfig>
128             refs = RefHelper.findAllDeployedItemRefConfigRefs( getQueryMgr() );
129             
130         final Map<String,DeployedItem> deployedItemsMap = Util.createNameMap( s );
131         
132         for( final DeployedItemRefConfig ref : refs )
133         {
134             final String name = ref.getName();
135             
136             final DeployedItem deployedItem = deployedItemsMap.get( name );
137             assert( deployedItem != null ) :
138                 "Deployed item reference '" + Util.getObjectName( ref ) +
139                     "' refers to a non-existent item";
140         }
141     }
142     */

143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Popular Tags