/
EncodableNamespaceTests.java
115 lines (107 loc) · 4.25 KB
/
EncodableNamespaceTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/******************************************************************************
** Copyright (c) 2008-2010 Franz Inc.
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the Eclipse Public License v1.0
** which accompanies this distribution, and is available at
** http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package test;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryException;
import com.franz.agraph.repository.AGFormattedNamespace;
public class EncodableNamespaceTests extends AGAbstractTest {
@Test
@Category(TestSuites.Prepush.class)
public void encodableNamespaces_rfe10197() throws Exception {
String NS0 = "http://franz.com/ns0";
String FORMAT0 = "[a-z][0-9]-[a-f]{3}";
Assert.assertTrue("expected none", conn.listEncodableNamespaces().isEmpty());
conn.registerEncodableNamespace(NS0,FORMAT0);
List<AGFormattedNamespace> namespaces = conn.listEncodableNamespaces();
Assert.assertEquals("expected one", 1, namespaces.size());
AGFormattedNamespace ns = namespaces.get(0);
Assert.assertEquals("unexpected prefix", NS0, ns.getNamespace());
Assert.assertEquals("unexpected format", FORMAT0, ns.getFormat());
URI uri = vf.generateURI(NS0);
Assert.assertTrue("expected prefix "+NS0, uri.stringValue().startsWith(NS0));
Assert.assertFalse("expected uniqueness", uri.stringValue().equals(vf.generateURI(NS0).stringValue()));
String NS1 = "http://franz.com/ns1";
String NS2 = "http://franz.com/ns2";
String NS3 = "http://franz.com/ns3";
String NS4 = "urn:franz:";
conn.registerEncodableNamespace(NS1,"[0-1]{59}"); // 59's the max
conn.registerEncodableNamespace(NS2,"[0-9]{18}"); // 18's the max
try {
conn.registerEncodableNamespace(NS3,"[0-9]{19}"); // 19's too big
Assert.fail("expected exception for format too large.");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
conn.registerEncodableNamespace(NS4,"[a-z][0-9]-[a-f]{1,3}");
try {
vf.generateURI(NS4);
Assert.fail("expected exception for format not fixed size.");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
try {
uri = vf.generateURI(NS0);
conn.add(uri,uri,uri);
conn.registerEncodableNamespace(NS0,"[0-9]{10}");
Assert.fail("expected exception for attempting reregistration.");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
namespaces = new ArrayList<AGFormattedNamespace>();
for (int i=0; i<10000; i++) {
namespaces.add(new AGFormattedNamespace("urn:franz-"+i+":","[0-1]{3}"));
}
conn.registerEncodableNamespaces(namespaces);
Assert.assertEquals(10004, conn.listEncodableNamespaces().size());
for (int i=0;i<8;i++) {
vf.generateURI("urn:franz-1234:");
}
try {
System.out.println(vf.generateURI("urn:franz-1234:"));
Assert.fail("expected exception for no more available id's.");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
URI[] uris = vf.generateURIs("urn:franz-9999:", 5);
Assert.assertEquals("expected 5 URI's", 5, uris.length);
for (int i=0;i<uris.length;i++) {
//System.out.println(uris[i]);
}
uris = vf.generateURIs("urn:franz-9999:", 5);
Assert.assertEquals("expected 3 URI's", 3, uris.length);
for (int i=0;i<uris.length;i++) {
//System.out.println(uris[i]);
}
try {
uris = vf.generateURIs("urn:franz-9999:", 5);
Assert.fail("expected no URI's available");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
conn.unregisterEncodableNamespace(NS2);
Assert.assertEquals(10003, conn.listEncodableNamespaces().size());
try {
conn.unregisterEncodableNamespace(NS0);
Assert.fail("expected namespace in use exception");
} catch (RepositoryException e) {
// expected
//System.out.println(e.getLocalizedMessage());
}
Assert.assertEquals(10003, conn.listEncodableNamespaces().size());
}
}