01: /******************************************************************
02: * File: TestPrintUtil.java
03: * Created by: Dave Reynolds
04: * Created on: 16-Aug-2006
05: *
06: * (c) Copyright 2006, Hewlett-Packard Development Company, LP
07: * [See end of file]
08: * $Id: TestPrintUtil.java,v 1.3 2008/01/02 12:08:35 andy_seaborne Exp $
09: *****************************************************************/package com.hp.hpl.jena.util.test;
10:
11: import java.util.HashMap;
12: import java.util.Map;
13:
14: import junit.framework.TestCase;
15: import junit.framework.TestSuite;
16:
17: import com.hp.hpl.jena.rdf.model.Resource;
18: import com.hp.hpl.jena.rdf.model.ResourceFactory;
19: import com.hp.hpl.jena.util.PrintUtil;
20:
21: public class TestPrintUtil extends TestCase {
22:
23: public TestPrintUtil(String name) {
24: super (name);
25: }
26:
27: public static TestSuite suite() {
28: return new TestSuite(TestPrintUtil.class);
29: }
30:
31: // Minimal test of formating a URI with prefixes
32: public void testPrefixUse() {
33: String NS = "http://jena.hpl.hp.com/example#";
34: String name = "r1";
35: String uri = NS + name;
36: String shortform = "p:" + name;
37: Resource r = ResourceFactory.createResource(uri);
38: assertEquals(uri, PrintUtil.print(r));
39:
40: PrintUtil.registerPrefix("p", NS);
41: assertEquals(shortform, PrintUtil.print(r));
42:
43: PrintUtil.removePrefix("p");
44: assertEquals(uri, PrintUtil.print(r));
45:
46: Map map = new HashMap();
47: map.put("p", NS);
48: PrintUtil.registerPrefixMap(map);
49: assertEquals(shortform, PrintUtil.print(r));
50:
51: PrintUtil.removePrefixMap(map);
52: assertEquals(uri, PrintUtil.print(r));
53: }
54: }
55:
56: /*
57: (c) Copyright 2006, 2007, 2008 Hewlett-Packard Development Company, LP
58: All rights reserved.
59:
60: Redistribution and use in source and binary forms, with or without
61: modification, are permitted provided that the following conditions
62: are met:
63:
64: 1. Redistributions of source code must retain the above copyright
65: notice, this list of conditions and the following disclaimer.
66:
67: 2. Redistributions in binary form must reproduce the above copyright
68: notice, this list of conditions and the following disclaimer in the
69: documentation and/or other materials provided with the distribution.
70:
71: 3. The name of the author may not be used to endorse or promote products
72: derived from this software without specific prior written permission.
73:
74: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|