001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded;
034:
035: import com.flexive.shared.CustomSequencer;
036: import com.flexive.shared.EJBLookup;
037: import com.flexive.shared.exceptions.FxApplicationException;
038: import com.flexive.shared.exceptions.FxLogoutFailedException;
039: import com.flexive.shared.interfaces.SequencerEngine;
040: import static com.flexive.tests.embedded.FxTestUtils.login;
041: import static com.flexive.tests.embedded.FxTestUtils.logout;
042: import org.apache.commons.lang.RandomStringUtils;
043: import org.testng.annotations.AfterClass;
044: import org.testng.annotations.BeforeClass;
045: import org.testng.annotations.Test;
046:
047: import java.util.List;
048:
049: /**
050: * Sequencer tests
051: *
052: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
053: */
054: @Test(groups={"ejb","structure"})
055: public class SequencerTest {
056:
057: private SequencerEngine id;
058:
059: @BeforeClass
060: public void beforeClass() throws Exception {
061: id = EJBLookup.getSequencerEngine();
062: login(TestUsers.SUPERVISOR);
063: }
064:
065: @AfterClass
066: public void afterClass() throws FxLogoutFailedException {
067: logout();
068: }
069:
070: @Test
071: public void customSequencer() throws Exception {
072: List<CustomSequencer> startList = id.getCustomSequencers();
073: String seq1 = "A"
074: + RandomStringUtils.randomAlphanumeric(16)
075: .toUpperCase();
076: String seq2 = "B"
077: + RandomStringUtils.randomAlphanumeric(16)
078: .toUpperCase();
079: String seq3 = "C"
080: + RandomStringUtils.randomAlphanumeric(16)
081: .toUpperCase();
082: id.createSequencer(seq1, true, 0);
083: id.createSequencer(seq2, true, SequencerEngine.MAX_ID);
084: id.createSequencer(seq3, false, SequencerEngine.MAX_ID);
085: assert id.sequencerExists(seq1) : "Expected sequencer " + seq1
086: + " to exist!";
087: assert id.sequencerExists(seq2) : "Expected sequencer " + seq2
088: + " to exist!";
089: assert id.sequencerExists(seq3) : "Expected sequencer " + seq3
090: + " to exist!";
091: long i1 = id.getId(seq1);
092: long i2 = id.getId(seq1);
093: assert i2 > i1 : "Expected a higher id after 2nd getId()!";
094: i1 = id.getId(seq2); //call should cause the sequencer to roll over
095: assert i1 == 0 : "Expected: " + 0 + ", got: " + i1;
096:
097: try {
098: id.getId(seq3);
099: assert false : "Expected an exception since seq3 should be exhausted!";
100: } catch (FxApplicationException e) {
101: //expected
102: }
103:
104: List<CustomSequencer> g2 = id.getCustomSequencers();
105: g2.removeAll(startList);
106: assert g2.size() == 3 : "Expected a size of 3, but got "
107: + g2.size();
108: assert g2.get(0).getName().equals(seq1) : "Expected " + seq1
109: + " got " + g2.get(0).getName();
110: assert g2.get(1).getName().equals(seq2) : "Expected " + seq2
111: + " got " + g2.get(1).getName();
112: assert g2.get(2).getName().equals(seq3) : "Expected " + seq3
113: + " got " + g2.get(2).getName();
114: assert g2.get(0).isAllowRollover();
115: assert g2.get(1).isAllowRollover();
116: assert !g2.get(2).isAllowRollover();
117: id.removeSequencer(seq1);
118: id.removeSequencer(seq2);
119: id.removeSequencer(seq3);
120: assert id.getCustomSequencers().size() == startList.size();
121: }
122: }
|