1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package org.jomc.sequences.it;
38
39 import java.io.IOException;
40 import java.io.InputStream;
41 import java.net.URL;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.List;
45 import java.util.logging.LogManager;
46 import org.jomc.sequences.Sequence;
47 import org.jomc.sequences.SequenceLimitException;
48 import org.jomc.sequences.SequenceNotFoundException;
49 import org.jomc.sequences.SequencesSystemException;
50 import org.junit.Test;
51 import org.junit.runner.JUnitCore;
52 import static org.junit.Assert.assertEquals;
53 import static org.junit.Assert.assertNotNull;
54 import static org.junit.Assert.fail;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
75
76
77 public class SequenceOperationsTest
78 {
79
80
81
82 private static final int TEST_INCREMENT = 10;
83
84
85
86
87
88
89 @Test public void testIllegalArguments() throws Exception
90 {
91 assert this.getSequenceOperations() != null;
92
93 try
94 {
95 this.getSequenceOperations().getNextSequenceValue( null );
96 fail( "Expected SequencesSystemException not thrown." );
97 }
98 catch ( final SequencesSystemException e )
99 {
100 assertNotNull( e.getMessage() );
101 System.out.println( e.toString() );
102 }
103
104 try
105 {
106 this.getSequenceOperations().getNextSequenceValues( null, 0 );
107 fail( "Expected SequencesSystemException not thrown." );
108 }
109 catch ( final SequencesSystemException e )
110 {
111 assertNotNull( e.getMessage() );
112 System.out.println( e.toString() );
113 }
114
115 try
116 {
117 this.getSequenceOperations().getNextSequenceValues( "TEST", -1 );
118 fail( "Expected SequencesSystemException not thrown." );
119 }
120 catch ( final SequencesSystemException e )
121 {
122 assertNotNull( e.getMessage() );
123 System.out.println( e.toString() );
124 }
125
126 }
127
128
129
130
131
132 @Test public void testSequenceNotFoundException() throws Exception
133 {
134 assert this.getSequenceOperations() != null;
135
136 try
137 {
138 this.getSequenceOperations().getNextSequenceValue( "UNKNOWN" );
139 fail( "Expected SequenceNotFoundException not thrown." );
140 }
141 catch ( final SequenceNotFoundException e )
142 {
143 assertNotNull( e.getMessage() );
144 System.out.println( e.toString() );
145 }
146
147 try
148 {
149 this.getSequenceOperations().getNextSequenceValues( "UNKNOWN", 100 );
150 fail( "Expected SequenceNotFoundException not thrown." );
151 }
152 catch ( final SequenceNotFoundException e )
153 {
154 assertNotNull( e.getMessage() );
155 System.out.println( e.toString() );
156 }
157 }
158
159
160
161
162
163
164 @Test public void testSequenceLimitException() throws Exception
165 {
166 this.setupTestSequence();
167
168 final long nextValue = this.getSequenceOperations().getNextSequenceValue( this.getClass().getName() );
169
170 assertEquals( 10, nextValue );
171
172 try
173 {
174 this.getSequenceOperations().getNextSequenceValue( this.getClass().getName() );
175 fail( "Expected SequenceLimitException not thrown." );
176 }
177 catch ( final SequenceLimitException e )
178 {
179 assertNotNull( e.getMessage() );
180 System.out.println( e.toString() );
181 }
182
183 this.setupTestSequence();
184
185 final long[] nextValues = this.getSequenceOperations().getNextSequenceValues( this.getClass().getName(), 1 );
186 assertEquals( 1, nextValues.length );
187 assertEquals( 10, nextValues[0] );
188
189 try
190 {
191 this.getSequenceOperations().getNextSequenceValues( this.getClass().getName(), 1 );
192 fail( "Expected SequenceLimitException not thrown." );
193 }
194 catch ( final SequenceLimitException e )
195 {
196 assertNotNull( e.getMessage() );
197 System.out.println( e.toString() );
198 }
199 }
200
201
202
203
204
205
206
207
208
209 public static void main( final String... args )
210 {
211 try
212 {
213 final URL loggingProperties = SequenceOperationsTest.class.getResource( "/logging.properties" );
214 if ( loggingProperties != null )
215 {
216 final InputStream in = loggingProperties.openStream();
217 LogManager.getLogManager().readConfiguration( in );
218 in.close();
219 }
220
221 final List<String> l = new ArrayList<String>( Arrays.asList( args ) );
222 l.add( 0, SequenceOperationsTest.class.getName() );
223 JUnitCore.main( l.toArray( new String[ l.size() ] ) );
224 }
225 catch ( final IOException e )
226 {
227 e.printStackTrace();
228 System.exit( 1 );
229 }
230 }
231
232 private void setupTestSequence() throws Exception
233 {
234 assert this.getSequenceDirectory() != null;
235
236 Sequence s = this.getSequenceDirectory().getSequence( this.getClass().getName() );
237
238 if ( s == null )
239 {
240 s = new Sequence();
241 s.setIncrement( TEST_INCREMENT );
242 s.setMaximum( TEST_INCREMENT );
243 s.setMinimum( 0 );
244 s.setName( this.getClass().getName() );
245 s.setValue( 0 );
246
247 this.getSequenceDirectory().addSequence( s );
248 }
249 else
250 {
251 s.setValue( 0 );
252 this.getSequenceDirectory().editSequence( s.getName(), s.getRevision(), s );
253 }
254 }
255
256
257
258
259
260
261 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
262 public SequenceOperationsTest()
263 {
264
265 super();
266
267 }
268
269
270
271
272
273
274
275
276
277
278
279
280
281 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
282 private org.jomc.sequences.SequenceDirectory getSequenceDirectory()
283 {
284 return (org.jomc.sequences.SequenceDirectory) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SequenceDirectory" );
285 }
286
287
288
289
290
291
292
293
294
295 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.0", comments = "See http://jomc.sourceforge.net/jomc/1.0/jomc-tools" )
296 private org.jomc.sequences.SequenceOperations getSequenceOperations()
297 {
298 return (org.jomc.sequences.SequenceOperations) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "SequenceOperations" );
299 }
300
301
302
303
304
305
306 }