001: /******************************************************************
002: * File: TestAnonID.java
003: * Created by: Dave Reynolds
004: * Created on: 18-Mar-2004
005: *
006: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
007: * [See end of file]
008: * $Id: TestAnonID.java,v 1.8 2008/01/02 12:04:41 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.rdf.model.test;
010:
011: import com.hp.hpl.jena.rdf.model.AnonId;
012: import com.hp.hpl.jena.shared.impl.JenaParameters;
013: import com.hp.hpl.jena.test.JenaTestBase;
014:
015: import junit.framework.TestSuite;
016:
017: /**
018: * Test for anonID generation. (Originally test for the debugging hack
019: * that switches off anonID generation.)
020: *
021: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
022: * @version $Revision: 1.8 $ on $Date: 2008/01/02 12:04:41 $
023: */
024: public class TestAnonID extends JenaTestBase {
025:
026: /**
027: * Boilerplate for junit
028: */
029: public TestAnonID(String name) {
030: super (name);
031: }
032:
033: /**
034: * Boilerplate for junit.
035: * This is its own test suite
036: */
037: public static TestSuite suite() {
038: return new TestSuite(TestAnonID.class);
039: }
040:
041: /**
042: * Check that anonIDs are distinct whichever state the flag is in.
043: */
044: public void testAnonID() {
045: boolean prior = JenaParameters.disableBNodeUIDGeneration;
046: try {
047: JenaParameters.disableBNodeUIDGeneration = false;
048: doTestAnonID();
049: JenaParameters.disableBNodeUIDGeneration = true;
050: doTestAnonID();
051: } finally {
052: JenaParameters.disableBNodeUIDGeneration = prior;
053: }
054: }
055:
056: /**
057: Check that anonIDs are distinct whichever state the flag is in.
058: */
059: public void doTestAnonID() {
060: AnonId id1 = AnonId.create();
061: AnonId id2 = AnonId.create();
062: AnonId id3 = AnonId.create();
063: AnonId id4 = AnonId.create();
064:
065: assertDiffer(id1, id2);
066: assertDiffer(id1, id3);
067: assertDiffer(id1, id4);
068: assertDiffer(id2, id3);
069: assertDiffer(id2, id4);
070: }
071:
072: /**
073: Test that creation of an AnonId from an AnonId string preserves that
074: string and is equal to the original AnonId.
075: */
076: public void testAnonIdPreserved() {
077: AnonId anon = AnonId.create();
078: String id = anon.toString();
079: assertEquals(anon, AnonId.create(id));
080: assertEquals(id, AnonId.create(id).toString());
081: }
082:
083: }
084:
085: /*
086: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
087: All rights reserved.
088:
089: Redistribution and use in source and binary forms, with or without
090: modification, are permitted provided that the following conditions
091: are met:
092:
093: 1. Redistributions of source code must retain the above copyright
094: notice, this list of conditions and the following disclaimer.
095:
096: 2. Redistributions in binary form must reproduce the above copyright
097: notice, this list of conditions and the following disclaimer in the
098: documentation and/or other materials provided with the distribution.
099:
100: 3. The name of the author may not be used to endorse or promote products
101: derived from this software without specific prior written permission.
102:
103: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
104: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
105: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
106: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
107: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
108: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
109: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
110: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
111: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
112: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
113: */
|