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  
20  package org.apache.myfaces.tobago.internal.util;
21  
22  import org.apache.myfaces.tobago.component.UILink;
23  import org.apache.myfaces.tobago.internal.config.AbstractTobagoTestBase;
24  import org.junit.Assert;
25  import org.junit.Test;
26  
27  import javax.faces.component.UIParameter;
28  
29  public class RenderUtilsUnitTest extends AbstractTobagoTestBase {
30  
31    @Test
32    public void simple() {
33      final UILink link = new UILink();
34      link.setLink("local.xhtml");
35      final String url = RenderUtils.generateUrl(getFacesContext(), link);
36      Assert.assertEquals("local.xhtml", url);
37    }
38  
39    @Test
40    public void mailto() {
41      final UILink link = new UILink();
42      link.setLink("mailto:MyFaces Discussion <users@myfaces.apache.org>");
43  
44      final UIParameter subject = new UIParameter();
45      subject.setName("subject");
46      subject.setValue("[Tobago] Preparation for the 5.0.0 release");
47      link.getChildren().add(subject);
48  
49      final UIParameter body = new UIParameter();
50      body.setName("body");
51      body.setValue("Hi, folks,\n"
52          + "\n"
53            + "we plan to build version 5.0.0 of Tobago soon.");
54      link.getChildren().add(body);
55  
56      final String url = RenderUtils.generateUrl(getFacesContext(), link);
57      Assert.assertEquals("mailto:MyFaces Discussion <users@myfaces.apache.org>"
58          + "?subject=%5BTobago%5D%20Preparation%20for%20the%205.0.0%20release"
59          + "&body=Hi%2C%20folks%2C%0A%0Awe%20plan%20to%20build%20version%205.0.0%20of%20Tobago%20soon.", url);
60    }
61  }