KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > spi > ConnectionParametersTest


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.spi;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.configuration.MockConnectionEl;
20 import scriptella.util.IOUtils;
21
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URI JavaDoc;
25 import java.net.URISyntaxException JavaDoc;
26 import java.text.ParseException JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29
30 /**
31  * Tests for {@link ConnectionParameters}.
32  *
33  * @author Fyodor Kupolov
34  * @version 1.0
35  */

36 public class ConnectionParametersTest extends AbstractTestCase {
37     /**
38      * Tests if properties parsing methods work correctly.
39      */

40     public void testPropertiesParsing() throws ParseException JavaDoc, MalformedURLException JavaDoc, URISyntaxException JavaDoc {
41         Map JavaDoc<String JavaDoc, Object JavaDoc> p = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
42         p.put("int", 10);
43         p.put("negative", -10);
44         p.put("int2", " 20");
45         p.put("boolean", true);
46         p.put("boolean2", "yes");
47         p.put("url1", "file://test");
48         p.put("url2", new URI JavaDoc("file:/url#hash"));
49         File JavaDoc f = new File JavaDoc("tmp");
50         p.put("url3", f);
51         p.put("url4", "file4");
52         ConnectionParameters cp = new ConnectionParameters(new MockConnectionEl(p), MockDriverContext.INSTANCE);
53         Integer JavaDoc v = cp.getIntegerProperty("nosuchproperty", 1);
54         assertEquals(1, v.intValue());
55         v = cp.getIntegerProperty("int", 1);
56         assertEquals(10, v.intValue());
57         v = cp.getIntegerProperty("negative", 1);
58         assertEquals(-10, v.intValue());
59         v = cp.getIntegerProperty("int2", 1);
60         assertEquals(20, v.intValue());
61         boolean b = cp.getBooleanProperty("nosuchprop", true);
62         assertEquals(true, b);
63         b = cp.getBooleanProperty("boolean", false);
64         assertEquals(true, b);
65         b = cp.getBooleanProperty("boolean2", false);
66         assertEquals(true, b);
67         //URLs parsing
68
assertEquals("file://test", cp.getUrlProperty("url1").toString());
69         assertEquals("file:/url#hash", cp.getUrlProperty("url2").toString());
70         assertEquals(IOUtils.toUrl(f), cp.getUrlProperty("url3"));
71         assertEquals("file:/file4", cp.getUrlProperty("url4").toString());
72     }
73 }
74
Popular Tags