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.trinidadbuild.test;
20  
21  import java.util.Collection;
22  
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import javax.el.ELContext;
28  
29  import javax.faces.application.Application;
30  import javax.faces.application.ApplicationWrapper;
31  import javax.faces.context.ExternalContext;
32  import javax.faces.context.FacesContext;
33  import javax.faces.context.PartialResponseWriter;
34  import javax.faces.context.PartialViewContext;
35  import javax.faces.event.PhaseId;
36  import javax.faces.event.SystemEvent;
37  import javax.faces.lifecycle.Lifecycle;
38  
39  import org.apache.shale.test.mock.MockFacesContext;
40  import org.apache.shale.test.mock.MockApplication12;
41  
42  
43  public class MockFacesContext12 extends MockFacesContext
44  {
45    public MockFacesContext12(ExternalContext ec,
46                              Lifecycle   lifecycle,
47                              Application application)
48    {
49      super(ec, lifecycle);
50      elContext = createELContext(application);
51      elContext.putContext(FacesContext.class, this);
52      _app = application;
53    }
54  
55    public MockFacesContext12(Application application)
56    {
57      elContext = createELContext(application);
58      elContext.putContext(FacesContext.class, this);
59      _app = application;
60    }
61    
62    public PhaseId getCurrentPhaseId() 
63    {
64      return _currentPhaseId;
65    }
66    
67    public void setCurrentPhaseId(PhaseId phaseId)
68    {
69      this._currentPhaseId = phaseId;
70    }
71  
72    public ELContext getELContext()
73    {
74      return elContext;
75    }
76  
77    protected MockELContext createELContext(Application application)
78    {
79      return new MockELContext(application);
80    }
81    
82    public Map<Object,Object> getAttributes()
83    {
84      return _attrs;
85    }
86    
87    public PartialViewContext getPartialViewContext()
88    {
89      return _mockPartialContext;
90    }
91    
92    public Application getApplication()
93    {
94      return new ApplicationWrapper()
95      {
96        public Application getWrapped()  
97        {
98          return _app;
99        }
100       public void publishEvent(FacesContext context,
101                                Class<? extends SystemEvent> systemEventClass,
102                                Class<?> sourceBaseType,
103                                Object source)
104       {
105         // do nothing
106       }
107       
108       public void publishEvent(FacesContext context,
109                                Class<? extends SystemEvent> systemEventClass,
110                                Object source)
111       {
112         //do nothing
113       }
114     };
115   }
116 
117   protected MockELContext elContext;
118   
119   private PhaseId _currentPhaseId;
120 
121   private final PartialViewContext _mockPartialContext = new MockPartialViewContext();
122   private final Map<Object, Object> _attrs = new HashMap<Object, Object>();
123   private Application _app;
124   
125   private static class MockPartialViewContext extends PartialViewContext
126   {
127     public Collection<String> getExecuteIds()
128     {
129       throw new UnsupportedOperationException();
130     }
131     
132     public Collection<String> getRenderIds()
133     {
134       throw new UnsupportedOperationException();
135     }
136     
137     public PartialResponseWriter getPartialResponseWriter()
138     {
139       throw new UnsupportedOperationException();
140     }
141     
142     public boolean isAjaxRequest()
143     {
144       return false;
145     }
146     
147     public boolean isPartialRequest()
148     {
149       return false;
150     }
151     
152     public boolean isExecuteAll()
153     {
154       throw new UnsupportedOperationException();
155     }
156     
157     public boolean isRenderAll()
158     {
159       throw new UnsupportedOperationException();
160     }
161     
162     public void setRenderAll(boolean renderAll)
163     {
164       throw new UnsupportedOperationException();
165     }
166     
167     public void setPartialRequest(boolean isPartialRequest)
168     {
169       throw new UnsupportedOperationException();
170     }
171     
172     public void release()
173     {
174       throw new UnsupportedOperationException();
175     }
176     
177     public void processPartial(PhaseId phaseId)
178     {
179       throw new UnsupportedOperationException();
180     }
181   }
182 }