1 package org.kuali.rice.krad.data.platform;
2
3 import org.junit.Test;
4 import org.kuali.rice.krad.test.KRADTestCase;
5 import org.kuali.rice.test.TestHarnessServiceLocator;
6 import org.springframework.dao.DataAccessException;
7 import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
8
9 import javax.sql.DataSource;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15
16
17
18
19
20 public class MaxValueIncrementerFactoryIntegrationTest extends KRADTestCase {
21
22 private static final String ARBITRARY_SEQUENCE = "TRVL_ID_SEQ";
23
24
25
26
27 @Test
28 public void testGetIncrementer_nextValues() {
29 DataSource dataSource = TestHarnessServiceLocator.getDataSource();
30 DataFieldMaxValueIncrementer incrementer =
31 MaxValueIncrementerFactory.getIncrementer(dataSource, ARBITRARY_SEQUENCE);
32 assertNotNull(incrementer);
33
34
35 int nextIntValue = incrementer.nextIntValue();
36 assertTrue("nextIntValue should be greater than 0", nextIntValue > 0);
37
38
39 int nextNextIntValue = incrementer.nextIntValue();
40 assertEquals("Next value should be one higher", nextIntValue + 1, nextNextIntValue);
41
42
43 long nextLongValue = incrementer.nextLongValue();
44 assertEquals(nextNextIntValue + 1, nextLongValue);
45
46
47 String nextStringValue = incrementer.nextStringValue();
48 assertEquals(nextLongValue + 1, Long.parseLong(nextStringValue));
49 }
50
51
52
53
54
55 @Test
56 public void testGetIncrementer_CaseInsensitive() {
57 DataSource dataSource = TestHarnessServiceLocator.getDataSource();
58 DataFieldMaxValueIncrementer incrementer =
59 MaxValueIncrementerFactory.getIncrementer(dataSource, ARBITRARY_SEQUENCE.toLowerCase());
60 assertNotNull(incrementer);
61
62
63 int nextIntValue = incrementer.nextIntValue();
64 assertTrue("nextIntValue should be greater than 0", nextIntValue > 0);
65 }
66
67
68
69
70 @Test(expected = DataAccessException.class)
71 public void testGetIncrementer_BadSequence() {
72 DataSource dataSource = TestHarnessServiceLocator.getDataSource();
73 DataFieldMaxValueIncrementer incrementer =
74 MaxValueIncrementerFactory.getIncrementer(dataSource, "OH_NO_YOU_DIDNT!");
75
76
77 assertNotNull(incrementer);
78
79
80 incrementer.nextLongValue();
81 }
82
83 }