KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: TestResourceImpl.java,v 1.5 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
11 import junit.framework.*;
12
13 /**
14     TestResourceImpl - fresh tests, make sure as-ing works a bit.
15
16     @author kers
17 */

18 public class TestResourceImpl extends ModelTestBase
19     {
20     public TestResourceImpl( String JavaDoc name )
21         { super(name); }
22
23     public static TestSuite suite()
24         { return new TestSuite( TestResourceImpl.class ); }
25
26     /**
27         Test that a non-literal node can be as'ed into a resource
28     */

29     public void testCannotAsNonLiteral()
30         { Model m = ModelFactory.createDefaultModel();
31         resource( m, "plumPie" ).as( Resource.class ); }
32     
33     /**
34         Test that a literal node cannot be as'ed into a resource.
35     */

36     public void testAsLiteral()
37         { Model m = ModelFactory.createDefaultModel();
38         try
39             { literal( m, "17" ).as( Resource.class );
40             fail( "literals cannot be resources"); }
41         catch (ResourceRequiredException e)
42             { pass(); }}
43     
44     public void testNameSpace()
45         {
46         assertEquals( "eh:x", resource( "eh:xyz" ).getNameSpace() );
47         assertEquals( "http://d/", resource( "http://d/stuff" ).getNameSpace() );
48         assertEquals( "ftp://dd.com/12345", resource( "ftp://dd.com/12345" ).getNameSpace() );
49         assertEquals( "http://domain/spoo#", resource( "http://domain/spoo#anchor" ).getNameSpace() );
50         assertEquals( "ftp://abd/def#ghi#", resource( "ftp://abd/def#ghi#e11-2" ).getNameSpace() );
51         }
52     
53     public void testLocalName()
54         {
55         assertEquals( "yz", resource( "eh:xyz" ).getLocalName() );
56         }
57     
58     public void testHasURI()
59         {
60         assertTrue( resource( "eh:xyz" ).hasURI( "eh:xyz" ) );
61         assertFalse( resource( "eh:xyz" ).hasURI( "eh:1yz" ) );
62         assertFalse( ResourceFactory.createResource().hasURI( "42" ) );
63         }
64     
65     }
66
67
68 /*
69     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
70     All rights reserved.
71
72     Redistribution and use in source and binary forms, with or without
73     modification, are permitted provided that the following conditions
74     are met:
75
76     1. Redistributions of source code must retain the above copyright
77        notice, this list of conditions and the following disclaimer.
78
79     2. Redistributions in binary form must reproduce the above copyright
80        notice, this list of conditions and the following disclaimer in the
81        documentation and/or other materials provided with the distribution.
82
83     3. The name of the author may not be used to endorse or promote products
84        derived from this software without specific prior written permission.
85
86     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
87     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
88     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
89     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
90     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
91     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
92     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
93     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
94     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
95     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96 */
Popular Tags