01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */
18: package org.apache.ivy.core;
19:
20: import java.io.File;
21: import java.net.MalformedURLException;
22: import java.net.URL;
23:
24: import junit.framework.TestCase;
25:
26: public class NormalRelativeUrlResolverTest extends TestCase {
27:
28: private NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
29:
30: public void testRelativeHttpURL() throws MalformedURLException {
31: URL base = new URL("http://xxx/file.txt");
32: assertEquals(new URL("http://xxx/file2.txt"), t.getURL(base,
33: "file2.txt"));
34: }
35:
36: public void testRelativeFileURL() throws MalformedURLException {
37: URL base = new URL("file://xxx/file.txt");
38: assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base,
39: "file2.txt"));
40: }
41:
42: public void testRelativeMixedURL() throws MalformedURLException {
43: URL base = new URL("http://xxx/file.txt");
44: assertEquals(new URL("file://file2.txt"), t.getURL(base,
45: "file://file2.txt"));
46: }
47:
48: public void testFileAndUrlWithAbsoluteFile()
49: throws MalformedURLException {
50: URL base = new URL("file://xxx/file.txt");
51: File absFile = new File(".").getAbsoluteFile();
52: assertEquals(absFile.toURL(), t.getURL(base,
53: absFile.toString(), null));
54: assertEquals(absFile.toURL(), t.getURL(base,
55: absFile.toString(), ""));
56: assertEquals(absFile.toURL(), t.getURL(base,
57: absFile.toString(), "somthing.txt"));
58: }
59:
60: public void testFileAndUrlWithRelativeFile()
61: throws MalformedURLException {
62: URL base = new URL("file://xxx/file.txt");
63: assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base,
64: "file2.txt", null));
65: assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base,
66: "file2.txt", ""));
67: assertEquals(new URL("file://xxx/sub/file2.txt"), t.getURL(
68: base, "sub/file2.txt", "something"));
69: }
70:
71: public void testFileAndUrlWithAbsoluteUrl()
72: throws MalformedURLException {
73: URL base = new URL("file://xxx/file.txt");
74: URL otherBase = new URL("http://localhost:80/otherfile.txt");
75: String absUrl = "http://ibiblio.org/dir/file.txt";
76: assertEquals(new URL(absUrl), t.getURL(base, null, absUrl));
77: assertEquals(new URL(absUrl), t.getURL(otherBase, null, absUrl));
78: }
79:
80: public void testFileAndUrlWithRelativeUrl()
81: throws MalformedURLException {
82: URL base = new URL("file://xxx/file.txt");
83: URL otherBase = new URL("http://localhost:80/otherfile.txt");
84: assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base,
85: null, "file2.txt"));
86: assertEquals(new URL("http://localhost:80/file2.txt"), t
87: .getURL(otherBase, null, "file2.txt"));
88: }
89:
90: }
|