001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.chain.web;
018
019
020 import junit.framework.Test;
021 import junit.framework.TestCase;
022 import junit.framework.TestSuite;
023
024
025 // Test case for org.apache.commons.chain.web.ChainResources
026
027 public class ChainResourcesTestCase extends TestCase {
028
029
030 // ---------------------------------------------------------- Constructors
031
032 /**
033 * Construct a new instance of this test case.
034 *
035 * @param name Name of the test case
036 */
037 public ChainResourcesTestCase(String name) {
038 super(name);
039 }
040
041
042 // ----------------------------------------------------- Instance Variables
043
044
045 protected TestData[] data = new TestData[]
046 {
047 new TestData("a,b,c", new String[] {"a", "b", "c"}),
048 new TestData("a , b , c ", new String[] {"a", "b", "c"}),
049 new TestData("a,\tb,\tc ", new String[] {"a", "b", "c"}),
050 new TestData("\na,\nb,\nc\n", new String[] {"a", "b", "c"}),
051 new TestData("a,,b,c ", new String[] {"a", "b", "c"}),
052 new TestData(",a,b,,c,,", new String[] {"a", "b", "c"}),
053 new TestData(null, new String[] {}),
054 new TestData("", new String[] {}),
055 new TestData(",", new String[] {}),
056 new TestData(",,", new String[] {})
057 };
058
059
060 // ------------------------------------------------ Individual Test Methods
061
062
063 public void testGetPaths() throws Exception {
064 for (int i = 0; i < data.length; i++) {
065 TestData datum = data[i];
066 String[] expected = datum.getExpected();
067 String[] actual = ChainResources.getResourcePaths(datum.getInput());
068
069 assertNotNull(actual);
070 assertEquals(expected.length, actual.length);
071 for (int j = 0; j < actual.length; j++) {
072 assertEquals(expected[j], actual[j]);
073 }
074 }
075 }
076
077
078 // ---------------------------------------------------------- Inner classes
079
080
081 // Container for test data for one test
082 public static final class TestData {
083 private String input;
084 private String[] expected;
085 public TestData(String input, String[] expected) {
086 this.input = input;
087 this.expected = expected;
088 }
089 public String getInput() {
090 return input;
091 }
092 public String[] getExpected() {
093 return expected;
094 }
095 }
096
097 }