001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestOrdinalManager.java 3669 2007-02-26 13:51:23Z gbevin $
007: */
008: package com.uwyn.rife.cmf.dam;
009:
010: import junit.framework.TestCase;
011:
012: import com.uwyn.rife.database.Datasource;
013: import com.uwyn.rife.database.querymanagers.generic.GenericQueryManager;
014: import com.uwyn.rife.database.querymanagers.generic.GenericQueryManagerFactory;
015:
016: public class TestOrdinalManager extends TestCase {
017: private Datasource mDatasource = null;
018: private OrdinalManager mOrdinalManager = null;
019: private GenericQueryManager<Ordered> mOrderedManager = null;
020: private OrdinalManager mOrdinalRestrictedManager = null;
021: private GenericQueryManager<OrderedRestricted> mOrderedRestrictedManager = null;
022:
023: public TestOrdinalManager(Datasource datasource,
024: String datasourceName, String name) {
025: super (name);
026:
027: mDatasource = datasource;
028: }
029:
030: protected void setUp() throws Exception {
031: mOrderedManager = GenericQueryManagerFactory.getInstance(
032: mDatasource, Ordered.class);
033: mOrdinalManager = new OrdinalManager(mDatasource,
034: mOrderedManager.getTable(), "priority");
035: mOrderedManager.install();
036: mOrderedRestrictedManager = GenericQueryManagerFactory
037: .getInstance(mDatasource, OrderedRestricted.class);
038: mOrdinalRestrictedManager = new OrdinalManager(mDatasource,
039: mOrderedRestrictedManager.getTable(), "priority",
040: "restricted");
041: mOrderedRestrictedManager.install();
042: }
043:
044: protected void tearDown() throws Exception {
045: mOrderedManager.remove();
046: mOrderedRestrictedManager.remove();
047: }
048:
049: public void testGetDirection() {
050: assertSame(OrdinalManager.UP, OrdinalManager.Direction
051: .getDirection("up"));
052: assertSame(OrdinalManager.DOWN, OrdinalManager.Direction
053: .getDirection("down"));
054: }
055:
056: public void testInitializationIllegalArguments() {
057: try {
058: new OrdinalManager(null, "table", "ordinal");
059: fail();
060: } catch (IllegalArgumentException e) {
061: assertTrue(true);
062: }
063:
064: try {
065: new OrdinalManager(mDatasource, null, "ordinal");
066: fail();
067: } catch (IllegalArgumentException e) {
068: assertTrue(true);
069: }
070:
071: try {
072: new OrdinalManager(mDatasource, "table", null);
073: fail();
074: } catch (IllegalArgumentException e) {
075: assertTrue(true);
076: }
077:
078: try {
079: new OrdinalManager(mDatasource, "table", "ordinal", null);
080: fail();
081: } catch (IllegalArgumentException e) {
082: assertTrue(true);
083: }
084: }
085:
086: public void testInitialization() {
087: assertEquals(mOrdinalManager.getTable(), mOrderedManager
088: .getTable());
089: assertEquals(mOrdinalManager.getOrdinalColumn(), "priority");
090: assertNull(mOrdinalManager.getRestrictColumn());
091: }
092:
093: public void testInitializationRestricted() {
094: assertEquals(mOrdinalRestrictedManager.getTable(),
095: mOrderedRestrictedManager.getTable());
096: assertEquals(mOrdinalRestrictedManager.getOrdinalColumn(),
097: "priority");
098: assertEquals(mOrdinalRestrictedManager.getRestrictColumn(),
099: "restricted");
100: }
101:
102: public void testFree() {
103: int ordered1 = mOrderedManager.save(new Ordered().name(
104: "ordered 1").priority(0));
105: int ordered2 = mOrderedManager.save(new Ordered().name(
106: "ordered 2").priority(1));
107: int ordered3 = mOrderedManager.save(new Ordered().name(
108: "ordered 3").priority(2));
109: int ordered4 = mOrderedManager.save(new Ordered().name(
110: "ordered 4").priority(3));
111: int ordered5 = mOrderedManager.save(new Ordered().name(
112: "ordered 5").priority(4));
113:
114: assertTrue(mOrdinalManager.free(1));
115: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
116: assertEquals(2, mOrderedManager.restore(ordered2).getPriority());
117: assertEquals(3, mOrderedManager.restore(ordered3).getPriority());
118: assertEquals(4, mOrderedManager.restore(ordered4).getPriority());
119: assertEquals(5, mOrderedManager.restore(ordered5).getPriority());
120: }
121:
122: public void testFreeRestricted() {
123: int ordered1 = mOrderedRestrictedManager
124: .save(new OrderedRestricted().name("ordered 1")
125: .priority(0).restricted(1));
126: int ordered2 = mOrderedRestrictedManager
127: .save(new OrderedRestricted().name("ordered 2")
128: .priority(1).restricted(1));
129: int ordered3 = mOrderedRestrictedManager
130: .save(new OrderedRestricted().name("ordered 3")
131: .priority(2).restricted(1));
132: int ordered4 = mOrderedRestrictedManager
133: .save(new OrderedRestricted().name("ordered 4")
134: .priority(0).restricted(2));
135: int ordered5 = mOrderedRestrictedManager
136: .save(new OrderedRestricted().name("ordered 5")
137: .priority(1).restricted(2));
138:
139: assertTrue(mOrdinalRestrictedManager.free(1, 1));
140: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
141: .getPriority());
142: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
143: .getPriority());
144: assertEquals(3, mOrderedRestrictedManager.restore(ordered3)
145: .getPriority());
146: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
147: .getPriority());
148: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
149: .getPriority());
150:
151: assertTrue(mOrdinalRestrictedManager.free(2, 0));
152: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
153: .getPriority());
154: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
155: .getPriority());
156: assertEquals(3, mOrderedRestrictedManager.restore(ordered3)
157: .getPriority());
158: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
159: .getPriority());
160: assertEquals(2, mOrderedRestrictedManager.restore(ordered5)
161: .getPriority());
162: }
163:
164: public void testFreeOutOfBounds() {
165: int ordered1 = mOrderedManager.save(new Ordered().name(
166: "ordered 1").priority(0));
167: int ordered2 = mOrderedManager.save(new Ordered().name(
168: "ordered 2").priority(1));
169: int ordered3 = mOrderedManager.save(new Ordered().name(
170: "ordered 3").priority(2));
171: int ordered4 = mOrderedManager.save(new Ordered().name(
172: "ordered 4").priority(3));
173: int ordered5 = mOrderedManager.save(new Ordered().name(
174: "ordered 5").priority(4));
175:
176: assertTrue(mOrdinalManager.free(5));
177: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
178: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
179: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
180: assertEquals(3, mOrderedManager.restore(ordered4).getPriority());
181: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
182:
183: assertFalse(mOrdinalManager.free(-1));
184: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
185: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
186: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
187: assertEquals(3, mOrderedManager.restore(ordered4).getPriority());
188: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
189: }
190:
191: public void testFreeOutOfBoundsRestricted() {
192: int ordered1 = mOrderedRestrictedManager
193: .save(new OrderedRestricted().name("ordered 1")
194: .priority(0).restricted(1));
195: int ordered2 = mOrderedRestrictedManager
196: .save(new OrderedRestricted().name("ordered 2")
197: .priority(1).restricted(1));
198: int ordered3 = mOrderedRestrictedManager
199: .save(new OrderedRestricted().name("ordered 3")
200: .priority(2).restricted(1));
201: int ordered4 = mOrderedRestrictedManager
202: .save(new OrderedRestricted().name("ordered 4")
203: .priority(0).restricted(2));
204: int ordered5 = mOrderedRestrictedManager
205: .save(new OrderedRestricted().name("ordered 5")
206: .priority(1).restricted(2));
207:
208: assertTrue(mOrdinalRestrictedManager.free(1, 3));
209: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
210: .getPriority());
211: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
212: .getPriority());
213: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
214: .getPriority());
215: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
216: .getPriority());
217: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
218: .getPriority());
219:
220: assertFalse(mOrdinalRestrictedManager.free(2, -1));
221: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
222: .getPriority());
223: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
224: .getPriority());
225: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
226: .getPriority());
227: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
228: .getPriority());
229: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
230: .getPriority());
231: }
232:
233: public void testFreeOutOfBoundsUnknownRestricted() {
234: int ordered1 = mOrderedRestrictedManager
235: .save(new OrderedRestricted().name("ordered 1")
236: .priority(0).restricted(1));
237: int ordered2 = mOrderedRestrictedManager
238: .save(new OrderedRestricted().name("ordered 2")
239: .priority(1).restricted(1));
240: int ordered3 = mOrderedRestrictedManager
241: .save(new OrderedRestricted().name("ordered 3")
242: .priority(2).restricted(1));
243: int ordered4 = mOrderedRestrictedManager
244: .save(new OrderedRestricted().name("ordered 4")
245: .priority(0).restricted(2));
246: int ordered5 = mOrderedRestrictedManager
247: .save(new OrderedRestricted().name("ordered 5")
248: .priority(1).restricted(2));
249:
250: assertTrue(mOrdinalRestrictedManager.free(3, 1));
251: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
252: .getPriority());
253: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
254: .getPriority());
255: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
256: .getPriority());
257: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
258: .getPriority());
259: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
260: .getPriority());
261: }
262:
263: public void testMove() {
264: int ordered1 = mOrderedManager.save(new Ordered().name(
265: "ordered 1").priority(0));
266: int ordered2 = mOrderedManager.save(new Ordered().name(
267: "ordered 2").priority(1));
268: int ordered3 = mOrderedManager.save(new Ordered().name(
269: "ordered 3").priority(2));
270: int ordered4 = mOrderedManager.save(new Ordered().name(
271: "ordered 4").priority(3));
272: int ordered5 = mOrderedManager.save(new Ordered().name(
273: "ordered 5").priority(4));
274:
275: assertTrue(mOrdinalManager.free(3));
276: assertTrue(mOrdinalManager.update(1, 3));
277: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
278: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
279: assertEquals(3, mOrderedManager.restore(ordered2).getPriority());
280: assertEquals(4, mOrderedManager.restore(ordered4).getPriority());
281: assertEquals(5, mOrderedManager.restore(ordered5).getPriority());
282: }
283:
284: public void testTighten() {
285: int ordered1 = mOrderedManager.save(new Ordered().name(
286: "ordered 1").priority(3));
287: int ordered2 = mOrderedManager.save(new Ordered().name(
288: "ordered 2").priority(13));
289: int ordered3 = mOrderedManager.save(new Ordered().name(
290: "ordered 3").priority(28));
291: int ordered4 = mOrderedManager.save(new Ordered().name(
292: "ordered 4").priority(56));
293: int ordered5 = mOrderedManager.save(new Ordered().name(
294: "ordered 5").priority(300));
295:
296: assertTrue(mOrdinalManager.tighten());
297: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
298: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
299: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
300: assertEquals(3, mOrderedManager.restore(ordered4).getPriority());
301: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
302: }
303:
304: public void testTightenRestricted() {
305: int ordered1 = mOrderedRestrictedManager
306: .save(new OrderedRestricted().name("ordered 1")
307: .priority(3).restricted(1));
308: int ordered2 = mOrderedRestrictedManager
309: .save(new OrderedRestricted().name("ordered 2")
310: .priority(13).restricted(1));
311: int ordered3 = mOrderedRestrictedManager
312: .save(new OrderedRestricted().name("ordered 3")
313: .priority(28).restricted(1));
314: int ordered4 = mOrderedRestrictedManager
315: .save(new OrderedRestricted().name("ordered 4")
316: .priority(56).restricted(2));
317: int ordered5 = mOrderedRestrictedManager
318: .save(new OrderedRestricted().name("ordered 5")
319: .priority(300).restricted(2));
320:
321: assertTrue(mOrdinalRestrictedManager.tighten(1));
322: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
323: .getPriority());
324: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
325: .getPriority());
326: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
327: .getPriority());
328: assertEquals(56, mOrderedRestrictedManager.restore(ordered4)
329: .getPriority());
330: assertEquals(300, mOrderedRestrictedManager.restore(ordered5)
331: .getPriority());
332:
333: assertTrue(mOrdinalRestrictedManager.tighten(2));
334: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
335: .getPriority());
336: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
337: .getPriority());
338: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
339: .getPriority());
340: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
341: .getPriority());
342: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
343: .getPriority());
344:
345: assertFalse(mOrdinalRestrictedManager.tighten(3));
346: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
347: .getPriority());
348: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
349: .getPriority());
350: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
351: .getPriority());
352: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
353: .getPriority());
354: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
355: .getPriority());
356: }
357:
358: public void testObtainInsertOrdinal() {
359: mOrderedManager.save(new Ordered().name("ordered 1")
360: .priority(0));
361: mOrderedManager.save(new Ordered().name("ordered 2")
362: .priority(1));
363: mOrderedManager.save(new Ordered().name("ordered 3")
364: .priority(2));
365: mOrderedManager.save(new Ordered().name("ordered 4")
366: .priority(3));
367: mOrderedManager.save(new Ordered().name("ordered 5")
368: .priority(4));
369: assertEquals(5, mOrdinalManager.obtainInsertOrdinal());
370: }
371:
372: public void testObtainInsertOrdinalRestricted() {
373: mOrderedRestrictedManager.save(new OrderedRestricted().name(
374: "ordered 1").priority(0).restricted(1));
375: mOrderedRestrictedManager.save(new OrderedRestricted().name(
376: "ordered 2").priority(1).restricted(1));
377: mOrderedRestrictedManager.save(new OrderedRestricted().name(
378: "ordered 3").priority(2).restricted(1));
379: mOrderedRestrictedManager.save(new OrderedRestricted().name(
380: "ordered 4").priority(0).restricted(2));
381: mOrderedRestrictedManager.save(new OrderedRestricted().name(
382: "ordered 5").priority(1).restricted(2));
383: assertEquals(3, mOrdinalRestrictedManager
384: .obtainInsertOrdinal(1));
385: assertEquals(2, mOrdinalRestrictedManager
386: .obtainInsertOrdinal(2));
387: assertEquals(0, mOrdinalRestrictedManager
388: .obtainInsertOrdinal(3));
389: }
390:
391: public void testMoveDown() {
392: int ordered1 = mOrderedManager.save(new Ordered().name(
393: "ordered 1").priority(0));
394: int ordered2 = mOrderedManager.save(new Ordered().name(
395: "ordered 2").priority(1));
396: int ordered3 = mOrderedManager.save(new Ordered().name(
397: "ordered 3").priority(2));
398: int ordered4 = mOrderedManager.save(new Ordered().name(
399: "ordered 4").priority(3));
400: int ordered5 = mOrderedManager.save(new Ordered().name(
401: "ordered 5").priority(4));
402:
403: assertTrue(mOrdinalManager.move(OrdinalManager.DOWN, 3));
404: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
405: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
406: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
407: assertEquals(3, mOrderedManager.restore(ordered5).getPriority());
408: assertEquals(4, mOrderedManager.restore(ordered4).getPriority());
409: }
410:
411: public void testMoveDownRestricted() {
412: int ordered1 = mOrderedRestrictedManager
413: .save(new OrderedRestricted().name("ordered 1")
414: .priority(0).restricted(1));
415: int ordered2 = mOrderedRestrictedManager
416: .save(new OrderedRestricted().name("ordered 2")
417: .priority(1).restricted(1));
418: int ordered3 = mOrderedRestrictedManager
419: .save(new OrderedRestricted().name("ordered 3")
420: .priority(2).restricted(1));
421: int ordered4 = mOrderedRestrictedManager
422: .save(new OrderedRestricted().name("ordered 4")
423: .priority(0).restricted(2));
424: int ordered5 = mOrderedRestrictedManager
425: .save(new OrderedRestricted().name("ordered 5")
426: .priority(1).restricted(2));
427:
428: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.DOWN,
429: 1, 1));
430: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
431: .getPriority());
432: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
433: .getPriority());
434: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
435: .getPriority());
436: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
437: .getPriority());
438: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
439: .getPriority());
440:
441: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.DOWN,
442: 2, 0));
443: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
444: .getPriority());
445: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
446: .getPriority());
447: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
448: .getPriority());
449: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
450: .getPriority());
451: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
452: .getPriority());
453: }
454:
455: public void testMoveUp() {
456: int ordered1 = mOrderedManager.save(new Ordered().name(
457: "ordered 1").priority(0));
458: int ordered2 = mOrderedManager.save(new Ordered().name(
459: "ordered 2").priority(1));
460: int ordered3 = mOrderedManager.save(new Ordered().name(
461: "ordered 3").priority(2));
462: int ordered4 = mOrderedManager.save(new Ordered().name(
463: "ordered 4").priority(3));
464: int ordered5 = mOrderedManager.save(new Ordered().name(
465: "ordered 5").priority(4));
466:
467: assertTrue(mOrdinalManager.move(OrdinalManager.UP, 3));
468: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
469: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
470: assertEquals(2, mOrderedManager.restore(ordered4).getPriority());
471: assertEquals(3, mOrderedManager.restore(ordered3).getPriority());
472: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
473: }
474:
475: public void testMoveUpRestricted() {
476: int ordered1 = mOrderedRestrictedManager
477: .save(new OrderedRestricted().name("ordered 1")
478: .priority(0).restricted(1));
479: int ordered2 = mOrderedRestrictedManager
480: .save(new OrderedRestricted().name("ordered 2")
481: .priority(1).restricted(1));
482: int ordered3 = mOrderedRestrictedManager
483: .save(new OrderedRestricted().name("ordered 3")
484: .priority(2).restricted(1));
485: int ordered4 = mOrderedRestrictedManager
486: .save(new OrderedRestricted().name("ordered 4")
487: .priority(0).restricted(2));
488: int ordered5 = mOrderedRestrictedManager
489: .save(new OrderedRestricted().name("ordered 5")
490: .priority(1).restricted(2));
491:
492: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.UP, 1,
493: 2));
494: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
495: .getPriority());
496: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
497: .getPriority());
498: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
499: .getPriority());
500: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
501: .getPriority());
502: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
503: .getPriority());
504:
505: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.UP, 2,
506: 1));
507: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
508: .getPriority());
509: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
510: .getPriority());
511: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
512: .getPriority());
513: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
514: .getPriority());
515: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
516: .getPriority());
517: }
518:
519: public void testMoveOther() {
520: int ordered1 = mOrderedManager.save(new Ordered().name(
521: "ordered 1").priority(0));
522: int ordered2 = mOrderedManager.save(new Ordered().name(
523: "ordered 2").priority(1));
524: int ordered3 = mOrderedManager.save(new Ordered().name(
525: "ordered 3").priority(2));
526: int ordered4 = mOrderedManager.save(new Ordered().name(
527: "ordered 4").priority(3));
528: int ordered5 = mOrderedManager.save(new Ordered().name(
529: "ordered 5").priority(4));
530:
531: assertTrue(mOrdinalManager.move(3, 1));
532: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
533: assertEquals(1, mOrderedManager.restore(ordered4).getPriority());
534: assertEquals(2, mOrderedManager.restore(ordered2).getPriority());
535: assertEquals(3, mOrderedManager.restore(ordered3).getPriority());
536: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
537:
538: assertTrue(mOrdinalManager.move(2, 4));
539: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
540: assertEquals(1, mOrderedManager.restore(ordered4).getPriority());
541: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
542: assertEquals(3, mOrderedManager.restore(ordered2).getPriority());
543: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
544: }
545:
546: public void testMoveOtherRestricted() {
547: int ordered1 = mOrderedRestrictedManager
548: .save(new OrderedRestricted().name("ordered 1")
549: .priority(0).restricted(1));
550: int ordered2 = mOrderedRestrictedManager
551: .save(new OrderedRestricted().name("ordered 2")
552: .priority(1).restricted(1));
553: int ordered3 = mOrderedRestrictedManager
554: .save(new OrderedRestricted().name("ordered 3")
555: .priority(2).restricted(1));
556: int ordered4 = mOrderedRestrictedManager
557: .save(new OrderedRestricted().name("ordered 4")
558: .priority(0).restricted(2));
559: int ordered5 = mOrderedRestrictedManager
560: .save(new OrderedRestricted().name("ordered 5")
561: .priority(1).restricted(2));
562:
563: assertTrue(mOrdinalRestrictedManager.move(1, 2, 0));
564: assertEquals(0, mOrderedRestrictedManager.restore(ordered3)
565: .getPriority());
566: assertEquals(1, mOrderedRestrictedManager.restore(ordered1)
567: .getPriority());
568: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
569: .getPriority());
570: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
571: .getPriority());
572: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
573: .getPriority());
574:
575: assertTrue(mOrdinalRestrictedManager.move(2, 1, 0));
576: assertEquals(0, mOrderedRestrictedManager.restore(ordered3)
577: .getPriority());
578: assertEquals(1, mOrderedRestrictedManager.restore(ordered1)
579: .getPriority());
580: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
581: .getPriority());
582: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
583: .getPriority());
584: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
585: .getPriority());
586:
587: assertTrue(mOrdinalRestrictedManager.move(1, 0, 2));
588: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
589: .getPriority());
590: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
591: .getPriority());
592: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
593: .getPriority());
594: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
595: .getPriority());
596: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
597: .getPriority());
598:
599: assertTrue(mOrdinalRestrictedManager.move(2, 0, 1));
600: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
601: .getPriority());
602: assertEquals(1, mOrderedRestrictedManager.restore(ordered3)
603: .getPriority());
604: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
605: .getPriority());
606: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
607: .getPriority());
608: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
609: .getPriority());
610: }
611:
612: public void testMoveDownExtremity() {
613: int ordered1 = mOrderedManager.save(new Ordered().name(
614: "ordered 1").priority(0));
615: int ordered2 = mOrderedManager.save(new Ordered().name(
616: "ordered 2").priority(1));
617: int ordered3 = mOrderedManager.save(new Ordered().name(
618: "ordered 3").priority(2));
619: int ordered4 = mOrderedManager.save(new Ordered().name(
620: "ordered 4").priority(3));
621: int ordered5 = mOrderedManager.save(new Ordered().name(
622: "ordered 5").priority(4));
623:
624: assertTrue(mOrdinalManager.move(OrdinalManager.DOWN, 4));
625: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
626: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
627: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
628: assertEquals(3, mOrderedManager.restore(ordered4).getPriority());
629: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
630: }
631:
632: public void testMoveDownExtremityRestricted() {
633: int ordered1 = mOrderedRestrictedManager
634: .save(new OrderedRestricted().name("ordered 1")
635: .priority(0).restricted(1));
636: int ordered2 = mOrderedRestrictedManager
637: .save(new OrderedRestricted().name("ordered 2")
638: .priority(1).restricted(1));
639: int ordered3 = mOrderedRestrictedManager
640: .save(new OrderedRestricted().name("ordered 3")
641: .priority(2).restricted(1));
642: int ordered4 = mOrderedRestrictedManager
643: .save(new OrderedRestricted().name("ordered 4")
644: .priority(0).restricted(2));
645: int ordered5 = mOrderedRestrictedManager
646: .save(new OrderedRestricted().name("ordered 5")
647: .priority(1).restricted(2));
648:
649: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.DOWN,
650: 1, 2));
651: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
652: .getPriority());
653: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
654: .getPriority());
655: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
656: .getPriority());
657: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
658: .getPriority());
659: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
660: .getPriority());
661:
662: assertTrue(mOrdinalRestrictedManager.move(OrdinalManager.DOWN,
663: 2, 1));
664: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
665: .getPriority());
666: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
667: .getPriority());
668: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
669: .getPriority());
670: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
671: .getPriority());
672: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
673: .getPriority());
674: }
675:
676: public void testMoveUpExtremity() {
677: int ordered1 = mOrderedManager.save(new Ordered().name(
678: "ordered 1").priority(0));
679: int ordered2 = mOrderedManager.save(new Ordered().name(
680: "ordered 2").priority(1));
681: int ordered3 = mOrderedManager.save(new Ordered().name(
682: "ordered 3").priority(2));
683: int ordered4 = mOrderedManager.save(new Ordered().name(
684: "ordered 4").priority(3));
685: int ordered5 = mOrderedManager.save(new Ordered().name(
686: "ordered 5").priority(4));
687:
688: assertFalse(mOrdinalManager.move(OrdinalManager.UP, 0));
689: assertEquals(0, mOrderedManager.restore(ordered1).getPriority());
690: assertEquals(1, mOrderedManager.restore(ordered2).getPriority());
691: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
692: assertEquals(3, mOrderedManager.restore(ordered4).getPriority());
693: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
694: }
695:
696: public void testMoveUpExtremityRestricted() {
697: int ordered1 = mOrderedRestrictedManager
698: .save(new OrderedRestricted().name("ordered 1")
699: .priority(0).restricted(1));
700: int ordered2 = mOrderedRestrictedManager
701: .save(new OrderedRestricted().name("ordered 2")
702: .priority(1).restricted(1));
703: int ordered3 = mOrderedRestrictedManager
704: .save(new OrderedRestricted().name("ordered 3")
705: .priority(2).restricted(1));
706: int ordered4 = mOrderedRestrictedManager
707: .save(new OrderedRestricted().name("ordered 4")
708: .priority(0).restricted(2));
709: int ordered5 = mOrderedRestrictedManager
710: .save(new OrderedRestricted().name("ordered 5")
711: .priority(1).restricted(2));
712:
713: assertFalse(mOrdinalRestrictedManager.move(OrdinalManager.UP,
714: 1, 0));
715: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
716: .getPriority());
717: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
718: .getPriority());
719: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
720: .getPriority());
721: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
722: .getPriority());
723: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
724: .getPriority());
725:
726: assertFalse(mOrdinalRestrictedManager.move(OrdinalManager.UP,
727: 2, 0));
728: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
729: .getPriority());
730: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
731: .getPriority());
732: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
733: .getPriority());
734: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
735: .getPriority());
736: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
737: .getPriority());
738: }
739:
740: public void testMoveOtherExtremity() {
741: int ordered1 = mOrderedManager.save(new Ordered().name(
742: "ordered 1").priority(0));
743: int ordered2 = mOrderedManager.save(new Ordered().name(
744: "ordered 2").priority(1));
745: int ordered3 = mOrderedManager.save(new Ordered().name(
746: "ordered 3").priority(2));
747: int ordered4 = mOrderedManager.save(new Ordered().name(
748: "ordered 4").priority(3));
749: int ordered5 = mOrderedManager.save(new Ordered().name(
750: "ordered 5").priority(4));
751:
752: assertTrue(mOrdinalManager.move(3, 0));
753: assertEquals(0, mOrderedManager.restore(ordered4).getPriority());
754: assertEquals(1, mOrderedManager.restore(ordered1).getPriority());
755: assertEquals(2, mOrderedManager.restore(ordered2).getPriority());
756: assertEquals(3, mOrderedManager.restore(ordered3).getPriority());
757: assertEquals(4, mOrderedManager.restore(ordered5).getPriority());
758:
759: assertTrue(mOrdinalManager.move(2, 8));
760: assertEquals(0, mOrderedManager.restore(ordered4).getPriority());
761: assertEquals(1, mOrderedManager.restore(ordered1).getPriority());
762: assertEquals(2, mOrderedManager.restore(ordered3).getPriority());
763: assertEquals(3, mOrderedManager.restore(ordered5).getPriority());
764: assertEquals(4, mOrderedManager.restore(ordered2).getPriority());
765: }
766:
767: public void testMoveOtherExtremityRestricted() {
768: int ordered1 = mOrderedRestrictedManager
769: .save(new OrderedRestricted().name("ordered 1")
770: .priority(0).restricted(1));
771: int ordered2 = mOrderedRestrictedManager
772: .save(new OrderedRestricted().name("ordered 2")
773: .priority(1).restricted(1));
774: int ordered3 = mOrderedRestrictedManager
775: .save(new OrderedRestricted().name("ordered 3")
776: .priority(2).restricted(1));
777: int ordered4 = mOrderedRestrictedManager
778: .save(new OrderedRestricted().name("ordered 4")
779: .priority(0).restricted(2));
780: int ordered5 = mOrderedRestrictedManager
781: .save(new OrderedRestricted().name("ordered 5")
782: .priority(1).restricted(2));
783:
784: assertTrue(mOrdinalRestrictedManager.move(1, 2, 0));
785: assertEquals(0, mOrderedRestrictedManager.restore(ordered3)
786: .getPriority());
787: assertEquals(1, mOrderedRestrictedManager.restore(ordered1)
788: .getPriority());
789: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
790: .getPriority());
791: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
792: .getPriority());
793: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
794: .getPriority());
795:
796: assertTrue(mOrdinalRestrictedManager.move(2, 1, 0));
797: assertEquals(0, mOrderedRestrictedManager.restore(ordered3)
798: .getPriority());
799: assertEquals(1, mOrderedRestrictedManager.restore(ordered1)
800: .getPriority());
801: assertEquals(2, mOrderedRestrictedManager.restore(ordered2)
802: .getPriority());
803: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
804: .getPriority());
805: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
806: .getPriority());
807:
808: assertTrue(mOrdinalRestrictedManager.move(1, 0, 6));
809: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
810: .getPriority());
811: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
812: .getPriority());
813: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
814: .getPriority());
815: assertEquals(0, mOrderedRestrictedManager.restore(ordered5)
816: .getPriority());
817: assertEquals(1, mOrderedRestrictedManager.restore(ordered4)
818: .getPriority());
819:
820: assertTrue(mOrdinalRestrictedManager.move(2, 0, 7));
821: assertEquals(0, mOrderedRestrictedManager.restore(ordered1)
822: .getPriority());
823: assertEquals(1, mOrderedRestrictedManager.restore(ordered2)
824: .getPriority());
825: assertEquals(2, mOrderedRestrictedManager.restore(ordered3)
826: .getPriority());
827: assertEquals(0, mOrderedRestrictedManager.restore(ordered4)
828: .getPriority());
829: assertEquals(1, mOrderedRestrictedManager.restore(ordered5)
830: .getPriority());
831: }
832: }
|