01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestSequenceValueH2.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.database.queries;
09:
10: import com.uwyn.rife.database.exceptions.SequenceNameRequiredException;
11: import com.uwyn.rife.database.exceptions.SequenceOperationRequiredException;
12:
13: public class TestSequenceValueH2 extends TestSequenceValue {
14: public TestSequenceValueH2(String name) {
15: super (name);
16: }
17:
18: public void testInstantiationH2() {
19: SequenceValue query = new SequenceValue(mH2);
20: assertNotNull(query);
21: try {
22: query.getSql();
23: fail();
24: } catch (SequenceNameRequiredException e) {
25: assertEquals(e.getQueryName(), "SequenceValue");
26: }
27: }
28:
29: public void testInvalidH2() {
30: SequenceValue query = new SequenceValue(mH2);
31: try {
32: query.getSql();
33: fail();
34: } catch (SequenceNameRequiredException e) {
35: assertEquals(e.getQueryName(), "SequenceValue");
36: }
37: query.name("sequencename");
38: try {
39: query.getSql();
40: fail();
41: } catch (SequenceOperationRequiredException e) {
42: assertEquals(e.getQueryName(), "SequenceValue");
43: }
44: query.clear();
45: query.next();
46: try {
47: query.getSql();
48: fail();
49: } catch (SequenceNameRequiredException e) {
50: assertEquals(e.getQueryName(), "SequenceValue");
51: }
52: query.clear();
53: }
54:
55: public void testClearH2() {
56: SequenceValue query = new SequenceValue(mH2);
57: query.name("sequencename").next();
58: assertNotNull(query.getSql());
59: query.clear();
60: try {
61: query.getSql();
62: fail();
63: } catch (SequenceNameRequiredException e) {
64: assertEquals(e.getQueryName(), "SequenceValue");
65: }
66: }
67:
68: public void testNextH2() {
69: SequenceValue query = new SequenceValue(mH2);
70: query.name("sequencename").next();
71: assertEquals(query.getSql(), "SELECT nextval('sequencename')");
72: assertTrue(execute(mH2, query) >= 0);
73: }
74:
75: public void testCurrentH2() {
76: SequenceValue query = new SequenceValue(mH2);
77: query.name("sequencename").current();
78: assertEquals(query.getSql(), "SELECT currval('sequencename')");
79: assertTrue(execute(mH2, query) >= 0);
80: }
81:
82: public void testCloneH2() {
83: SequenceValue query = new SequenceValue(mH2);
84: query.name("sequencename").next();
85: SequenceValue query_clone = query.clone();
86: assertEquals(query.getSql(), query_clone.getSql());
87: assertTrue(query != query_clone);
88: assertTrue(execute(mH2, query_clone) >= 0);
89: }
90: }
|