View Javadoc

    1   package org.apache.turbine.services.pull.tools;
    2
    3   /*
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *   http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21
    22
    23  import static org.junit.Assert.assertEquals;
    24  import static org.junit.Assert.assertNotNull;
    25  import static org.junit.Assert.assertTrue;
    26
    27  import java.util.HashMap;
    28  import java.util.Map;
    29
    30  import org.apache.commons.lang.ArrayUtils;
    31  import org.apache.turbine.TurbineConstants;
    32  import org.apache.turbine.services.jsonrpc.JsonrpcServicelTest;
    33  import org.apache.turbine.services.pull.PullService;
    34  import org.apache.turbine.services.pull.TurbinePull;
    35  import org.apache.turbine.test.BaseTestCase;
    36  import org.apache.turbine.util.TurbineConfig;
    37  import org.apache.velocity.context.Context;
    38  import org.junit.AfterClass;
    39  import org.junit.BeforeClass;
    40  import org.junit.Test;
    41  import org.junit.runner.RunWith;
    42  import org.junit.runners.Suite;
    43
    44  @RunWith(Suite.class)
    45  @Suite.SuiteClasses({
    46      JsonrpcServicelTest.class
    47      })
    48  public class UIToolTest
    49          extends BaseTestCase
    50  {
    51
    52      private static TurbineConfig turbineConfig = null;
    53      private static PullService pullService = null;
    54      private static UITool ui = null;
    55
    56
    57      @BeforeClass
    58      public static void setUp() throws Exception {
    59
    60
    61          Map<String, String> initParams = new HashMap<String, String>();
    62          initParams.put(TurbineConfig.PROPERTIES_PATH_KEY, "/conf/test/CompleteTurbineResources.properties"); // "conf/test/TurbineResources.properties"
    63          initParams.put(TurbineConstants.LOGGING_ROOT_KEY, "target/test-logs");
    64
    65          turbineConfig = new TurbineConfig(".", initParams);
    66          turbineConfig.initialize();
    67
    68          //pullService = (PullService)TurbineServices.getInstance().getService(PullService.SERVICE_NAME);
    69          pullService = TurbinePull.getService();
    70          assertNotNull(pullService);
    71          Context globalContext = pullService.getGlobalContext();
    72          assertNotNull(globalContext);
    73
    74          ui = (UITool) globalContext.get("ui");
    75      }
    76
    77      @AfterClass
    78      public static void destroy() throws Exception {
    79          turbineConfig.dispose();
    80          ui=null;
    81      }
    82
    83      @Test
    84      public void testTool()
    85      {
    86          assertNotNull(ui);
    87      }
    88
    89      @Test
    90      public void testCssSlashes()
    91      {
    92
    93          ui.setSkin("myskin");
    94
    95          String cssUrl = ui.getStylecss();
    96          assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
    97      }
    98
    99      @Test
    100     public void testImageSlashes()
    101     {
    102         ui.setSkin("myskin");
    103
    104         String img = "myimage.gif";
    105
    106         String imgUrl = ui.image(img);
    107         assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl);
    108
    109         String img2 = "foo/myimage.gif";
    110
    111         String imgUrl2 = ui.image(img2);
    112         assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2);
    113
    114         String img3 = "/foo/myimage.gif";
    115
    116         String imgUrl3 = ui.image(img3);
    117         assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3);
    118     }
    119     @Test
    120     public void testPathologicalCases()
    121     {
    122         ui.setSkin("myskin");
    123
    124         String img = "";
    125         String imgUrl = ui.image(img);
    126         assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
    127
    128         img = "/";
    129         imgUrl = ui.image(img);
    130         assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
    131
    132         img = "//";
    133         imgUrl = ui.image(img);
    134         assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
    135     }
    136     @Test
    137     public void testGetSkinNames()
    138     {
    139
    140         String[] skinNames = ui.getSkinNames();
    141         // Remove the ".svn" dir that may be present.
    142         skinNames = (String[]) ArrayUtils.removeElement(skinNames, ".svn");
    143         assertEquals(2, skinNames.length);
    144
    145         assertTrue(ArrayUtils.contains(skinNames, "myotherskin"));
    146         assertTrue(ArrayUtils.contains(skinNames, "myskin"));
    147     }
    148     @Test
    149     public void testSkinValues()
    150     {
    151
    152         // Default skin
    153         //skin_property_1 = skin_property_1_my_skin
    154         assertEquals("skin_property_1_my_skin", ui.get("skin_property_1"));
    155
    156         ui.setSkin("myotherskin");
    157         //skin_property_1 = skin_property_1_my_other_skin
    158         assertEquals("skin_property_1_my_other_skin", ui.get("skin_property_1"));
    159     }
    160 }