View Javadoc

    1   package org.apache.turbine.om;
    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  import static org.junit.Assert.assertEquals;
    23  import static org.junit.Assert.assertNotNull;
    24  import static org.junit.Assert.assertNotSame;
    25  import static org.junit.Assert.assertSame;
    26  import static org.junit.Assert.assertTrue;
    27
    28  import org.apache.turbine.util.TurbineConfig;
    29  import org.junit.AfterClass;
    30  import org.junit.Before;
    31  import org.junit.BeforeClass;
    32  import org.junit.Test;
    33
    34  /**
    35   * This class tests the {@link OMTool} functionality.
    36   *
    37   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    38   */
    39  public class OMToolTest
    40  {
    41      private static TurbineConfig tc = null;
    42      private OMTool om;
    43
    44      @BeforeClass
    45      public static void init() {
    46          tc = new TurbineConfig(
    47                              ".",
    48                              "/conf/test/CompleteTurbineResources.properties");
    49          tc.initialize();
    50      }
    51
    52      @Before
    53      public void setUpBefore() throws Exception
    54      {
    55          om = new OMTool();
    56      }
    57
    58      @Test
    59      public void testGetString() throws Exception
    60      {
    61          assertNotNull("RetrieverFactory should not be null", om.omFactory);
    62          OMTool.PullHelper ph1 = om.get("test1");
    63          assertNotNull("PullHelper should not be null", ph1);
    64          OMTool.PullHelper ph2 = om.get("test2");
    65          assertNotNull("PullHelper should not be null", ph2);
    66          assertNotSame("Should not be same instance", ph1, ph2);
    67          OMTool.PullHelper ph3 = om.get("test2");
    68          assertNotNull("PullHelper should not be null", ph3);
    69          assertSame("Should be same instance", ph3, ph2);
    70      }
    71
    72      @Test
    73      public void testGetStringString() throws Exception
    74      {
    75          Object testString1 = om.get("test1", "testString");
    76          assertNotNull("Object should not be null", testString1);
    77          assertTrue("Object should be a string", testString1 instanceof String);
    78          assertEquals("Object should be a string", "testString", testString1);
    79          Object testString2 = om.get("test1", "testString");
    80          assertNotNull("Object should not be null", testString2);
    81          assertSame("Should be same instance", testString1, testString2);
    82      }
    83
    84      @AfterClass
    85      public static void destroy()
    86      {
    87          tc.dispose();
    88      }
    89  }