FileDocCategorySizeDatePackage
DanglingRefsTest.javaAPI DocGlassfish v2 API5680Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.config

DanglingRefsTest

public final class DanglingRefsTest extends com.sun.enterprise.management.AMXTestBase
This test should normally be run before the generic tests so that it can set up default items for many of the config elements so that the generic tests will actually test them. Otherwise, when the generic tests are run, they won't see any instances of many of the AMXConfig MBeans.

If there are errors doing this, disable this test in amxtest.classes, fix the error in the specific place it's occurring, then re-enabled this test.

Fields Summary
Constructors Summary
public DanglingRefsTest()

	
Methods Summary
private void_testDanglingResourceRefConfigs()

	    final DomainConfig  domainConfig    = getDomainConfig();
	    final Set<ResourceConfig> resourcesSet    =
	        getQueryMgr().queryInterfaceSet( ResourceConfig.class.getName(), null );
	    
	    final Set<ResourceRefConfig>
	        refs = RefHelper.findAllResourceRefConfigs( getQueryMgr() );
	    
	    final Map<String,ResourceConfig>    resourcesMap    = Util.createNameMap( resourcesSet );
	    
	    for( final ResourceRefConfig ref : refs )
	    {
	        final String    name    = ref.getName();
	        
	        final ResourceConfig    resourceConfig  = resourcesMap.get( name );
	        if ( resourceConfig == null )
	        {
	            String msg    = 
	             "Resource reference '" +
	                Util.getObjectName( ref ) + "' refers to a non-existent resource";
	            
	            boolean removedOK   = false;
	            try
	            {
	               final ResourceRefConfigCR   container   =
	                    (ResourceRefConfigCR)ref.getContainer();
	                    
	               container.removeResourceRefConfig( name );
	               removedOK    = true;
	            }
	            catch( Exception e )
	            {
	                msg = msg + ", and trying to remove it throws an Exception " +
	                "(remove it manually from domain.xml)" +
	                ", see bug #6298512";
	            }
	            
	            if ( ! removedOK )
	            {
	                warning( msg );
	            }
	        }
	        else
	        {
	            //printVerbose( "ResourceRefConfig '" + name + "' is OK" );
	        }
	    }
	
public voidtestAllDangling()

	    _testDanglingResourceRefConfigs();
	    //_testDanglingDeployedItemRefConfigs();