001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: TestResourceImpl.java,v 1.13 2008/01/02 12:04:41 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.test;
008:
009: import com.hp.hpl.jena.rdf.model.*;
010: import com.hp.hpl.jena.vocabulary.RDF;
011:
012: import junit.framework.*;
013:
014: /**
015: TestResourceImpl - fresh tests, make sure as-ing works a bit.
016:
017: @author kers
018: */
019: public class TestResourceImpl extends ModelTestBase {
020: public TestResourceImpl(String name) {
021: super (name);
022: }
023:
024: public static TestSuite suite() {
025: return new TestSuite(TestResourceImpl.class);
026: }
027:
028: /**
029: Test that a non-literal node can be as'ed into a resource
030: */
031: public void testCannotAsNonLiteral() {
032: Model m = ModelFactory.createDefaultModel();
033: resource(m, "plumPie").as(Resource.class);
034: }
035:
036: /**
037: Test that a literal node cannot be as'ed into a resource.
038: */
039: public void testAsLiteral() {
040: Model m = ModelFactory.createDefaultModel();
041: try {
042: literal(m, "17").as(Resource.class);
043: fail("literals cannot be resources");
044: } catch (ResourceRequiredException e) {
045: pass();
046: }
047: }
048:
049: public void testNameSpace() {
050: assertEquals("eh:x", resource("eh:xyz").getNameSpace());
051: assertEquals("http://d/", resource("http://d/stuff")
052: .getNameSpace());
053: assertEquals("ftp://dd.com/12345", resource(
054: "ftp://dd.com/12345").getNameSpace());
055: assertEquals("http://domain/spoo#", resource(
056: "http://domain/spoo#anchor").getNameSpace());
057: assertEquals("ftp://abd/def#ghi#", resource(
058: "ftp://abd/def#ghi#e11-2").getNameSpace());
059: }
060:
061: public void testLocalName() {
062: assertEquals("yz", resource("eh:xyz").getLocalName());
063: }
064:
065: public void testHasURI() {
066: assertTrue(resource("eh:xyz").hasURI("eh:xyz"));
067: assertFalse(resource("eh:xyz").hasURI("eh:1yz"));
068: assertFalse(ResourceFactory.createResource().hasURI("42"));
069: }
070:
071: public void testAddTypedPropertyDouble() {
072: Model m = ModelFactory.createDefaultModel();
073: Resource r = m.createResource();
074: r.addLiteral(RDF.value, 1.0d);
075: assertEquals(m.createTypedLiteral(1.0d), r.getProperty(
076: RDF.value).getLiteral());
077: }
078:
079: public void testAddTypedPropertyFloat() {
080: Model m = ModelFactory.createDefaultModel();
081: Resource r = m.createResource();
082: r.addLiteral(RDF.value, 1.0f);
083: assertEquals(m.createTypedLiteral(1.0f), r.getProperty(
084: RDF.value).getLiteral());
085: }
086:
087: public void testHasTypedPropertyDouble() {
088: Model m = ModelFactory.createDefaultModel();
089: Resource r = m.createResource();
090: r.addLiteral(RDF.value, 1.0d);
091: assertTrue(r.hasLiteral(RDF.value, 1.0d));
092: }
093:
094: public void testHasTypedPropertyFloat() {
095: Model m = ModelFactory.createDefaultModel();
096: Resource r = m.createResource();
097: r.addLiteral(RDF.value, 1.0f);
098: assertTrue(r.hasLiteral(RDF.value, 1.0f));
099: }
100:
101: public void testAddTypedPropertyLong() {
102: Model m = ModelFactory.createDefaultModel();
103: Resource r = m.createResource();
104: r.addLiteral(RDF.value, 1L);
105: assertEquals(m.createTypedLiteral(1L), r.getProperty(RDF.value)
106: .getLiteral());
107: }
108:
109: public void testHasTypedPropertyLong() {
110: Model m = ModelFactory.createDefaultModel();
111: Resource r = m.createResource();
112: r.addLiteral(RDF.value, 1L);
113: assertTrue(r.hasLiteral(RDF.value, 1L));
114: }
115:
116: public void testAddTypedPropertyInt() {
117:
118: }
119:
120: public void testHasTypedPropertyInt() {
121:
122: }
123:
124: public void testAddTypedPropertyChar() {
125: Model m = ModelFactory.createDefaultModel();
126: Resource r = m.createResource();
127: r.addLiteral(RDF.value, 'x');
128: assertEquals(m.createTypedLiteral('x'), r
129: .getProperty(RDF.value).getLiteral());
130: }
131:
132: public void testHasTypedPropertyChar() {
133: Model m = ModelFactory.createDefaultModel();
134: Resource r = m.createResource();
135: r.addLiteral(RDF.value, 'x');
136: assertTrue(r.hasLiteral(RDF.value, 'x'));
137: }
138:
139: public void testAddTypedPropertyBoolean() {
140: Model m = ModelFactory.createDefaultModel();
141: Resource r = m.createResource();
142: r.addLiteral(RDF.value, true);
143: assertEquals(m.createTypedLiteral(true), r.getProperty(
144: RDF.value).getLiteral());
145: }
146:
147: public void testHasTypedPropertyBoolean() {
148: Model m = ModelFactory.createDefaultModel();
149: Resource r = m.createResource();
150: r.addLiteral(RDF.value, false);
151: assertTrue(r.hasLiteral(RDF.value, false));
152: }
153:
154: public void testAddTypedPropertyString() {
155:
156: }
157:
158: public void testHasTypedPropertyString() {
159:
160: }
161:
162: public void testAddTypedPropertyObject() {
163: Object z = new Object();
164: Model m = ModelFactory.createDefaultModel();
165: Resource r = m.createResource();
166: r.addLiteral(RDF.value, z);
167: assertEquals(m.createTypedLiteral(z), r.getProperty(RDF.value)
168: .getLiteral());
169: }
170:
171: public void testHasTypedPropertyObject() {
172: Object z = new Object();
173: Model m = ModelFactory.createDefaultModel();
174: Resource r = m.createResource();
175: r.addLiteral(RDF.value, z);
176: assertTrue(r.hasLiteral(RDF.value, z));
177: }
178:
179: }
180:
181: /*
182: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
183: All rights reserved.
184:
185: Redistribution and use in source and binary forms, with or without
186: modification, are permitted provided that the following conditions
187: are met:
188:
189: 1. Redistributions of source code must retain the above copyright
190: notice, this list of conditions and the following disclaimer.
191:
192: 2. Redistributions in binary form must reproduce the above copyright
193: notice, this list of conditions and the following disclaimer in the
194: documentation and/or other materials provided with the distribution.
195:
196: 3. The name of the author may not be used to endorse or promote products
197: derived from this software without specific prior written permission.
198:
199: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
200: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
202: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
203: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
204: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
205: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
206: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
207: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
208: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
209: */
|