blob: eecf3ee5b23e28d2e0da1ef747152721c0345e10 (
plain) (
blame)
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
116
117
118
119
120
121
122
|
/*******************************************************************************
* Copyright (c) 2010 Oracle. 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
*
* Contributors:
* Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jaxb.core.tests.internal;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Vector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.eclipse.jpt.jaxb.core.xsd.XsdSchema;
public class SchemaLibraryTests
extends JaxbTestCase {
public SchemaLibraryTests(String name) {
super(name);
}
// tests schema for namespace that is set in catalog, but not in project properties
public void testUnsetNamespace() {
String namespace = "http://www.w3.org/2001/XInclude";
// test initial load
XsdSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test cached load
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test unload/reload
schema.getXSDComponent().eResource().unload();
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
}
// tests schema for registered uri that is set in project properties (namespace not registered in catalog)
public void testSetRegisteredUriUnregisteredNamespace() {
String namespace = "http://java.sun.com/xml/ns/persistence/orm";
// set namespace in project properties\
List<String> schemaLocations = new Vector<String>();
schemaLocations.add("http://java.sun.com/xml/ns/persistence/orm_2_0.xsd");
getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations);
// test initial load
XsdSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test cached load
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test unload/reload
schema.getXSDComponent().eResource().unload();
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
}
// tests schema for registerd uri that is set in project properties (namespace already registered in catalog)
public void testSetRegisteredUriRegisteredNamespace() {
String namespace = "http://www.eclipse.org/eclipselink/xsds/persistence/orm";
// set namespace in project properties\
List<String> schemaLocations = new Vector<String>();
schemaLocations.add("http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_1_0.xsd");
getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations);
// test initial load
XsdSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test cached load
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test unload/reload
schema.getXSDComponent().eResource().unload();
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
}
// tests schema for unregistered uri that is set in project properties (local file)
public void testSetUnregisterdUri() throws Exception {
IFile schemaFile = getJaxbProject().getProject().getFile(new Path("customer.xsd"));
String contents =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""
+ " targetNamespace=\"http://www.example.org/customer-example\">"
+ "</xs:schema>";
schemaFile.create(new ByteArrayInputStream(contents.getBytes()), true, null);
String namespace = "http://www.example.org/customer-example";
// set namespace in project properties\
List<String> schemaLocations = new Vector<String>();
schemaLocations.add("platform:/resource/" + BASE_PROJECT_NAME + "/customer.xsd");
getJaxbProject().getSchemaLibrary().setSchemaLocations(schemaLocations);
// test initial load
XsdSchema schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test cached load
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
// test unload/reload
schema.getXSDComponent().eResource().unload();
schema = getJaxbProject().getSchemaLibrary().getSchema(namespace);
assertNotNull(schema);
}
}
|