001: /*
002: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: * [See end of file]
005: */
006:
007: package com.hp.hpl.jena.util.junit;
008:
009: import com.hp.hpl.jena.rdf.model.Literal;
010: import com.hp.hpl.jena.rdf.model.Property;
011: import com.hp.hpl.jena.rdf.model.RDFNode;
012: import com.hp.hpl.jena.rdf.model.Resource;
013:
014: /** com.hp.hpl.jena.query.test.TestUtils
015: *
016: * @author Andy Seaborne
017: * @version $Id: TestUtils.java,v 1.2 2008/01/02 12:11:12 andy_seaborne Exp $
018: */
019:
020: public class TestUtils {
021: public static Resource getResource(Resource r, Property p) {
022: if (r == null)
023: return null;
024: if (!r.hasProperty(p))
025: return null;
026:
027: RDFNode n = r.getProperty(p).getObject();
028: if (n instanceof Resource)
029: return (Resource) n;
030:
031: throw new TestException("Manifest problem (not a Resource): "
032: + n + " => " + p);
033: }
034:
035: public static String getLiteral(Resource r, Property p) {
036: if (r == null)
037: return null;
038: if (!r.hasProperty(p))
039: return null;
040:
041: RDFNode n = r.getProperty(p).getObject();
042: if (n instanceof Literal)
043: return ((Literal) n).getLexicalForm();
044:
045: throw new TestException("Manifest problem (not a Literal): "
046: + n + " => " + p);
047: }
048:
049: public static String getLiteralOrURI(Resource r, Property p) {
050: if (r == null)
051: return null;
052:
053: if (!r.hasProperty(p))
054: return null;
055:
056: RDFNode n = r.getProperty(p).getObject();
057: if (n instanceof Literal)
058: return ((Literal) n).getLexicalForm();
059:
060: if (n instanceof Resource) {
061: Resource r2 = (Resource) n;
062: if (!r2.isAnon())
063: return r2.getURI();
064: }
065:
066: throw new TestException("Manifest problem: " + n + " => " + p);
067: }
068:
069: public static String safeName(String s) {
070: // Safe from Eclipse
071: s = s.replace('(', '[');
072: s = s.replace(')', ']');
073: return s;
074:
075: }
076: }
077:
078: /*
079: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
080: * All rights reserved.
081: *
082: * Redistribution and use in source and binary forms, with or without
083: * modification, are permitted provided that the following conditions
084: * are met:
085: * 1. Redistributions of source code must retain the above copyright
086: * notice, this list of conditions and the following disclaimer.
087: * 2. Redistributions in binary form must reproduce the above copyright
088: * notice, this list of conditions and the following disclaimer in the
089: * documentation and/or other materials provided with the distribution.
090: * 3. The name of the author may not be used to endorse or promote products
091: * derived from this software without specific prior written permission.
092: *
093: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
094: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
095: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
096: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
097: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
098: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
099: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103: */
|