1 package org.kuali.rice.krad.service;
2
3 import org.junit.Test;
4 import org.kuali.rice.core.api.config.ConfigurationException;
5 import org.kuali.rice.kns.service.KNSServiceLocator;
6 import org.kuali.rice.krad.test.KRADTestCase;
7 import org.kuali.rice.krad.test.document.OjbAndJpa;
8 import org.kuali.rice.krad.test.document.OjbOnly;
9 import org.kuali.rice.krad.test.document.bo.JPADataObject;
10
11 import static org.junit.Assert.*;
12
13
14
15
16
17
18
19 public class SequenceAccessorServiceTest extends KRADTestCase {
20
21 private static final String ARBITRARY_SEQUENCE = "trvl_id_seq";
22
23
24
25
26
27 @Test
28 public void testExceptionForKradData() {
29 try {
30 KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(ARBITRARY_SEQUENCE, JPADataObject.class);
31 fail( "Using Legacy SequenceAccessorService in non-Legacy Context - should have failed." );
32 } catch ( ConfigurationException ex ) {
33
34 } catch ( Exception ex ) {
35 fail( "We should have failed with a configuration Exception - but intead got a: " + ex.getClass().getName() + " : " + ex.getMessage() );
36 ex.printStackTrace();
37 }
38 }
39
40 @Test
41 public void testOjbOnlyWorks() {
42 Long nextAvailableSequenceNumber =
43 KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(ARBITRARY_SEQUENCE, OjbOnly.class);
44 assertNotNull("Next sequence number should not have been null",nextAvailableSequenceNumber);
45 assertTrue( "Nest sequence number should have been created than zero. Was: " + nextAvailableSequenceNumber, nextAvailableSequenceNumber.longValue() > 0);
46 }
47
48 @Test
49 @Legacy
50 public void testNoExceptionForBothKradDataAndOjb_InLegacyContext() {
51 Long nextAvailableSequenceNumber =
52 KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(ARBITRARY_SEQUENCE, OjbAndJpa.class);
53 assertNotNull("Next sequence number should not have been null",nextAvailableSequenceNumber);
54 assertTrue( "Nest sequence number should have been created than zero. Was: " + nextAvailableSequenceNumber, nextAvailableSequenceNumber.longValue() > 0);
55 }
56
57 @Test
58 public void testExceptionForBothKradDataAndOjb_NotInLegacyContext() {
59 try {
60
61 KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(ARBITRARY_SEQUENCE, OjbAndJpa.class);
62 fail( "Using Legacy SequenceAccessorService in non-Legacy Context - should have failed." );
63 } catch ( ConfigurationException ex ) {
64
65 } catch ( Exception ex ) {
66 fail( "We should have failed with a configuration Exception - but intead got a: " + ex.getClass().getName() + " : " + ex.getMessage() );
67 ex.printStackTrace();
68 }
69 }
70
71 }