1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.data.platform;
18
19 import org.junit.Test;
20 import org.kuali.rice.krad.test.KRADTestCase;
21 import org.kuali.rice.test.TestHarnessServiceLocator;
22 import org.springframework.context.ConfigurableApplicationContext;
23 import org.springframework.context.support.ClassPathXmlApplicationContext;
24 import org.springframework.dao.DataAccessException;
25 import org.springframework.jdbc.BadSqlGrammarException;
26 import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
27
28 import javax.sql.DataSource;
29
30 import static org.junit.Assert.*;
31
32 public class MaxValueIncrementerFactoryBeanIntegrationTest extends KRADTestCase {
33
34 private final static String TEST_INCREMENTER = "testIncrementer";
35 private final static String INVALID_TEST_INCREMENTER = "invalidTestIncrementer";
36
37 private ConfigurableApplicationContext context;
38
39 @Override
40 public void setUpInternal() throws Exception {
41 super.setUpInternal();
42 context = new ClassPathXmlApplicationContext("MaxValueIncrementerFactoryBeanTest.xml", getClass());
43 }
44
45 @Override
46 public void tearDown() throws Exception {
47 if (context != null) {
48 context.close();
49 }
50 super.tearDown();
51 }
52
53
54
55
56 @Test
57 public void testGetIncrementer_nextValues() {
58 DataFieldMaxValueIncrementer incrementer = (DataFieldMaxValueIncrementer) context.getBean(TEST_INCREMENTER);
59 assertNotNull(incrementer);
60
61
62 int nextIntValue = incrementer.nextIntValue();
63 assertTrue("nextIntValue should be greater than 0", nextIntValue > 0);
64
65
66 int nextNextIntValue = incrementer.nextIntValue();
67 assertEquals("Next value should be one higher", nextIntValue + 1, nextNextIntValue);
68
69
70 long nextLongValue = incrementer.nextLongValue();
71 assertEquals(nextNextIntValue + 1, nextLongValue);
72
73
74 String nextStringValue = incrementer.nextStringValue();
75 assertEquals(nextLongValue + 1, Long.parseLong(nextStringValue));
76 }
77
78
79
80
81
82 @Test
83 public void testGetIncrementer_CaseInsensitive() {
84 DataFieldMaxValueIncrementer incrementer = (DataFieldMaxValueIncrementer) context.getBean(TEST_INCREMENTER);
85 assertNotNull(incrementer);
86
87
88 int nextIntValue = incrementer.nextIntValue();
89 assertTrue("nextIntValue should be greater than 0", nextIntValue > 0);
90 }
91
92
93
94
95 @Test(expected = DataAccessException.class)
96 public void testGetIncrementer_BadSequence() {
97 DataFieldMaxValueIncrementer incrementer = (DataFieldMaxValueIncrementer) context.getBean(INVALID_TEST_INCREMENTER);
98
99
100 assertNotNull(incrementer);
101
102
103 incrementer.nextLongValue();
104 }
105 }