KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > jdbc > ParametersParserTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
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 scriptella.jdbc;
17
18 import junit.framework.TestCase;
19 import scriptella.expression.Expression;
20 import scriptella.spi.MockDriverContext;
21 import scriptella.spi.MockParametersCallbacks;
22
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25
26 /**
27  * Tests for {@link ParametersParser}.
28  *
29  * @author Fyodor Kupolov
30  * @version 1.0
31  */

32 public class ParametersParserTest extends TestCase {
33     /**
34      * Tests valid file references
35      */

36     public void testValid() throws MalformedURLException JavaDoc {
37
38         final MockDriverContext dc = new MockDriverContext();
39         ParametersParser p = new ParametersParser(dc);
40
41         String JavaDoc expr = "file 'myfile'";
42         Lobs.UrlBlob actual = (Lobs.UrlBlob) p.evaluate(expr, MockParametersCallbacks.UNSUPPORTED);
43         URL JavaDoc expected = dc.resolve("myfile");
44         assertEquals(expected, actual.getUrl());
45         expr = "file 'http'+'://127.0.0.1/'+name";
46         actual = (Lobs.UrlBlob) p.evaluate(expr, MockParametersCallbacks.SIMPLE);
47         expected = new URL JavaDoc("http://127.0.0.1/*name*");
48         assertEquals(expected, actual.getUrl());
49     }
50
51     /**
52      * Tests invalid file references
53      */

54     public void testInvalid() throws MalformedURLException JavaDoc {
55
56         final MockDriverContext dc = new MockDriverContext();
57         ParametersParser p = new ParametersParser(dc);
58
59         try {
60             p.evaluate("file myfile'", MockParametersCallbacks.UNSUPPORTED);
61             fail("illegal file reference");
62         } catch (Expression.ParseException e) {
63             //ok
64
}
65         //not a file reference, just an expression starting with file prefix
66
try {
67             p.evaluate("file + 'text'", MockParametersCallbacks.NULL);
68         } catch (Expression.EvaluationException e) {
69             assertTrue(e.getCause() instanceof NullPointerException JavaDoc);
70         }
71         //not a file reference, just an expression starting with file prefix
72
final Object JavaDoc o = p.evaluate("file + var", MockParametersCallbacks.SIMPLE);
73         assertEquals("*file**var*",o);
74
75
76
77
78
79
80     }
81
82 }
83
Popular Tags