001: /*
002: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved - see end of file.
004: $Id: NewRegressionStatements.java,v 1.8 2008/01/02 12:07:04 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.regression;
008:
009: import junit.framework.*;
010:
011: import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
012: import com.hp.hpl.jena.rdf.model.*;
013: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
014: import com.hp.hpl.jena.regression.Regression.*;
015:
016: public class NewRegressionStatements extends ModelTestBase {
017: public NewRegressionStatements(String name) {
018: super (name);
019: }
020:
021: public static TestSuite suite() {
022: return new TestSuite(NewRegressionStatements.class);
023: }
024:
025: protected Model getModel() {
026: return ModelFactory.createDefaultModel();
027: }
028:
029: static final String subjURI = "http://aldabaran.hpl.hp.com/foo";
030: static final String predURI = "http://aldabaran.hpl.hp.com/bar";
031:
032: protected Resource r;
033: protected Property p;
034:
035: protected Model m;
036:
037: public void setUp() {
038: m = getModel();
039: r = m.createResource(subjURI);
040: p = m.createProperty(predURI);
041: }
042:
043: public void tearDown() {
044: m = null;
045: r = null;
046: p = null;
047: }
048:
049: public void testCreateStatementTrue() {
050: Statement s = m.createLiteralStatement(r, p, true);
051: assertEquals(r, s.getSubject());
052: assertEquals(p, s.getPredicate());
053: assertEquals(true, s.getBoolean());
054: }
055:
056: public void testCreateStatementByteMax() {
057: Statement s = m.createLiteralStatement(r, p, Byte.MAX_VALUE);
058: assertEquals(r, s.getSubject());
059: assertEquals(p, s.getPredicate());
060: assertEquals(Byte.MAX_VALUE, s.getByte());
061: }
062:
063: public void testCreateStatementShortMax() {
064: Statement s = m.createLiteralStatement(r, p, Short.MAX_VALUE);
065: assertEquals(r, s.getSubject());
066: assertEquals(p, s.getPredicate());
067: assertEquals(Short.MAX_VALUE, s.getShort());
068: }
069:
070: public void testCreateStatementIntMax() {
071: Statement s = m.createLiteralStatement(r, p, Integer.MAX_VALUE);
072: assertEquals(r, s.getSubject());
073: assertEquals(p, s.getPredicate());
074: assertEquals(Integer.MAX_VALUE, s.getInt());
075: }
076:
077: public void testCreateStatementLongMax() {
078: Statement s = m.createLiteralStatement(r, p, Long.MAX_VALUE);
079: assertEquals(r, s.getSubject());
080: assertEquals(p, s.getPredicate());
081: assertEquals(Long.MAX_VALUE, s.getLong());
082: }
083:
084: public void testCreateStatementChar() {
085: Statement s = m.createLiteralStatement(r, p, '$');
086: assertEquals(r, s.getSubject());
087: assertEquals(p, s.getPredicate());
088: assertEquals('$', s.getChar());
089: }
090:
091: public void testCreateStatementFloat() {
092: Statement s = m.createStatement(r, p, m
093: .createTypedLiteral(123.456f));
094: assertEquals(r, s.getSubject());
095: assertEquals(p, s.getPredicate());
096: assertEquals(123.456f, s.getFloat(), 0.0005);
097: }
098:
099: public void testCreateStatementDouble() {
100: Statement s = m.createStatement(r, p, m
101: .createTypedLiteral(12345.67890d));
102: assertEquals(r, s.getSubject());
103: assertEquals(p, s.getPredicate());
104: assertEquals(12345.67890d, s.getDouble(), 0.0000005);
105: }
106:
107: public void testCreateStatementString() {
108: String string = "this is a plain string", lang = "en";
109: Statement s = m.createStatement(r, p, string);
110: assertEquals(r, s.getSubject());
111: assertEquals(p, s.getPredicate());
112: assertEquals(string, s.getString());
113: assertEquals(lang, m.createStatement(r, p, string, lang)
114: .getLanguage());
115: }
116:
117: public void testCreateStatementTypeLiteral() {
118: Model m = ModelFactory.createDefaultModel();
119: Resource R = m.createResource("http://example/r");
120: Property P = m.createProperty("http://example/p");
121: m.add(R, P, "2", XSDDatatype.XSDinteger);
122: Literal L = ResourceFactory.createTypedLiteral("2",
123: XSDDatatype.XSDinteger);
124: assertTrue(m.contains(R, P, L));
125: assertFalse(m.contains(R, P, "2"));
126: }
127:
128: public void testCreateStatementFactory() {
129: LitTestObj tv = new LitTestObj(Long.MIN_VALUE);
130: Statement s = m.createLiteralStatement(r, p, tv);
131: assertEquals(r, s.getSubject());
132: assertEquals(p, s.getPredicate());
133: assertEquals(tv, s.getObject(new LitTestObjF()));
134: }
135:
136: public void testCreateStatementResource() {
137: Resource tv = m.createResource();
138: Statement s = m.createStatement(r, p, tv);
139: assertEquals(r, s.getSubject());
140: assertEquals(p, s.getPredicate());
141: assertEquals(tv, s.getResource());
142: }
143: }
144:
145: /*
146: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
147: * All rights reserved.
148: *
149: * Redistribution and use in source and binary forms, with or without
150: * modification, are permitted provided that the following conditions
151: * are met:
152: * 1. Redistributions of source code must retain the above copyright
153: * notice, this list of conditions and the following disclaimer.
154: * 2. Redistributions in binary form must reproduce the above copyright
155: * notice, this list of conditions and the following disclaimer in the
156: * documentation and/or other materials provided with the distribution.
157: * 3. The name of the author may not be used to endorse or promote products
158: * derived from this software without specific prior written permission.
159: *
160: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
162: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
163: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
164: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
165: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
166: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
167: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
168: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
169: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170: */
|