View Javadoc

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.el.unified;
20  
21  import static org.easymock.EasyMock.expect;
22  
23  import java.util.ArrayList;
24  import java.util.Arrays;
25  import java.util.List;
26  
27  import javax.el.ELResolver;
28  import javax.faces.el.PropertyResolver;
29  import javax.faces.el.VariableResolver;
30  
31  import org.apache.myfaces.config.RuntimeConfig;
32  import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
33  import org.apache.myfaces.el.convert.VariableResolverToELResolver;
34  import org.apache.myfaces.test.base.junit4.AbstractJsfTestCase;
35  import org.easymock.classextension.EasyMock;
36  import org.easymock.classextension.IMocksControl;
37  import org.junit.After;
38  import org.junit.Assert;
39  import org.junit.Before;
40  import org.junit.Test;
41  
42  /**
43   * @author Mathias Broekelmann (latest modification by $Author: lu4242 $)
44   * @version $Revision: 1296049 $ $Date: 2012-03-01 23:48:16 -0500 (Thu, 01 Mar 2012) $
45   */
46  @SuppressWarnings("deprecation")
47  public class ResolverBuilderBaseTest extends AbstractJsfTestCase
48  {
49      private IMocksControl _mocksControl;
50      private RuntimeConfig _runtimeConfig;
51      private ResolverBuilderBase _testImpl;
52      private List<ELResolver> _resolvers;
53      
54      public ResolverBuilderBaseTest()
55      {
56      }
57  
58      @Before
59      public void setUp() throws Exception
60      {
61          super.setUp();
62          _mocksControl = EasyMock.createNiceControl();
63          _runtimeConfig = _mocksControl.createMock(RuntimeConfig.class);
64          _testImpl = new ResolverBuilderBase(_runtimeConfig);
65          _resolvers = new ArrayList<ELResolver>();
66      }
67      
68      @After
69      public void tearDown() throws Exception
70      {
71          super.tearDown();
72          _mocksControl = null;
73          _runtimeConfig = null;
74          _testImpl = null;
75          _resolvers = null;
76      }
77  
78      /*
79      @Test
80      public void testGetFacesConfigElResolvers() throws Exception
81      {
82          ELResolver resolver = _mocksControl.createMock(ELResolver.class);
83          expect(_runtimeConfig.getFacesConfigElResolvers()).andReturn(resolver).anyTimes();
84          _compositeELResolver = _mocksControl.createMock(CompositeELResolver.class);
85          _compositeELResolver.add(eq(resolver));
86          _mocksControl.replay();
87          _testImpl.addFromRuntimeConfig(_compositeELResolver);
88          _mocksControl.verify();
89      }*/
90  
91      @Test
92      public void testGetApplicationElResolvers() throws Exception
93      {
94          ELResolver resolver = _mocksControl.createMock(ELResolver.class);
95          expect(_runtimeConfig.getApplicationElResolvers()).andReturn(Arrays.asList(resolver)).anyTimes();
96          _mocksControl.replay();
97          _testImpl.addFromRuntimeConfig(_resolvers);
98          _mocksControl.verify();
99          Assert.assertEquals(Arrays.asList(resolver), _resolvers);
100     }
101 
102     @Test
103     public void testGetVariableResolver() throws Exception
104     {
105         VariableResolver resolver = _mocksControl.createMock(VariableResolver.class);
106         expect(_runtimeConfig.getVariableResolver()).andReturn(resolver).anyTimes();
107         _mocksControl.replay();
108         _testImpl.addFromRuntimeConfig(_resolvers);
109         _mocksControl.verify();
110         
111         VariableResolverToELResolver elResolver
112                 = (VariableResolverToELResolver) _resolvers.get(0);
113         Assert.assertEquals(resolver, elResolver.getVariableResolver());
114     }
115 
116     @Test
117     public void testGetVariableResolverChainHead() throws Exception
118     {
119         VariableResolver resolver = _mocksControl.createMock(VariableResolver.class);
120         EasyMock.expect(_runtimeConfig.getVariableResolverChainHead()).andReturn(resolver).anyTimes();
121         _mocksControl.replay();
122         _testImpl.addFromRuntimeConfig(_resolvers);
123         _mocksControl.verify();
124         
125         VariableResolverToELResolver elResolver
126                 = (VariableResolverToELResolver) _resolvers.get(0);
127         Assert.assertEquals(resolver, elResolver.getVariableResolver());
128     }
129 
130     @Test
131     public void testGetPropertyResolver() throws Exception
132     {
133         PropertyResolver resolver = _mocksControl.createMock(PropertyResolver.class);
134         expect(_runtimeConfig.getPropertyResolver()).andReturn(resolver).anyTimes();
135         _mocksControl.replay();
136         _testImpl.addFromRuntimeConfig(_resolvers);
137         _mocksControl.verify();
138         
139         PropertyResolverToELResolver elResolver
140                 = (PropertyResolverToELResolver) _resolvers.get(0);
141         Assert.assertEquals(resolver, elResolver.getPropertyResolver());
142     }
143 
144     @Test
145     public void testGetPropertyResolverChainHead() throws Exception
146     {
147         PropertyResolver resolver = _mocksControl.createMock(PropertyResolver.class);
148         EasyMock.expect(_runtimeConfig.getPropertyResolverChainHead()).andReturn(resolver).anyTimes();
149         _mocksControl.replay();
150         _testImpl.addFromRuntimeConfig(_resolvers);
151         _mocksControl.verify();
152         
153 
154         PropertyResolverToELResolver elResolver
155                 = (PropertyResolverToELResolver) _resolvers.get(0);
156         Assert.assertEquals(resolver, elResolver.getPropertyResolver());
157     }
158 
159 }