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.orchestra.requestParameterProvider;
    20
    21  import junit.framework.TestCase;
    22  import org.apache.myfaces.orchestra.frameworkAdapter.local.LocalFrameworkAdapter;
    23  import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
    24  import org.apache.myfaces.orchestra.conversation.basic.LogConversationMessager;
    25
    26  public class TestRequestParameterProviderManager extends TestCase
    27  {
    28      public void testParameterAdding()
    29      {
    30          LocalFrameworkAdapter lfa = new LocalFrameworkAdapter();
    31          lfa.setConversationMessager(new LogConversationMessager());
    32          lfa.setRequestAttribute(RequestParameterServletFilter.REQUEST_PARAM_FILTER_CALLED, Boolean.TRUE);
    33          FrameworkAdapter.setCurrentInstance(lfa);
    34          RequestParameterProviderManager man = RequestParameterProviderManager.getInstance();
    35          man.register(new RequestParameterProvider()
    36          {
    37
    38              public String[] getFields()
    39              {
    40                  return new String[] {"FIELD"};
    41              }
    42
    43              public String getFieldValue(String field)
    44              {
    45                  return "VALUE";
    46              }
    47          });
    48
    49          assertEquals("http://domain/path?FIELD=VALUE", man.encodeAndAttachParameters("http://domain/path"));
    50          assertEquals("http://domain/path?ab=cd&FIELD=VALUE", man.encodeAndAttachParameters("http://domain/path?ab=cd"));
    51          assertEquals("http://domain/path?FIELD=VALUE#", man.encodeAndAttachParameters("http://domain/path#"));
    52          assertEquals("http://domain/path?FIELD=VALUE#22", man.encodeAndAttachParameters("http://domain/path#22"));
    53          assertEquals("http://domain/path?ab=cd&FIELD=VALUE#22", man.encodeAndAttachParameters("http://domain/path?ab=cd#22"));
    54          assertEquals("javascript:anyMethod(anyUrl)", man.encodeAndAttachParameters("javascript:anyMethod(anyUrl)"));
    55          assertEquals("relative/url?FIELD=VALUE", man.encodeAndAttachParameters("relative/url"));
    56          assertEquals("useless:/url?FIELD=VALUE", man.encodeAndAttachParameters("useless:/url"));
    57          assertEquals("#", man.encodeAndAttachParameters("#"));
    58      }
    59  }