Coverage Report - org.apache.myfaces.mc.test.core.AbstractMyFacesCDIRequestTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractMyFacesCDIRequestTestCase
0%
0/17
0%
0/4
1.857
AbstractMyFacesCDIRequestTestCase$CDIJUnitFacesInitializer
0%
0/19
N/A
1.857
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.mc.test.core;
 20  
 
 21  
 import javax.faces.FacesException;
 22  
 import javax.faces.context.ExternalContext;
 23  
 import javax.servlet.ServletContext;
 24  
 import org.apache.myfaces.shared.util.ClassUtils;
 25  
 import org.apache.myfaces.spi.InjectionProvider;
 26  
 import org.apache.myfaces.spi.InjectionProviderException;
 27  
 import org.apache.myfaces.spi.InjectionProviderFactory;
 28  
 import org.apache.myfaces.spi.impl.CDIAnnotationDelegateInjectionProvider;
 29  
 import org.apache.myfaces.webapp.AbstractFacesInitializer;
 30  
 
 31  
 /**
 32  
  *
 33  
  */
 34  0
 public class AbstractMyFacesCDIRequestTestCase extends AbstractMyFacesRequestTestCase
 35  
 {
 36  
     
 37  
     //protected WebBeansConfigurationListener owbListener;
 38  
     private Object owbListener;
 39  
     protected InjectionProvider injectionProvider;
 40  
     
 41  
     @Override
 42  
     protected void setUpWebConfigParams() throws Exception
 43  
     {
 44  0
         super.setUpWebConfigParams();
 45  0
         servletContext.addInitParameter("org.apache.myfaces.spi.InjectionProvider", 
 46  
             CDIAnnotationDelegateInjectionProvider.class.getName());
 47  0
    }
 48  
     
 49  
     @Override
 50  
     protected void setUpServletListeners() throws Exception
 51  
     {
 52  0
         Class listenerClass = ClassUtils.classForName("org.apache.webbeans.servlet.WebBeansConfigurationListener");
 53  0
         if (listenerClass == null)
 54  
         {
 55  0
             listenerClass = ClassUtils.classForName("org.jboss.weld.environment.servlet.Listener");
 56  
         }
 57  0
         if (listenerClass != null)
 58  
         {
 59  0
             owbListener = ClassUtils.newInstance(listenerClass);
 60  0
             webContainer.subscribeListener(owbListener);
 61  
         }
 62  0
         super.setUpServletListeners();
 63  0
     }
 64  
 
 65  
     @Override
 66  
     protected void tearDownServletListeners() throws Exception
 67  
     {
 68  0
         super.tearDownServletListeners();
 69  0
         owbListener = null;
 70  0
     }
 71  
 
 72  
     @Override
 73  
     protected AbstractFacesInitializer createFacesInitializer()
 74  
     {
 75  0
         return new CDIJUnitFacesInitializer(this);
 76  
     }
 77  
     
 78  0
     protected class CDIJUnitFacesInitializer extends AbstractMyFacesTestCase.JUnitFacesInitializer
 79  
     {
 80  
         private Object testCaseCreationMetadata;
 81  
 
 82  
         public CDIJUnitFacesInitializer(AbstractMyFacesTestCase testCase)
 83  0
         {
 84  0
             super(testCase);
 85  0
         }
 86  
 
 87  
         @Override
 88  
         protected void initContainerIntegration(ServletContext servletContext, ExternalContext externalContext)
 89  
         {
 90  0
             super.initContainerIntegration(servletContext, externalContext);
 91  
             
 92  0
             InjectionProviderFactory ipf = InjectionProviderFactory.getInjectionProviderFactory();
 93  0
             injectionProvider = ipf.getInjectionProvider(externalContext);
 94  0
             AbstractMyFacesTestCase testCase = getTestCase();
 95  
             try
 96  
             {
 97  0
                 testCaseCreationMetadata = injectionProvider.inject(testCase);
 98  0
                 injectionProvider.postConstruct(testCase, testCaseCreationMetadata);
 99  
             }
 100  0
             catch (InjectionProviderException ex)
 101  
             {
 102  0
                 throw new FacesException("Cannot inject JUnit Test case", ex);
 103  0
             }
 104  0
         }
 105  
 
 106  
         @Override
 107  
         public void destroyFaces(ServletContext servletContext)
 108  
         {
 109  
             try
 110  
             {
 111  0
                 injectionProvider.preDestroy(getTestCase(), testCaseCreationMetadata);
 112  
             }
 113  0
             catch (InjectionProviderException ex)
 114  
             {
 115  0
                 throw new FacesException("Cannot call @PreDestroy over inject JUnit Test case", ex);
 116  0
             }
 117  0
             super.destroyFaces(servletContext);
 118  0
         }
 119  
         
 120  
         
 121  
     }
 122  
 }