KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > Compiler_Test


1 /* ****************************************************************************
2  * Compiler_Test.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.compiler;
11 import java.io.*;
12 import java.util.*;
13 import org.jdom.Element;
14 import junit.framework.*;
15 import org.openlaszlo.xml.internal.XMLUtils;
16
17 /*
18  * junit.awtui.TestRunner
19  * junit.swingui.TestRunner
20  * junit.textui.TestRunner
21  * java junit.textui.TestRunner org.openlaszlo.utils.Compiler_Test
22  *
23  * @author Oliver Steele
24  */

25
26 public class Compiler_Test extends TestCase {
27     public Compiler_Test(String JavaDoc name) {
28         super(name);
29     }
30
31     public void setUp() {
32     }
33
34     public void testAdjustRelativePath() {
35         String JavaDoc tests[] = {
36             // sourcedir, destdir, source, dest
37
// dest == null is an abbreviation for dest == source
38

39             // If it's not an URL, don't change it
40
"from", "to", "base.ext", null, // 1
41
"from", "to", "dir/base.ext", null, // 2
42
"from", "to", "/dir/base.ext", null, // 3
43
"from", "to", "c:/dir/base.ext", null, // 4
44

45             // If it's an absolute URL, don't change it
46
"from", "to", "http:///base.ext", null, // 5
47
"from", "to", "http:///dir/base.ext", null, // 6
48

49             // If it's on another host, don't change it
50
"from", "to", "http://host.com/base.ext", null, // 7
51
"from", "to", "http://host.com/dir/base.ext", null, // 8
52

53             // Relative URL on this host
54
"", "", "http:base.ext", null, // 9
55
".", "", "http:base.ext", null, // 10
56
"", ".", "http:base.ext", null, // 11
57
".", ".", "http:base.ext", null, // 12
58
"from", "", "http:base.ext", "http:../base.ext", // 13
59
"", "to", "http:base.ext", "http:to/base.ext", // 14
60
"from", "to", "http:base.ext", "http:../to/base.ext", // 15
61
"/from", "/to", "http:base.ext", "http:../to/base.ext", // 16
62
"c:/from", "c:/to", "http:base.ext", "http:../to/base.ext", // 17
63

64             // Preserve protocol and query
65
// https: gets "unknown protocol" under ant
66
"from", "to", "ftp:base.ext", "ftp:../to/base.ext", // 18
67
"from", "to", "http:base.ext?query", "http:../to/base.ext?query", // 19
68

69             // no way to indicate port on a relative URL?
70
// doesn't preserve fragment, but the agent doesn't parse this
71
// anyway
72
//"from", "to", "http:base.ext#frag", "http:../to/base.ext#frag", // 19
73

74             // Absolute pathnames on same root
75
"/c/from", "/c/to", "http:base.ext", "http:../to/base.ext",
76             "c:/from", "c:/to", "http:base.ext", "http:../to/base.ext",
77         };
78         int i = 0;
79         while (i < tests.length) {
80             File sourcedir = new File(tests[i++]);
81             File destdir = new File(tests[i++]);
82             String JavaDoc source = tests[i++];
83             String JavaDoc dest = tests[i++];
84             if (dest == null) {
85                 dest = source;
86             }
87             String JavaDoc result = CompilationEnvironment.adjustRelativeURL(
88                 source, sourcedir, destdir);
89             assertEquals("" + i/4 + ": adjustRelativeURL(\"" + source + "\", \"" + sourcedir + "\", \"" + destdir + "\")", result, dest);
90         }
91     }
92
93     public void testRlementRecognition() {
94         // local datasets
95
for (Iterator iter = Arrays.asList(
96                  new String JavaDoc[] {"<dataset/>",
97                                "<dataset SRC=\"local\"/>",
98                                "<dataset SRC=\"c:/local\"/>",
99                  }).iterator(); iter.hasNext(); ) {
100             String JavaDoc src = (String JavaDoc) iter.next();
101             Element elt = XMLUtils.parse(src);
102             assertTrue(src, DataCompiler.isElement(elt));
103         }
104         // non-local dataset
105
for (Iterator iter = Arrays.asList(
106                  new String JavaDoc[] {"<dataset type=\"soap\"/>",
107                                "<dataset type=\"http\"/>",
108                                "<dataset SRC=\"http:foo\"/>",
109                                "<dataset SRC=\"https:foo\"/>",
110                                "<dataset SRC=\"ftp:foo\"/>",
111                  }).iterator(); iter.hasNext(); ) {
112             String JavaDoc src = (String JavaDoc) iter.next();
113             Element elt = XMLUtils.parse(src);
114             assertTrue(src, !DataCompiler.isElement(elt));
115         }
116     }
117 }
118
Popular Tags