    001package org.apache.turbine.om;
    002
    003/*
    004 * Licensed to the Apache Software Foundation (ASF) under one
    005 * or more contributor license agreements.  See the NOTICE file
    006 * distributed with this work for additional information
    007 * regarding copyright ownership.  The ASF licenses this file
    008 * to you under the Apache License, Version 2.0 (the
    009 * "License"); you may not use this file except in compliance
    010 * with the License.  You may obtain a copy of the License at
    011 *
    012 *   http://www.apache.org/licenses/LICENSE-2.0
    013 *
    014 * Unless required by applicable law or agreed to in writing,
    015 * software distributed under the License is distributed on an
    016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    017 * KIND, either express or implied.  See the License for the
    018 * specific language governing permissions and limitations
    019 * under the License.
    020 */
    021
    022import static org.junit.Assert.assertEquals;
    023import static org.junit.Assert.assertNotNull;
    024import static org.junit.Assert.assertNotSame;
    025import static org.junit.Assert.assertSame;
    026import static org.junit.Assert.assertTrue;
    027
    028import org.apache.turbine.util.TurbineConfig;
    029import org.junit.AfterClass;
    030import org.junit.Before;
    031import org.junit.BeforeClass;
    032import org.junit.Test;
    033
    034/**
    035 * This class tests the {@link OMTool} functionality.
    036 *
    037 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    038 */
    039public class OMToolTest
    040{
    041    private static TurbineConfig tc = null;
    042    private OMTool om;
    043
    044    @BeforeClass
    045    public static void init() {
    046        tc = new TurbineConfig(
    047                            ".",
    048                            "/conf/test/CompleteTurbineResources.properties");
    049        tc.initialize();
    050    }
    051
    052    @Before
    053    public void setUpBefore() throws Exception
    054    {
    055        om = new OMTool();
    056    }
    057
    058    @Test
    059    public void testGetString() throws Exception
    060    {
    061        assertNotNull("RetrieverFactory should not be null", om.omFactory);
    062        OMTool.PullHelper ph1 = om.get("test1");
    063        assertNotNull("PullHelper should not be null", ph1);
    064        OMTool.PullHelper ph2 = om.get("test2");
    065        assertNotNull("PullHelper should not be null", ph2);
    066        assertNotSame("Should not be same instance", ph1, ph2);
    067        OMTool.PullHelper ph3 = om.get("test2");
    068        assertNotNull("PullHelper should not be null", ph3);
    069        assertSame("Should be same instance", ph3, ph2);
    070    }
    071
    072    @Test
    073    public void testGetStringString() throws Exception
    074    {
    075        Object testString1 = om.get("test1", "testString");
    076        assertNotNull("Object should not be null", testString1);
    077        assertTrue("Object should be a string", testString1 instanceof String);
    078        assertEquals("Object should be a string", "testString", testString1);
    079        Object testString2 = om.get("test1", "testString");
    080        assertNotNull("Object should not be null", testString2);
    081        assertSame("Should be same instance", testString1, testString2);
    082    }
    083
    084    @AfterClass
    085    public static void destroy()
    086    {
    087        tc.dispose();
    088    }
    089}