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.webapp;
20  
21  import static org.easymock.EasyMock.*;
22  
23  import javax.el.ELContext;
24  import javax.el.ELContextEvent;
25  import javax.el.ELContextListener;
26  import javax.faces.application.Application;
27  import javax.faces.context.FacesContext;
28  
29  import junit.framework.TestCase;
30  
31  import org.apache.myfaces.test.mock.MockFacesContext12;
32  import org.easymock.IMocksControl;
33  import org.easymock.classextension.EasyMock;
34  
35  /**
36   * @author Mathias Broekelmann (latest modification by $Author: lu4242 $)
37   * @version $Revision: 883907 $ $Date: 2009-11-24 17:37:53 -0500 (Tue, 24 Nov 2009) $
38   */
39  public class FacesELContextListenerTest extends TestCase
40  {
41  
42      /**
43       * Test method for {@link org.apache.myfaces.webapp.FacesELContextListener#contextCreated(javax.el.ELContextEvent)}.
44       */
45      public void testContextCreated()
46      {
47          FacesELContextListener listener = new FacesELContextListener();
48          IMocksControl mockControl = EasyMock.createControl();
49          ELContext elctx = mockControl.createMock(ELContext.class);
50          MockFacesContext12 facesctx = new MockFacesContext12();
51          Application app = mockControl.createMock(Application.class);
52          facesctx.setApplication(app);
53          ELContextEvent event = mockControl.createMock(ELContextEvent.class);
54          expect(event.getELContext()).andReturn(elctx);
55          elctx.putContext(eq(FacesContext.class), same(facesctx));
56          ELContextListener elctxListener = mockControl.createMock(ELContextListener.class);
57          expect(app.getELContextListeners()).andReturn(new ELContextListener[] { elctxListener });
58          elctxListener.contextCreated(same(event));
59          mockControl.replay();
60          listener.contextCreated(event);
61          mockControl.verify();
62      }
63  
64  }