View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.fatwire.gst.foundation.facade.runtag.render;
17  
18  import java.util.Arrays;
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.Map;
22  import java.util.Map.Entry;
23  
24  import junit.framework.TestCase;
25  
26  public class CallTemplateTest extends TestCase {
27  
28      public void testFixPageCriteria() {
29          x();
30      }
31  
32      void x() {
33          String[] pc = { "locale", "p" };
34          Map<String, Object> m = new HashMap<String, Object>();
35  
36          m.put("TTYPE", "foo");
37          m.put("ARGS_locale", "en");
38          m.put("ARGS_foo", "foo");
39          m.put("ARGS_TNAME", "foo");
40          for (final Iterator<Entry<String, Object>> i = m.entrySet().iterator(); i.hasNext();) {
41              final Entry<String, ?> e = i.next();
42              final String key = e.getKey();
43              // only inspect arguments that start with ARGS_
44              if (key.startsWith(CallTemplate.ARGS)) {
45  
46                  String shortKey = key.substring(CallTemplate.ARGS.length());
47                  boolean found = CallTemplate.CALLTEMPLATE_EXCLUDE_VARS.contains(shortKey);
48                  System.out.println(key +" " + found);
49                  if (!found) {
50                      for (final String c : pc) {
51                          if (c.equalsIgnoreCase(shortKey)) {
52                              found = true;
53                              break;
54                          }
55                      }
56                  }
57                  if (!found) {
58                      System.out.println("Argument '" + key + "' not found as PageCriterium " + ". Arguments are: "
59                              + m.keySet().toString() + ". PageCriteria: " + Arrays.asList(pc));
60                      // we could correct this by calling as an element
61                      // or by removing the argument
62  
63                      i.remove();
64                      System.out.println("Argument '" + key + "' is removed from the call as it is not a PageCriterium.");
65                  }
66  
67              }
68          }
69      }
70  
71  }