1 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 uri1 = "http://example.org/example#a1"; 15 static final String uri2 = "http://example.org/example#a2"; 16 17 public static TestSuite suite() { 18 return new TestSuite(TestResourceFactory.class); 19 } 20 21 public TestResourceFactory(String 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 uriref) { 83 return null; 84 } 85 86 public Literal createPlainLiteral( String string ) { 87 return null; 88 } 89 90 public Property createProperty(String uriref) { 91 return null; 92 } 93 94 public Property createProperty(String namespace, String 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 136 | Popular Tags |