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.application.contracts;
20  
21  import java.util.List;
22  import java.util.Set;
23  import javax.faces.application.StateManager;
24  
25  import junit.framework.Assert;
26  import org.apache.myfaces.config.RuntimeConfig;
27  
28  import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
29  import org.apache.myfaces.shared.config.MyfacesConfig;
30  import org.junit.Test;
31  
32  public class DefaultContractsConfigMyFacesRequestTestCase extends AbstractMyFacesRequestTestCase
33  {
34  
35      @Override
36      protected boolean isScanAnnotations()
37      {
38          return true;
39      }
40  
41      @Override
42      protected void setUpWebConfigParams() throws Exception
43      {
44          super.setUpWebConfigParams();
45          servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.application.contracts");
46          servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
47          servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
48          servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
49      }
50      
51      @Test
52      public void testDefaultConfiguration() throws Exception
53      {
54          startViewRequest("/index.xhtml");
55          RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
56          
57          Set<String> allContracts = runtimeConfig.getResourceLibraryContracts();
58          Set<String> externalContextContracts = runtimeConfig.getExternalContextResourceLibraryContracts();
59          Set<String> classloaderContracts = runtimeConfig.getClassLoaderResourceLibraryContracts();
60  
61          Assert.assertTrue(allContracts.contains("yellow"));
62          Assert.assertTrue(allContracts.contains("blue"));
63          Assert.assertTrue(allContracts.contains("red"));
64  
65          Assert.assertTrue(classloaderContracts.contains("yellow"));
66          Assert.assertTrue(classloaderContracts.contains("blue"));
67          Assert.assertTrue(externalContextContracts.contains("red"));
68          
69          List<String> defaultContracts = runtimeConfig.getContractMappings().get("*");
70          
71          Assert.assertTrue(defaultContracts.contains("yellow"));
72          Assert.assertTrue(defaultContracts.contains("blue"));
73          Assert.assertTrue(defaultContracts.contains("red"));
74          
75          processLifecycleExecute();
76          executeBuildViewCycle(facesContext);
77          
78          List<String> contractsList = facesContext.getResourceLibraryContracts();
79          Assert.assertTrue(contractsList.contains("yellow"));
80          Assert.assertTrue(contractsList.contains("blue"));
81          Assert.assertTrue(contractsList.contains("red"));
82          
83          endRequest();
84      }
85  
86  }