01: /*
02: * Copyright 2006-2007 The Scriptella Project Team.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
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 v;
39:
40: public void setValue(Object v) {
41: this .v = v;
42: }
43:
44: public void testExecuteScript() {
45: v = null;
46: Resource r = new StringResource(
47: "x=0;while (x < 10) {x=x+2;};obj.setValue(x)");
48: JexlConnection jc = new JexlConnection(
49: new ConnectionParameters(new MockConnectionEl(),
50: new MockDriverContext()));
51: jc.executeScript(r, MockParametersCallbacks.fromMap(Collections
52: .singletonMap("obj", this )));
53: assertEquals(10, ((Number) v).intValue());
54: }
55:
56: public void testExecuteQuery() {
57: Resource r = new StringResource(
58: "i=0;a=a0;s='test';while (i < 10) {i=i+1;query.next();}");
59: JexlConnection jc = new JexlConnection(
60: new ConnectionParameters(new MockConnectionEl(),
61: new MockDriverContext()));
62: IndexedQueryCallback callback = new IndexedQueryCallback() {
63: protected void processRow(
64: final ParametersCallback parameters,
65: final int rowNumber) {
66: assertEquals(rowNumber + 1, ((Number) parameters
67: .getParameter("i")).intValue());
68: assertEquals(5, ((Number) parameters.getParameter("a"))
69: .intValue());
70: assertEquals("test", parameters.getParameter("s"));
71: }
72: };
73: jc.executeQuery(r, MockParametersCallbacks.fromMap(Collections
74: .singletonMap("a0", 5)), callback);
75:
76: }
77:
78: }
|