KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > test > TestResourceFactory


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestResourceFactory.java,v 1.6 2005/02/21 12:15:17 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model.test;
8
9 import com.hp.hpl.jena.rdf.model.*;
10 import junit.framework.*;
11
12 public class TestResourceFactory extends TestCase {
13     
14     static final String JavaDoc uri1 = "http://example.org/example#a1";
15     static final String JavaDoc uri2 = "http://example.org/example#a2";
16     
17     public static TestSuite suite() {
18         return new TestSuite(TestResourceFactory.class);
19     }
20
21     public TestResourceFactory(String JavaDoc name) {
22         super(name);
23     }
24
25     public void testCreateResource() {
26         Resource r1 = ResourceFactory.createResource();
27         assertTrue(r1.isAnon());
28         Resource r2 = ResourceFactory.createResource();
29         assertTrue(r2.isAnon());
30         assertTrue(!r1.equals(r2));
31         
32         r1 = ResourceFactory.createResource(uri1);
33         assertTrue(r1.getURI().equals(uri1));
34     }
35
36     public void testCreateProperty() {
37         Property p1 = ResourceFactory.createProperty(uri1);
38         assertTrue(p1.getURI().equals(uri1));
39         Property p2 = ResourceFactory.createProperty(uri1, "2");
40         assertTrue(p2.getURI().equals(uri1+"2"));
41     }
42     
43     public void testCreateStatement() {
44         Resource s = ResourceFactory.createResource();
45         Property p = ResourceFactory.createProperty(uri2);
46         Resource o = ResourceFactory.createResource();
47         Statement stmt = ResourceFactory.createStatement(s, p, o);
48         assertTrue(stmt.getSubject().equals(s));
49         assertTrue(stmt.getPredicate().equals(p));
50         assertTrue(stmt.getObject().equals(o));
51     }
52
53     public void testGetInstance() {
54         ResourceFactory.Interface factory = ResourceFactory.getInstance();
55         Resource r1 = ResourceFactory.createResource();
56         assertTrue(r1.isAnon());
57         Resource r2 = ResourceFactory.createResource();
58         assertTrue(r2.isAnon());
59         assertTrue(!r1.equals(r2));
60     }
61
62     public void testSetInstance() {
63         Resource r = ResourceFactory.createResource();
64         ResourceFactory.Interface factory = new TestFactory(r);
65         ResourceFactory.setInstance(factory);
66         assertTrue(factory.equals(ResourceFactory.getInstance()));
67         assertTrue(ResourceFactory.createResource() == r);
68     }
69
70     class TestFactory implements ResourceFactory.Interface {
71
72         Resource resource;
73
74         TestFactory(Resource r) {
75             resource = r;
76         }
77
78         public Resource createResource() {
79             return resource;
80         }
81
82         public Resource createResource(String JavaDoc uriref) {
83             return null;
84         }
85         
86         public Literal createPlainLiteral( String JavaDoc string ) {
87             return null;
88         }
89
90         public Property createProperty(String JavaDoc uriref) {
91             return null;
92         }
93
94         public Property createProperty(String JavaDoc namespace, String JavaDoc localName) {
95             return null;
96         }
97
98         public Statement createStatement(
99             Resource subject,
100             Property predicate,
101             RDFNode object) {
102             return null;
103         }
104     }
105 }
106
107 /*
108     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
109     All rights reserved.
110
111     Redistribution and use in source and binary forms, with or without
112     modification, are permitted provided that the following conditions
113     are met:
114
115     1. Redistributions of source code must retain the above copyright
116        notice, this list of conditions and the following disclaimer.
117
118     2. Redistributions in binary form must reproduce the above copyright
119        notice, this list of conditions and the following disclaimer in the
120        documentation and/or other materials provided with the distribution.
121
122     3. The name of the author may not be used to endorse or promote products
123        derived from this software without specific prior written permission.
124
125     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
126     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
128     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
129     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
130     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
134     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135 */

136
Popular Tags