001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionAddAndContains.java,v 1.9 2008/01/02 12:07:05 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import junit.framework.*;
010:
011: import com.hp.hpl.jena.rdf.model.*;
012: import com.hp.hpl.jena.regression.Regression.LitTestObj;
013: import com.hp.hpl.jena.vocabulary.RDF;
014:
015: public class NewRegressionAddAndContains extends NewRegressionBase {
016: public NewRegressionAddAndContains(String name) {
017: super (name);
018: }
019:
020: public static TestSuite suite() {
021: return new TestSuite(NewRegressionAddAndContains.class);
022: }
023:
024: protected Model getModel() {
025: return ModelFactory.createDefaultModel();
026: }
027:
028: protected Model m;
029: protected Resource S;
030: protected Property P;
031:
032: public void setUp() {
033: m = getModel();
034: S = m.createResource("http://nowhere.man/subject");
035: P = m.createProperty("http://nowhere.man/predicate");
036: }
037:
038: public void tearDown() {
039: m = null;
040: S = null;
041: P = null;
042: }
043:
044: public void testEmpty() {
045: assertFalse(m.containsLiteral(S, P, tvBoolean));
046: assertFalse(m.contains(S, P, m.createResource()));
047: assertFalse(m.containsLiteral(S, P, tvByte));
048: assertFalse(m.containsLiteral(S, P, tvShort));
049: assertFalse(m.containsLiteral(S, P, tvInt));
050: assertFalse(m.containsLiteral(S, P, tvLong));
051: assertFalse(m.containsLiteral(S, P, tvChar));
052: assertFalse(m.containsLiteral(S, P, tvFloat));
053: assertFalse(m.containsLiteral(S, P, tvDouble));
054: assertFalse(m.containsLiteral(S, P, new LitTestObj(12345)));
055: assertFalse(m.contains(S, P, "test string"));
056: assertFalse(m.contains(S, P, "test string", "en"));
057: }
058:
059: public void testAddContainsResource() {
060: Resource r = m.createResource();
061: m.add(S, P, r);
062: assertTrue(m.contains(S, P, r));
063: }
064:
065: public void testAddContainsBoolean() {
066: m.addLiteral(S, P, tvBoolean);
067: assertTrue(m.containsLiteral(S, P, tvBoolean));
068: }
069:
070: public void testAddContainsByte() {
071: m.addLiteral(S, P, tvByte);
072: assertTrue(m.containsLiteral(S, P, tvByte));
073: }
074:
075: public void testAddContainsShort() {
076: m.addLiteral(S, P, tvShort);
077: assertTrue(m.containsLiteral(S, P, tvShort));
078: }
079:
080: public void testAddContainsInt() {
081: m.addLiteral(S, P, tvInt);
082: assertTrue(m.containsLiteral(S, P, tvInt));
083: }
084:
085: public void testAddContainsLong() {
086: m.addLiteral(S, P, tvLong);
087: assertTrue(m.containsLiteral(S, P, tvLong));
088: }
089:
090: public void testAddContainsChar() {
091: m.addLiteral(S, P, tvChar);
092: assertTrue(m.containsLiteral(S, P, tvChar));
093: }
094:
095: public void testAddContainsFloat() {
096: m.addLiteral(S, P, tvFloat);
097: assertTrue(m.containsLiteral(S, P, tvFloat));
098: }
099:
100: public void testAddContainsDouble() {
101: m.addLiteral(S, P, tvDouble);
102: assertTrue(m.containsLiteral(S, P, tvDouble));
103: }
104:
105: public void testAddContainsObject() {
106: LitTestObj O = new LitTestObj(12345);
107: m.addLiteral(S, P, O);
108: assertTrue(m.containsLiteral(S, P, O));
109: }
110:
111: public void testAddContainsPlainString() {
112: m.add(S, P, "test string");
113: assertTrue(m.contains(S, P, "test string"));
114: assertFalse(m.contains(S, P, "test string", "en"));
115: }
116:
117: public void testAddContainsLanguagedString() {
118: m.add(S, P, "test string", "en");
119: assertFalse(m.contains(S, P, "test string"));
120: assertTrue(m.contains(S, P, "test string", "en"));
121: }
122:
123: public void testAddContainLiteralByStatement() {
124: Literal L = m.createTypedLiteral(210);
125: Statement s = m.createStatement(S, RDF.value, L);
126: assertTrue(m.add(s).contains(s));
127: assertTrue(m.contains(S, RDF.value));
128: }
129:
130: public void testAddDuplicateLeavesSizeSame() {
131: Statement s = m.createStatement(S, RDF.value, "something");
132: m.add(s);
133: long size = m.size();
134: m.add(s);
135: assertEquals(size, m.size());
136: }
137:
138: }
139:
140: /*
141: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
142: * All rights reserved.
143: *
144: * Redistribution and use in source and binary forms, with or without
145: * modification, are permitted provided that the following conditions
146: * are met:
147: * 1. Redistributions of source code must retain the above copyright
148: * notice, this list of conditions and the following disclaimer.
149: * 2. Redistributions in binary form must reproduce the above copyright
150: * notice, this list of conditions and the following disclaimer in the
151: * documentation and/or other materials provided with the distribution.
152: * 3. The name of the author may not be used to endorse or promote products
153: * derived from this software without specific prior written permission.
154: *
155: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
156: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
157: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
158: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
159: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
160: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
161: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
162: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
163: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
164: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
165: */
|