View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.myfaces.config.annotation;
18  
19  import org.apache.myfaces.config.ManagedBeanBuilder;
20  import org.apache.myfaces.config.impl.digester.elements.ManagedBeanImpl;
21  import org.apache.myfaces.config.impl.digester.elements.ManagedPropertyImpl;
22  import org.apache.myfaces.test.base.AbstractJsfTestCase;
23  
24  /**
25   * Test MYFACES-1761 Handling PostConstruct annotations - wrong order 
26   * 
27   * @author Leonardo Uribe
28   *
29   */
30  public class Myfaces1761TestCase extends AbstractJsfTestCase
31  {
32  
33      protected ManagedBeanBuilder managedBeanBuilder;
34      protected LifecycleProvider2 lifecycleProvider;
35      protected ManagedBeanImpl beanConfiguration;
36      
37      private static final String TEST_LIFECYCLE_PROVIDER = MockLifecycleProvider2.class.getName();
38      
39      protected static final String INJECTED_VALUE = "tatiana";
40      
41      public Myfaces1761TestCase(String name)
42      {
43          super(name);
44      }
45  
46      protected void setUp() throws Exception
47      {
48          super.setUp();
49          managedBeanBuilder  = new ManagedBeanBuilder();
50          
51          beanConfiguration = new ManagedBeanImpl();        
52          beanConfiguration.setBeanClass(AnnotatedManagedBean2.class.getName());
53          beanConfiguration.setName("managed");
54          beanConfiguration.setScope("request");
55          
56          ManagedPropertyImpl managedProperty = new ManagedPropertyImpl();
57          managedProperty.setPropertyName("managedProperty");
58          managedProperty.setValue(INJECTED_VALUE);
59          beanConfiguration.addProperty(managedProperty);
60          
61          LifecycleProviderFactory.getLifecycleProviderFactory(externalContext).release();
62          servletContext.addInitParameter(DefaultLifecycleProviderFactory.LIFECYCLE_PROVIDER, TEST_LIFECYCLE_PROVIDER);
63      }
64  
65      public void tearDown() throws Exception
66      {
67          LifecycleProviderFactory.getLifecycleProviderFactory(externalContext).release();
68          super.tearDown();
69          managedBeanBuilder = null;
70      }
71      
72      public void testPostConstruct() throws Exception
73      {
74          AnnotatedManagedBean2 bean = (AnnotatedManagedBean2) managedBeanBuilder.buildManagedBean(facesContext, beanConfiguration);
75          assertEquals(INJECTED_VALUE, bean.getManagedProperty());
76          assertTrue(bean.isPostConstructCalled());
77      }
78  }