KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > driver > jexl > JexlConnectionTest


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.driver.jexl;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.configuration.MockConnectionEl;
20 import scriptella.configuration.StringResource;
21 import scriptella.spi.ConnectionParameters;
22 import scriptella.spi.IndexedQueryCallback;
23 import scriptella.spi.MockDriverContext;
24 import scriptella.spi.MockParametersCallbacks;
25 import scriptella.spi.ParametersCallback;
26 import scriptella.spi.Resource;
27
28 import java.util.Collections JavaDoc;
29
30 /**
31  * Tests for {@link JexlConnection}.
32  *
33  * @author Fyodor Kupolov
34  * @version 1.0
35  * @since 11.01.2007
36  */

37 public class JexlConnectionTest extends AbstractTestCase {
38     private Object JavaDoc v;
39     public void setValue(Object JavaDoc v) {
40         this.v = v;
41     }
42
43     public void testExecuteScript() {
44         v=null;
45         Resource r = new StringResource("x=0;while (x < 10) {x=x+2;};obj.setValue(x)");
46         JexlConnection jc = new JexlConnection(new ConnectionParameters(new MockConnectionEl(), new MockDriverContext()));
47         jc.executeScript(r, MockParametersCallbacks.fromMap(Collections.singletonMap("obj", this)));
48         assertEquals(10, ((Number JavaDoc)v).intValue());
49     }
50
51     public void testExecuteQuery() {
52         Resource r = new StringResource("i=0;a=a0;s='test';while (i < 10) {i=i+1;query.next();}");
53         JexlConnection jc = new JexlConnection(new ConnectionParameters(new MockConnectionEl(), new MockDriverContext()));
54         IndexedQueryCallback callback = new IndexedQueryCallback() {
55             protected void processRow(final ParametersCallback parameters, final int rowNumber) {
56                 assertEquals(rowNumber+1, ((Number JavaDoc)parameters.getParameter("i")).intValue());
57                 assertEquals(5, ((Number JavaDoc)parameters.getParameter("a")).intValue());
58                 assertEquals("test", parameters.getParameter("s"));
59             }
60         };
61         jc.executeQuery(r, MockParametersCallbacks.fromMap(Collections.singletonMap("a0", 5)), callback);
62
63     }
64
65 }
66
Popular Tags