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