View Javadoc

1   package org.apache.myfaces.config.annotation;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.test.base.AbstractJsfTestCase;
21  
22  import javax.naming.NamingException;
23  import java.lang.reflect.InvocationTargetException;
24  
25  
26  public class AnnotationProcessorTestCase extends AbstractJsfTestCase
27  {
28      protected LifecycleProvider2 lifecycleProvider;
29      protected AnnotatedManagedBean managedBean;
30  
31  
32      public AnnotationProcessorTestCase(String string)
33      {
34          super(string);
35      }
36  
37      public void setUp() throws Exception {
38          super.setUp();
39          lifecycleProvider = new AllAnnotationLifecycleProvider(null);
40          managedBean = new AnnotatedManagedBean();
41      }
42  
43      public void testPostConstruct() throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException
44      {
45          AnnotatedManagedBean managedBean = (AnnotatedManagedBean) lifecycleProvider.newInstance(AnnotatedManagedBean.class.getName());
46          lifecycleProvider.postConstruct(managedBean);
47          assertTrue(managedBean.isPostConstructCalled());
48          assertFalse(managedBean.isPreDestroyCalled());
49      }
50  
51      public void testPreDestroy() throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException
52      {
53          AnnotatedManagedBean managedBean = (AnnotatedManagedBean) lifecycleProvider.newInstance(AnnotatedManagedBean.class.getName());
54          lifecycleProvider.postConstruct(managedBean);
55          lifecycleProvider.destroyInstance(managedBean);
56          assertTrue(managedBean.isPostConstructCalled());
57          assertTrue(managedBean.isPreDestroyCalled());
58      }
59  
60      public void testPostConstructException() throws IllegalAccessException, InvocationTargetException
61      {
62          try
63          {
64              lifecycleProvider.destroyInstance(new AnnotatedManagedBean(true));
65          } catch (InvocationTargetException e) {
66              return;  
67          }
68          assertTrue(false);
69  
70      }
71  }