001: /*
002: * (c) Copyright 2000-2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: * [See end of file]
005: * $Id: URITests.java,v 1.16 2008/01/02 12:06:50 andy_seaborne Exp $
006: */
007:
008: package com.hp.hpl.jena.rdf.arp.test;
009:
010: import com.hp.hpl.jena.iri.*;
011:
012: import junit.framework.Test;
013: import junit.framework.TestCase;
014: import junit.framework.TestSuite;
015:
016: //import java.net.*;
017: /**
018: * @author jjc
019: *
020: */
021: public class URITests extends TestCase {
022: // TODO: not for 2.3 relative/absolute tests
023: static public Test suite() {
024: TestSuite suite = new TestSuite("URIs");
025: suite.addTest(new URITests("testNoDomain"));
026: suite.addTest(new URITests("testLong"));
027: suite.addTest(new URITests("testBadScheme"));
028: suite.addTest(new URITests("testJustScheme"));
029:
030: // TODO: not for 2.3. are these tests right?
031: // suite.addTest(new URITests("testBadHost"));
032: // suite.addTest(new URITests("testBadPort"));
033: // suite.addTest(new URITests("testBadUserHost"));
034: suite.addTest(new URITests("testHostPortNoSlashWithFragment"));
035: suite.addTest(new URITests("testHostNoSlashWithFragment"));
036:
037: suite.addTest(new URITests("testBadAuthority"));
038: suite.addTest(new URITests("testTwoHashes"));
039: suite.addTest(new URITests("testTwoHashes2"));
040: return suite;
041: }
042:
043: URITests(String s) {
044: super (s);
045: }
046:
047: static IRIFactory factory = IRIFactory.jenaImplementation();
048:
049: // static {
050: // factory.useSpecificationRDF(false);
051: // }
052: public void testURI(String uri, boolean ok) {
053: IRI ref = factory.create(uri);
054: if (ok && ref.hasViolation(false)) {
055: Violation v = (Violation) ref.violations(false).next();
056: fail("<" + uri + "> is expected to be a URI, but: "
057: + v.getLongMessage());
058: }
059: assertEquals("<" + uri + "> is" + (ok ? " " : " not ")
060: + "a URI", ok, !ref.hasViolation(false));
061:
062: }
063:
064: public void testNoDomain() {
065: testURI("app://calendar/event", true);
066: }
067:
068: public void testLong() {
069: testURI(
070: "http://46229EFFE16A9BD60B9F1BE88B2DB047ADDED785/demo.mp3",
071: true);
072: }
073:
074: public void testBadScheme() {
075: testURI("ht^tp://www.w3.org/demo.mp3", false);
076: }
077:
078: public void testFragmentLooksLikeScheme() {
079: testURI("ht#tp://www.w3.org/demo.mp3", true);
080: }
081:
082: public void testHostNoSlashWithFragment() {
083: testURI("http://www.w#3.org/demo.mp3", true);
084: }
085:
086: public void testHostPortNoSlashWithFragment() {
087: testURI("http://www.w3.org:1#4/demo.mp3", true);
088: }
089:
090: public void testBadHost() {
091: testURI("http://www.w+3.org/demo.mp3", false);
092: }
093:
094: // TODO: not for 2.3. Is this test correct?
095: public void testJustScheme() {
096: testURI("http:", false);
097: }
098:
099: public void testBadPort() {
100: testURI("http://www.w3.org:1+4/demo.mp3", false);
101: }
102:
103: public void testBadUserHost() {
104: testURI("http://jjc@www.w@3.org/demo.mp3", false);
105: }
106:
107: public void testBadAuthority() {
108: testURI("http://jjc^3.org/demo.mp3", false);
109: }
110:
111: public void testTwoHashes() {
112: testURI("ht#tp://jjc3.org/demo.mp3#frag", false);
113:
114: }
115:
116: public void testTwoHashes2() {
117: testURI("http://jjc#3.org/demo.mp3#frag", false);
118:
119: }
120: }
121:
122: /*
123: (c) Copyright 2000-2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
124: All rights reserved.
125:
126: Redistribution and use in source and binary forms, with or without
127: modification, are permitted provided that the following conditions
128: are met:
129:
130: 1. Redistributions of source code must retain the above copyright
131: notice, this list of conditions and the following disclaimer.
132:
133: 2. Redistributions in binary form must reproduce the above copyright
134: notice, this list of conditions and the following disclaimer in the
135: documentation and/or other materials provided with the distribution.
136:
137: 3. The name of the author may not be used to endorse or promote products
138: derived from this software without specific prior written permission.
139:
140: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
141: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
142: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
143: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
144: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
145: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
149: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150: */
|