1   /*
2    * Copyright 2005 The Apache Software Foundation
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
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  
19  import junit.framework.Test;
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  
24  // Test case for org.apache.commons.chain.web.ChainResources
25  
26  public class ChainResourcesTestCase extends TestCase {
27  
28  
29      // ---------------------------------------------------------- Constructors
30  
31      /***
32       * Construct a new instance of this test case.
33       *
34       * @param name Name of the test case
35       */
36      public ChainResourcesTestCase(String name) {
37          super(name);
38      }
39  
40  
41      // ----------------------------------------------------- Instance Variables
42  
43  
44      protected TestData[] data = new TestData[]
45          {
46              new TestData("a,b,c",            new String[] {"a", "b", "c"}),
47              new TestData("a , b , c ",       new String[] {"a", "b", "c"}),
48              new TestData("a,\tb,\tc ",       new String[] {"a", "b", "c"}),
49              new TestData("\na,\nb,\nc\n",    new String[] {"a", "b", "c"}),
50              new TestData("a,,b,c ",          new String[] {"a", "b", "c"}),
51              new TestData(",a,b,,c,,",        new String[] {"a", "b", "c"}),
52              new TestData(null,               new String[] {}),
53              new TestData("",                 new String[] {}),
54              new TestData(",",                new String[] {}),
55              new TestData(",,",               new String[] {})
56          };
57  
58  
59      // ------------------------------------------------ Individual Test Methods
60  
61  
62      public void testGetPaths() throws Exception {
63          for (int i = 0; i < data.length; i++) {
64              TestData datum = data[i];
65              String[] expected = datum.getExpected();
66              String[] actual = ChainResources.getResourcePaths(datum.getInput());
67  
68              assertNotNull(actual);
69              assertEquals(expected.length, actual.length);
70              for (int j = 0; j < actual.length; j++) {
71                  assertEquals(expected[j], actual[j]);
72              }
73          }
74      }
75  
76  
77      // ---------------------------------------------------------- Inner classes
78  
79  
80      // Container for test data for one test
81      public static final class TestData {
82          private String input;
83          private String[] expected;
84          public TestData(String input, String[] expected) {
85              this.input = input;
86              this.expected = expected;
87          }
88          public String getInput() {
89              return input;
90          }
91          public String[] getExpected() {
92              return expected;
93          }
94      }
95  
96  }