01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.geoserver.ows.kvp;
06:
07: import java.util.Arrays;
08: import java.util.List;
09:
10: import org.geoserver.ows.util.KvpUtils;
11:
12: import junit.framework.TestCase;
13:
14: public class KvpUtilsTest extends TestCase {
15: public void testEmptyString() {
16: assertEquals(0, KvpUtils.readFlat("").size());
17: }
18:
19: public void testTrailingEmtpyStrings() {
20: assertEquals(Arrays
21: .asList(new String[] { "x", "", "x", "", "" }),
22: KvpUtils.readFlat("x,,x,,"));
23: }
24:
25: public void testEmtpyNestedString() {
26: List result = KvpUtils.readNested("");
27: assertEquals(1, result.size());
28: assertEquals(0, ((List) result.get(0)).size());
29: }
30:
31: public void testStarNestedString() {
32: List result = KvpUtils.readNested("*");
33: assertEquals(1, result.size());
34: assertEquals(0, ((List) result.get(0)).size());
35: }
36:
37: public void testWellKnownTokenizers() {
38: String[] expected;
39: List actual;
40:
41: expected = new String[] { "1", "2", "3", "" };
42: actual = KvpUtils.readFlat("1,2,3,", KvpUtils.INNER_DELIMETER);
43: assertKvp(expected, actual);
44:
45: expected = new String[] { "abc", "def", "" };
46: actual = KvpUtils.readFlat("(abc)(def)()",
47: KvpUtils.OUTER_DELIMETER);
48: assertKvp(expected, actual);
49:
50: expected = new String[] { "abc" };
51: actual = KvpUtils.readFlat("(abc)", KvpUtils.OUTER_DELIMETER);
52: assertKvp(expected, actual);
53:
54: expected = new String[] { "" };
55: actual = KvpUtils.readFlat("()", KvpUtils.OUTER_DELIMETER);
56: assertKvp(expected, actual);
57:
58: expected = new String[] { "", "A=1", "B=2", "" };
59: actual = KvpUtils.readFlat(";A=1;B=2;", KvpUtils.CQL_DELIMITER);
60: assertKvp(expected, actual);
61:
62: expected = new String[] { "ab", "cd", "ef", "" };
63: actual = KvpUtils.readFlat("ab&cd&ef&",
64: KvpUtils.KEYWORD_DELIMITER);
65: assertKvp(expected, actual);
66:
67: expected = new String[] { "A", "1 " };
68: actual = KvpUtils.readFlat("A=1 ", KvpUtils.VALUE_DELIMITER);
69: assertKvp(expected, actual);
70: }
71:
72: public void testRadFlatUnkownDelimiter() {
73: List actual;
74:
75: final String[] expected = new String[] { "1", "2", "3", "" };
76: actual = KvpUtils.readFlat("1^2^3^", "\\^");
77: assertKvp(expected, actual);
78:
79: actual = KvpUtils.readFlat("1-2-3-", "-");
80: assertKvp(expected, actual);
81: }
82:
83: private void assertKvp(String[] expected, List actual) {
84: List expectedList = Arrays.asList(expected);
85: assertEquals(expectedList.size(), actual.size());
86: assertEquals(expectedList, actual);
87: }
88: }
|