1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.chain.web;
18
19
20 import junit.framework.Test;
21 import junit.framework.TestCase;
22 import junit.framework.TestSuite;
23
24
25 // Test case for org.apache.commons.chain.web.ChainResources
26
27 public class ChainResourcesTestCase extends TestCase {
28
29
30 // ---------------------------------------------------------- Constructors
31
32 /**
33 * Construct a new instance of this test case.
34 *
35 * @param name Name of the test case
36 */
37 public ChainResourcesTestCase(String name) {
38 super(name);
39 }
40
41
42 // ----------------------------------------------------- Instance Variables
43
44
45 protected TestData[] data = new TestData[]
46 {
47 new TestData("a,b,c", new String[] {"a", "b", "c"}),
48 new TestData("a , b , c ", new String[] {"a", "b", "c"}),
49 new TestData("a,\tb,\tc ", new String[] {"a", "b", "c"}),
50 new TestData("\na,\nb,\nc\n", new String[] {"a", "b", "c"}),
51 new TestData("a,,b,c ", new String[] {"a", "b", "c"}),
52 new TestData(",a,b,,c,,", new String[] {"a", "b", "c"}),
53 new TestData(null, new String[] {}),
54 new TestData("", new String[] {}),
55 new TestData(",", new String[] {}),
56 new TestData(",,", new String[] {})
57 };
58
59
60 // ------------------------------------------------ Individual Test Methods
61
62
63 public void testGetPaths() throws Exception {
64 for (int i = 0; i < data.length; i++) {
65 TestData datum = data[i];
66 String[] expected = datum.getExpected();
67 String[] actual = ChainResources.getResourcePaths(datum.getInput());
68
69 assertNotNull(actual);
70 assertEquals(expected.length, actual.length);
71 for (int j = 0; j < actual.length; j++) {
72 assertEquals(expected[j], actual[j]);
73 }
74 }
75 }
76
77
78 // ---------------------------------------------------------- Inner classes
79
80
81 // Container for test data for one test
82 public static final class TestData {
83 private String input;
84 private String[] expected;
85 public TestData(String input, String[] expected) {
86 this.input = input;
87 this.expected = expected;
88 }
89 public String getInput() {
90 return input;
91 }
92 public String[] getExpected() {
93 return expected;
94 }
95 }
96
97 }