source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/fs/TestPath.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.fs;
20
21import java.util.*;
22import junit.framework.TestCase;
23
24public class TestPath extends TestCase {
25  public void testToString() {
26    toStringTest("/");
27    toStringTest("/foo");
28    toStringTest("/foo/bar");
29    toStringTest("foo");
30    toStringTest("foo/bar");
31    boolean emptyException = false;
32    try {
33      toStringTest("");
34    } catch (IllegalArgumentException e) {
35      // expect to receive an IllegalArgumentException
36      emptyException = true;
37    }
38    assertTrue(emptyException);
39    if (Path.WINDOWS) {
40      toStringTest("c:");
41      toStringTest("c:/");
42      toStringTest("c:foo");
43      toStringTest("c:foo/bar");
44      toStringTest("c:foo/bar");
45      toStringTest("c:/foo/bar");
46    }
47  }
48
49  private void toStringTest(String pathString) {
50    assertEquals(pathString, new Path(pathString).toString());
51  }
52
53  public void testNormalize() {
54    assertEquals("/", new Path("//").toString());
55    assertEquals("/foo", new Path("/foo/").toString());
56    assertEquals("/foo", new Path("/foo/").toString());
57    assertEquals("foo", new Path("foo/").toString());
58    assertEquals("foo", new Path("foo//").toString());
59    assertEquals("foo/bar", new Path("foo//bar").toString());
60    if (Path.WINDOWS) {
61      assertEquals("c:/a/b", new Path("c:\\a\\b").toString());
62    }
63  }
64
65  public void testIsAbsolute() {
66    assertTrue(new Path("/").isAbsolute());
67    assertTrue(new Path("/foo").isAbsolute());
68    assertFalse(new Path("foo").isAbsolute());
69    assertFalse(new Path("foo/bar").isAbsolute());
70    assertFalse(new Path(".").isAbsolute());
71    if (Path.WINDOWS) {
72      assertTrue(new Path("c:/a/b").isAbsolute());
73      assertFalse(new Path("c:a/b").isAbsolute());
74    }
75  }
76
77  public void testParent() {
78    assertEquals(new Path("/foo"), new Path("/foo/bar").getParent());
79    assertEquals(new Path("foo"), new Path("foo/bar").getParent());
80    assertEquals(new Path("/"), new Path("/foo").getParent());
81    if (Path.WINDOWS) {
82      assertEquals(new Path("c:/"), new Path("c:/foo").getParent());
83    }
84  }
85
86  public void testChild() {
87    assertEquals(new Path("."), new Path(".", "."));
88    assertEquals(new Path("/"), new Path("/", "."));
89    assertEquals(new Path("/"), new Path(".", "/"));
90    assertEquals(new Path("/foo"), new Path("/", "foo"));
91    assertEquals(new Path("/foo/bar"), new Path("/foo", "bar"));
92    assertEquals(new Path("/foo/bar/baz"), new Path("/foo/bar", "baz"));
93    assertEquals(new Path("/foo/bar/baz"), new Path("/foo", "bar/baz"));
94    assertEquals(new Path("foo"), new Path(".", "foo"));
95    assertEquals(new Path("foo/bar"), new Path("foo", "bar"));
96    assertEquals(new Path("foo/bar/baz"), new Path("foo", "bar/baz"));
97    assertEquals(new Path("foo/bar/baz"), new Path("foo/bar", "baz"));
98    assertEquals(new Path("/foo"), new Path("/bar", "/foo"));
99    if (Path.WINDOWS) {
100      assertEquals(new Path("c:/foo"), new Path("/bar", "c:/foo"));
101      assertEquals(new Path("c:/foo"), new Path("d:/bar", "c:/foo"));
102    }
103  }
104 
105  public void testEquals() {
106    assertFalse(new Path("/").equals(new Path("/foo")));
107  }
108
109  public void testDots() {
110    // Test Path(String)
111    assertEquals(new Path("/foo/bar/baz").toString(), "/foo/bar/baz");
112    assertEquals(new Path("/foo/bar", ".").toString(), "/foo/bar");
113    assertEquals(new Path("/foo/bar/../baz").toString(), "/foo/baz");
114    assertEquals(new Path("/foo/bar/./baz").toString(), "/foo/bar/baz");
115    assertEquals(new Path("/foo/bar/baz/../../fud").toString(), "/foo/fud");
116    assertEquals(new Path("/foo/bar/baz/.././../fud").toString(), "/foo/fud");
117    assertEquals(new Path("../../foo/bar").toString(), "../../foo/bar");
118    assertEquals(new Path(".././../foo/bar").toString(), "../../foo/bar");
119    assertEquals(new Path("./foo/bar/baz").toString(), "foo/bar/baz");
120    assertEquals(new Path("/foo/bar/../../baz/boo").toString(), "/baz/boo");
121    assertEquals(new Path("foo/bar/").toString(), "foo/bar");
122    assertEquals(new Path("foo/bar/../baz").toString(), "foo/baz");
123    assertEquals(new Path("foo/bar/../../baz/boo").toString(), "baz/boo");
124   
125   
126    // Test Path(Path,Path)
127    assertEquals(new Path("/foo/bar", "baz/boo").toString(), "/foo/bar/baz/boo");
128    assertEquals(new Path("foo/bar/","baz/bud").toString(), "foo/bar/baz/bud");
129   
130    assertEquals(new Path("/foo/bar","../../boo/bud").toString(), "/boo/bud");
131    assertEquals(new Path("foo/bar","../../boo/bud").toString(), "boo/bud");
132    assertEquals(new Path(".","boo/bud").toString(), "boo/bud");
133
134    assertEquals(new Path("/foo/bar/baz","../../boo/bud").toString(), "/foo/boo/bud");
135    assertEquals(new Path("foo/bar/baz","../../boo/bud").toString(), "foo/boo/bud");
136
137   
138    assertEquals(new Path("../../","../../boo/bud").toString(), "../../../../boo/bud");
139    assertEquals(new Path("../../foo","../../../boo/bud").toString(), "../../../../boo/bud");
140    assertEquals(new Path("../../foo/bar","../boo/bud").toString(), "../../foo/boo/bud");
141
142    assertEquals(new Path("foo/bar/baz","../../..").toString(), "");
143    assertEquals(new Path("foo/bar/baz","../../../../..").toString(), "../..");
144  }
145 
146  public void testScheme() throws java.io.IOException {
147    assertEquals("foo:/bar", new Path("foo:/","/bar").toString()); 
148    assertEquals("foo://bar/baz", new Path("foo://bar/","/baz").toString()); 
149  }
150
151
152}
Note: See TracBrowser for help on using the repository browser.