001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionResourceMethods.java,v 1.9 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import com.hp.hpl.jena.rdf.model.*;
010: import com.hp.hpl.jena.shared.PropertyNotFoundException;
011: import com.hp.hpl.jena.vocabulary.RDF;
012:
013: import junit.framework.*;
014:
015: public class NewRegressionResourceMethods extends NewRegressionBase {
016: public NewRegressionResourceMethods(String name) {
017: super (name);
018: }
019:
020: public static Test suite() {
021: return new TestSuite(NewRegressionResourceMethods.class);
022: }
023:
024: protected Model getModel() {
025: return ModelFactory.createDefaultModel();
026: }
027:
028: protected Model m;
029:
030: protected Resource r;
031:
032: protected final String lang = "en";
033:
034: protected Literal tvLiteral;
035:
036: protected Resource tvResource;
037:
038: public void setUp() {
039: m = getModel();
040: tvLiteral = m.createLiteral("test 12 string 2");
041: tvResource = m.createResource();
042: r = m.createResource().addLiteral(RDF.value, tvBoolean)
043: .addLiteral(RDF.value, tvByte).addLiteral(RDF.value,
044: tvShort).addLiteral(RDF.value, tvInt)
045: .addLiteral(RDF.value, tvLong).addLiteral(RDF.value,
046: tvChar).addLiteral(RDF.value, tvFloat)
047: .addLiteral(RDF.value, tvDouble).addProperty(RDF.value,
048: tvString)
049: .addProperty(RDF.value, tvString, lang).addLiteral(
050: RDF.value, tvObject).addProperty(RDF.value,
051: tvLiteral).addProperty(RDF.value, tvResource);
052: }
053:
054: public void testBoolean() {
055: assertTrue(r.hasLiteral(RDF.value, tvBoolean));
056: }
057:
058: public void testByte() {
059: assertTrue(r.hasLiteral(RDF.value, tvByte));
060: }
061:
062: public void testShort() {
063: assertTrue(r.hasLiteral(RDF.value, tvShort));
064: }
065:
066: public void testInt() {
067: assertTrue(r.hasLiteral(RDF.value, tvInt));
068: }
069:
070: public void testLong() {
071: assertTrue(r.hasLiteral(RDF.value, tvLong));
072: }
073:
074: public void testChar() {
075: assertTrue(r.hasLiteral(RDF.value, tvChar));
076: }
077:
078: public void testFloat() {
079: assertTrue(r.hasLiteral(RDF.value, tvFloat));
080: }
081:
082: public void testDouble() {
083: assertTrue(r.hasLiteral(RDF.value, tvDouble));
084: }
085:
086: public void testString() {
087: assertTrue(r.hasProperty(RDF.value, tvString));
088: }
089:
090: public void testStringWithLanguage() {
091: assertTrue(r.hasProperty(RDF.value, tvString, lang));
092: }
093:
094: public void testObject() {
095: assertTrue(r.hasLiteral(RDF.value, tvObject));
096: }
097:
098: public void testLiteral() {
099: assertTrue(r.hasProperty(RDF.value, tvLiteral));
100: }
101:
102: public void testResource() {
103: assertTrue(r.hasProperty(RDF.value, tvResource));
104: }
105:
106: public void testCorrectSubject() {
107: assertEquals(r, r.getRequiredProperty(RDF.value).getSubject());
108: }
109:
110: public void testNoSuchPropertyException() {
111: try {
112: r.getRequiredProperty(RDF.type);
113: fail("missing property should throw exception");
114: } catch (PropertyNotFoundException e) {
115: pass();
116: }
117: }
118:
119: public void testNoSuchPropertyNull() {
120: assertNull(r.getProperty(RDF.type));
121: }
122:
123: public void testAllSubjectsCorrect() {
124: testHasSubjectR(m.listStatements());
125: testHasSubjectR(r.listProperties());
126: }
127:
128: protected void testHasSubjectR(StmtIterator it) {
129: while (it.hasNext())
130: assertEquals(r, it.nextStatement().getSubject());
131: }
132:
133: public void testCountsCorrect() {
134: assertEquals(13, iteratorToList(m.listStatements()).size());
135: assertEquals(13, iteratorToList(r.listProperties(RDF.value))
136: .size());
137: assertEquals(0, iteratorToList(r.listProperties(RDF.type))
138: .size());
139: }
140:
141: public void testRemoveProperties() {
142: r.removeProperties();
143: assertEquals(false, m.listStatements(r, null, (RDFNode) null)
144: .hasNext());
145: }
146: }
147:
148: /*
149: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
150: * All rights reserved.
151: *
152: * Redistribution and use in source and binary forms, with or without
153: * modification, are permitted provided that the following conditions
154: * are met:
155: * 1. Redistributions of source code must retain the above copyright
156: * notice, this list of conditions and the following disclaimer.
157: * 2. Redistributions in binary form must reproduce the above copyright
158: * notice, this list of conditions and the following disclaimer in the
159: * documentation and/or other materials provided with the distribution.
160: * 3. The name of the author may not be used to endorse or promote products
161: * derived from this software without specific prior written permission.
162: *
163: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
164: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
165: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
166: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
167: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
168: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
169: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
170: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
171: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
172: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
173: */
|