Coverage Report - org.apache.maven.wagon.tck.http.WagonTestCaseConfigurator
 
Classes in this File Line Coverage Branch Coverage Complexity
WagonTestCaseConfigurator
0 %
0/33
0 %
0/12
2,429
 
 1  
 package org.apache.maven.wagon.tck.http;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with 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,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.log4j.Logger;
 23  
 import org.apache.maven.wagon.Wagon;
 24  
 import org.codehaus.plexus.PlexusConstants;
 25  
 import org.codehaus.plexus.PlexusContainer;
 26  
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
 27  
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 28  
 import org.codehaus.plexus.component.configurator.ComponentConfigurator;
 29  
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 30  
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 31  
 import org.codehaus.plexus.context.Context;
 32  
 import org.codehaus.plexus.context.ContextException;
 33  
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 34  
 
 35  0
 public class WagonTestCaseConfigurator
 36  
     implements Contextualizable
 37  
 {
 38  
     private static final String UNSUPPORTED_ELEMENT = "unsupported";
 39  
 
 40  
     private PlexusConfiguration useCaseConfigs;
 41  
 
 42  
     private ComponentConfigurator configurator;
 43  
 
 44  
     private ClassRealm realm;
 45  
 
 46  
     private String wagonHint;
 47  
 
 48  0
     private static Logger logger = Logger.getLogger( WagonTestCaseConfigurator.class );
 49  
 
 50  
     public boolean isSupported( final String useCaseId )
 51  
     {
 52  0
         if ( useCaseConfigs != null )
 53  
         {
 54  0
             PlexusConfiguration config = useCaseConfigs.getChild( useCaseId, false );
 55  
 
 56  0
             if ( config != null && config.getChild( UNSUPPORTED_ELEMENT, false ) != null )
 57  
             {
 58  0
                 logger.info( "Test case '" + useCaseId + "' is marked as unsupported by this wagon." );
 59  0
                 return false;
 60  
             }
 61  
         }
 62  
 
 63  0
         return true;
 64  
     }
 65  
 
 66  
     public boolean configureWagonForTest( final Wagon wagon, final String useCaseId )
 67  
         throws ComponentConfigurationException
 68  
     {
 69  0
         if ( useCaseConfigs != null )
 70  
         {
 71  0
             PlexusConfiguration config = useCaseConfigs.getChild( useCaseId, false );
 72  
 
 73  0
             if ( config != null )
 74  
             {
 75  0
                 if ( config.getChild( UNSUPPORTED_ELEMENT, false ) != null )
 76  
                 {
 77  0
                     logger.error( "Test case '" + useCaseId + "' is marked as unsupported by this wagon." );
 78  0
                     return false;
 79  
                 }
 80  
                 else
 81  
                 {
 82  0
                     logger.info( "Configuring wagon for test case: " + useCaseId + " with:\n\n" + config );
 83  0
                     configurator.configureComponent( wagon, useCaseConfigs.getChild( useCaseId, false ), realm );
 84  
                 }
 85  
             }
 86  
             else
 87  
             {
 88  0
                 logger.info( "No wagon configuration found for test case: " + useCaseId );
 89  
             }
 90  0
         }
 91  
         else
 92  
         {
 93  0
             logger.info( "No test case configurations found." );
 94  
         }
 95  
 
 96  0
         return true;
 97  
     }
 98  
 
 99  
     public void contextualize( final Context context )
 100  
         throws ContextException
 101  
     {
 102  0
         PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
 103  0
         this.realm = container.getContainerRealm();
 104  
         try
 105  
         {
 106  0
             configurator = (ComponentConfigurator) container.lookup( ComponentConfigurator.ROLE );
 107  
         }
 108  0
         catch ( ComponentLookupException e )
 109  
         {
 110  0
             throw new ContextException( "Failed to lookup component configurator: " + e.getMessage(), e );
 111  0
         }
 112  0
     }
 113  
 
 114  
     public PlexusConfiguration getUseCaseConfigs()
 115  
     {
 116  0
         return useCaseConfigs;
 117  
     }
 118  
 
 119  
     public void setUseCaseConfigs( final PlexusConfiguration useCaseConfigs )
 120  
     {
 121  0
         this.useCaseConfigs = useCaseConfigs;
 122  0
     }
 123  
 
 124  
     public String getWagonHint()
 125  
     {
 126  0
         return wagonHint;
 127  
     }
 128  
 
 129  
     public void setWagonHint( final String wagonHint )
 130  
     {
 131  0
         this.wagonHint = wagonHint;
 132  0
     }
 133  
 
 134  
 }