001: /******************************************************************
002: * File: TestRemoveBug.java
003: * Created by: Dave Reynolds
004: * Created on: 06-Feb-2006
005: *
006: * (c) Copyright 2006, Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: TestRemoveBug.java,v 1.5 2008/01/02 12:04:40 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.rdf.model.test;
010:
011: import java.io.StringReader;
012:
013: import com.hp.hpl.jena.rdf.model.Model;
014: import com.hp.hpl.jena.rdf.model.ModelFactory;
015: import com.hp.hpl.jena.rdf.model.Property;
016: import com.hp.hpl.jena.rdf.model.RDFNode;
017: import com.hp.hpl.jena.rdf.model.ResIterator;
018: import com.hp.hpl.jena.rdf.model.Resource;
019: import com.hp.hpl.jena.rdf.model.Statement;
020: import com.hp.hpl.jena.rdf.model.StmtIterator;
021:
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024:
025: /**
026: *
027: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
028: * @version $Revision: 1.5 $
029: */
030:
031: public class TestRemoveBug extends TestCase {
032:
033: public TestRemoveBug(String name) {
034: super (name);
035: }
036:
037: public static TestSuite suite() {
038: return new TestSuite(TestRemoveBug.class);
039: }
040:
041: /**
042: * Test a bug case, intermittent only (about 1 in 50!)
043: */
044: public void testBug1() {
045: String src = "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n"
046: + "<http://www.hp.com/people/Ian_Dickinson> foaf:mbox_sha1sum '896dfb5980f37c47ada8c2a2538888d0c39e582d' .\n"
047: +
048: // "[a foaf:Person ; foaf:name 'Ian Dickinson' ; foaf:title 'Mr' ;" +
049: // " foaf:givenname 'Ian' ; foaf:family_name 'Dickinson' ;\n" +
050: // " foaf:mbox_sha1sum '896dfb5980f37c47ada8c2a2538888d0c39e582d' ;" +
051: // " foaf:homepage <http://www.iandickinson.me.uk>;\n" +
052: // " foaf:phone <tel:+44-(117)-312-8796> ; " +
053: // " foaf:depiction <http://www.iandickinson.me.uk/images/me2005.jpg>;" +
054: // " foaf:workInfoHomepage <http://www.hpl.hp.com/semweb>" +
055: "[] foaf:name 'Ian Dickinson' ;\n"
056: + " foaf:p1 'v1'; \n"
057: + " foaf:p1 'v2'; \n"
058: + " foaf:p1 'v3'; \n"
059: + " foaf:p1 'v4'; \n"
060: + " foaf:p1 'v5'; \n"
061: + " foaf:p1 'v6'; \n"
062: + " foaf:p1 'v7'; \n"
063: + " foaf:p1 'v8'; \n"
064: + " foaf:p1 'v9'; \n" + ".";
065:
066: for (int count = 0; count < 1000; count++) {
067: // System.out.println("Test " + count);
068: Model incoming = ModelFactory.createDefaultModel();
069: incoming.read(new StringReader(src), null, "N3");
070:
071: // Find the bNode that will be rewritten
072: Property name = incoming.createProperty(
073: "http://xmlns.com/foaf/0.1/", "name");
074: ResIterator ri = incoming.listSubjectsWithProperty(name,
075: "Ian Dickinson");
076: Resource bNode = ri.nextResource();
077: ri.close();
078:
079: // Rewrite it to ground form
080: int originalCount = bNode.listProperties().toList().size();
081: Resource newR = incoming
082: .createResource("http://www.hp.com/people/Ian_Dickinson");
083: int runningCount = 0;
084: StmtIterator si = incoming.listStatements(bNode, null,
085: (RDFNode) null);
086: Model additions = ModelFactory.createDefaultModel();
087: while (si.hasNext()) {
088: Statement s = si.nextStatement();
089: runningCount += 1;
090: si.remove();
091: // System.out.println("Rewrite " + s + " base on " + newR);
092: additions.add(additions.createStatement(newR, s
093: .getPredicate(), s.getObject()));
094: }
095: assertEquals("on iteration " + count + " with "
096: + bNode.asNode().getBlankNodeLabel(),
097: originalCount, runningCount);
098: incoming.add(additions);
099: Resource ian = incoming
100: .getResource("http://www.hp.com/people/Ian_Dickinson");
101: assertTrue("Smush failed on iteration " + count, ian
102: .hasProperty(name));
103: }
104: }
105: }
106:
107: /*
108: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
109: All rights reserved.
110:
111: Redistribution and use in source and binary forms, with or without
112: modification, are permitted provided that the following conditions
113: are met:
114:
115: 1. Redistributions of source code must retain the above copyright
116: notice, this list of conditions and the following disclaimer.
117:
118: 2. Redistributions in binary form must reproduce the above copyright
119: notice, this list of conditions and the following disclaimer in the
120: documentation and/or other materials provided with the distribution.
121:
122: 3. The name of the author may not be used to endorse or promote products
123: derived from this software without specific prior written permission.
124:
125: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
126: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
128: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
129: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
130: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
134: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135: */
|