001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data;
017:
018: import junit.framework.TestCase;
019:
020: /**
021: * Test of LockingAPI FeatureLock data object.
022: * <p>
023: *
024: * @see org.geotools.data
025: * @author jgarnett, Refractions Reasearch Inc.
026: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/data/FeatureLockTest.java $
027: * @version CVS Version
028: */
029: public class FeatureLockTest extends TestCase {
030: String lockName;
031: long lockDuration;
032: FeatureLock lock;
033:
034: /**
035: * Constructor for LockTest.
036: * @param arg0
037: */
038: public FeatureLockTest(String arg0) {
039: super (arg0);
040: }
041:
042: /**
043: * Sets up lock objects for use.
044: * </p>
045: * @throws java.lang.Exception
046: *
047: * @see junit.framework.TestCase#setUp()
048: */
049: protected void setUp() throws Exception {
050: lockDuration = 4 * 60 * 60 * 60; // 4 hours/60 min/60 sec/60 milliseconds
051: lockName = "TestLock";
052: lock = DefaultFeatureLockFactory.createTestLock(lockName,
053: lockDuration);
054: }
055:
056: /**
057: * Clears lock objects.
058: *
059: * @throws java.lang.Exception
060: *
061: * @see junit.framework.TestCase#tearDown()
062: */
063: protected void tearDown() throws Exception {
064: super .tearDown();
065: lockName = null;
066: lock = null;
067: }
068:
069: public void testGetID() {
070: assertEquals("lockName", lockName, lock.getAuthorization());
071: }
072:
073: public void testGetExpire() {
074: assertEquals("lockDate", lockDuration, lock.getDuration());
075: }
076:
077: /*
078: * Test for FeatureLock generate(int)
079: */
080: public void testGenerateint() {
081: FeatureLock lock = FeatureLockFactory.generate("Test", 3600);
082: }
083:
084: public void testNextIDNumberDate() {
085: DefaultFeatureLockFactory.seedIdNumber(0);
086: long number1 = DefaultFeatureLockFactory
087: .nextIdNumber(lockDuration);
088: long number2 = DefaultFeatureLockFactory
089: .nextIdNumber(lockDuration);
090: long number3 = DefaultFeatureLockFactory
091: .nextIdNumber(lockDuration);
092: assertFalse("lockDate:" + number1, number1 == number2);
093: assertFalse("lockDate:" + number1, number1 == number3);
094: assertFalse("lockDate:" + number1, number2 == number3);
095:
096: }
097:
098: /*
099: * Test for FeatureLock generate(String, long)
100: */
101: public void testGenerateStringLong() {
102: FeatureLock lock = FeatureLockFactory.generate("Test",
103: lockDuration);
104: assertTrue(lock.getAuthorization().startsWith("Test"));
105: }
106: }
|