1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2010 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: tao $'
|
7
|
* '$Date: 2016-09-02 17:58:12 -0900 $'
|
8
|
* '$Revision: 5211 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
package edu.ucsb.nceas.metacattest;
|
25
|
|
26
|
import java.io.ByteArrayInputStream;
|
27
|
import java.io.File;
|
28
|
import java.io.InputStream;
|
29
|
import java.io.StringReader;
|
30
|
|
31
|
import junit.framework.Test;
|
32
|
import junit.framework.TestSuite;
|
33
|
|
34
|
import org.xml.sax.*;
|
35
|
|
36
|
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
|
37
|
import edu.ucsb.nceas.MCTestCase;
|
38
|
import edu.ucsb.nceas.metacat.AccessionNumber;
|
39
|
import edu.ucsb.nceas.metacat.AccessionNumberException;
|
40
|
import edu.ucsb.nceas.metacat.IdentifierManager;
|
41
|
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
|
42
|
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
|
43
|
import edu.ucsb.nceas.metacat.client.MetacatException;
|
44
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
45
|
import edu.ucsb.nceas.metacat.dataone.CNodeService;
|
46
|
import edu.ucsb.nceas.metacat.dataone.MNodeService;
|
47
|
|
48
|
import org.apache.commons.io.FileUtils;
|
49
|
import org.dataone.service.types.v1.Identifier;
|
50
|
import org.dataone.service.types.v1.ObjectFormatIdentifier;
|
51
|
import org.dataone.service.types.v1.Session;
|
52
|
import org.dataone.service.types.v2.SystemMetadata;
|
53
|
|
54
|
|
55
|
/**
|
56
|
* This test tests some scenarios during Metacat inserting:
|
57
|
* dtd, schema with namespace, schema without namespace and no-dtd/schema.
|
58
|
* @author tao
|
59
|
*
|
60
|
*/
|
61
|
public class MetacatValidationAlgorithmTest extends D1NodeServiceTest {
|
62
|
|
63
|
private static final String UNREGISTERED_SCHEMA_XML_INSTANCE="<?xml version=\"1.0\"?> "+
|
64
|
"<note:note xmlns:note=\"http://www.w3schools.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3schools.com https://www.loc.gov/ead/ead.xsd\"> "+
|
65
|
"<to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note:note>";
|
66
|
|
67
|
private static final String UNREGISTERED_NONAMESPACE_SCHEMA_XML_INSTANCE = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?> "+
|
68
|
"<metadata xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.fgdc.gov/metadata/foo.xsd\">"+
|
69
|
"<idinfo><citation><citeinfo><origin>National Center for Earth Surface Dynamics</origin><pubdate>20160811</pubdate><title>Shuttle Radar Topography Mission (SRTM)</title>"+
|
70
|
"<onlink>http://doi.org/10.5967/M09W0CGK</onlink></citeinfo></citation></idinfo></metadata>";
|
71
|
public MetacatValidationAlgorithmTest (String name) {
|
72
|
super(name);
|
73
|
}
|
74
|
|
75
|
/**
|
76
|
* Create a suite of tests to be run together
|
77
|
*/
|
78
|
public static Test suite() {
|
79
|
TestSuite suite = new TestSuite();
|
80
|
// Test basic functions
|
81
|
suite.addTest(new MetacatValidationAlgorithmTest("testRegisteredDTDDucoment"));
|
82
|
suite.addTest(new MetacatValidationAlgorithmTest("testRegisteredDTDInvalidDucoment"));
|
83
|
suite.addTest(new MetacatValidationAlgorithmTest("testUnRegisteredDTDDucoment"));
|
84
|
suite.addTest(new MetacatValidationAlgorithmTest("testValidationUnneededDucoment"));
|
85
|
suite.addTest(new MetacatValidationAlgorithmTest("testUnregisteredNamespaceSchema"));
|
86
|
suite.addTest(new MetacatValidationAlgorithmTest("testEML201"));
|
87
|
suite.addTest(new MetacatValidationAlgorithmTest("testEML211"));
|
88
|
suite.addTest(new MetacatValidationAlgorithmTest("testRegisteredNamespaceOrFormatIdSchema"));
|
89
|
suite.addTest(new MetacatValidationAlgorithmTest("testUnregisteredNoNamespaceSchema"));
|
90
|
suite.addTest(new MetacatValidationAlgorithmTest("testRegisteredNoNamespaceSchema"));
|
91
|
return suite;
|
92
|
}
|
93
|
/**
|
94
|
* Initialize the connection to metacat, and insert a document to be
|
95
|
* used for testing with a known docid.
|
96
|
*/
|
97
|
public void setUp() throws Exception{
|
98
|
metacatConnectionNeeded = true;
|
99
|
super.setUp();
|
100
|
|
101
|
|
102
|
}
|
103
|
|
104
|
|
105
|
|
106
|
/**
|
107
|
* Insert a test document which's dtd was registered, returning the docid that was used.
|
108
|
*/
|
109
|
public void testRegisteredDTDDucoment() throws Exception {
|
110
|
String xml = FileUtils.readFileToString(new File("./test/jones.204.22.xml"), "UTF-8");
|
111
|
String docid = generateDocumentId() + ".1";
|
112
|
try {
|
113
|
m.login(username, password);
|
114
|
String response = insertDocumentId(docid, xml, true, false);
|
115
|
assertTrue(response.contains(docid));
|
116
|
} catch (MetacatAuthException e) {
|
117
|
fail(e.getMessage());
|
118
|
} catch (MetacatInaccessibleException e) {
|
119
|
fail(e.getMessage());
|
120
|
}
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Insert a test document which's dtd was registered. But the xml doesn't follow the dta and returning an error.
|
125
|
*/
|
126
|
public void testRegisteredDTDInvalidDucoment() throws Exception {
|
127
|
String xml = FileUtils.readFileToString(new File("./test/jones.204.22.xml.invalid"), "UTF-8");
|
128
|
String docid = generateDocumentId() + ".1";
|
129
|
m.login(username, password);
|
130
|
try {
|
131
|
String response = m.insert(docid, new StringReader(xml), null);
|
132
|
fail("we shouldn't get get since we inserted an invalid xml");
|
133
|
} catch (MetacatException e) {
|
134
|
assertTrue(e.getMessage().contains("<error>"));
|
135
|
}
|
136
|
|
137
|
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* Insert a test document which's dtd was registered. But the xml doesn't follow the dta and returning an error.
|
142
|
*/
|
143
|
public void testUnRegisteredDTDDucoment() throws Exception {
|
144
|
String xml = FileUtils.readFileToString(new File("./test/doc_with_unregister_dtd.xml"), "UTF-8");
|
145
|
String docid = generateDocumentId() + ".1";
|
146
|
m.login(username, password);
|
147
|
try {
|
148
|
String response = m.insert(docid, new StringReader(xml), null);
|
149
|
fail("We can't get since the inserted xml has a unregistered dtd");
|
150
|
} catch (MetacatException e) {
|
151
|
assertTrue(e.getMessage().contains("<error>"));
|
152
|
assertTrue(e.getMessage().contains("isn't registered in Metacat"));
|
153
|
}
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Insert test documents which don't need to be validated: with embeded dtd or no declaration at all.
|
158
|
*/
|
159
|
public void testValidationUnneededDucoment() throws Exception {
|
160
|
//with embedded dtd
|
161
|
String xml = FileUtils.readFileToString(new File("./test/doc_with_embedded_dtd.xml"), "UTF-8");
|
162
|
String docid = generateDocumentId() + ".1";
|
163
|
try {
|
164
|
m.login(username, password);
|
165
|
String response = insertDocumentId(docid, xml, true, false);
|
166
|
assertTrue(response.contains(docid));
|
167
|
} catch (MetacatAuthException e) {
|
168
|
fail(e.getMessage());
|
169
|
} catch (MetacatInaccessibleException e) {
|
170
|
fail(e.getMessage());
|
171
|
}
|
172
|
//without dtd and scheam declaration
|
173
|
xml = FileUtils.readFileToString(new File("./test/doc_without_declaration.xml"), "UTF-8");
|
174
|
docid = generateDocumentId() + ".1";
|
175
|
try {
|
176
|
m.login(username, password);
|
177
|
String response = insertDocumentId(docid, xml, true, false);
|
178
|
assertTrue(response.contains(docid));
|
179
|
} catch (MetacatAuthException e) {
|
180
|
fail(e.getMessage());
|
181
|
} catch (MetacatInaccessibleException e) {
|
182
|
fail(e.getMessage());
|
183
|
}
|
184
|
}
|
185
|
|
186
|
/**
|
187
|
* Insert a test documents which uses an unregistered namespace
|
188
|
*/
|
189
|
public void testUnregisteredNamespaceSchema() throws Exception {
|
190
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
191
|
formatId.setValue("http://www.cuahsi.org/waterML/1.1/");
|
192
|
//Metacat API
|
193
|
String docid = generateDocumentId() + ".1";
|
194
|
try {
|
195
|
m.login(username, password);
|
196
|
String response = m.insert(docid, new StringReader(UNREGISTERED_SCHEMA_XML_INSTANCE), null);
|
197
|
fail("We shouldn't get there since the above statement should throw an exception.");
|
198
|
} catch (MetacatException e) {
|
199
|
assertTrue(e.getMessage().contains("<error>"));
|
200
|
assertTrue(e.getMessage().contains("http://www.w3schools.com"));
|
201
|
assertTrue(e.getMessage().contains("not registered"));
|
202
|
}
|
203
|
Thread.sleep(200);
|
204
|
//DaaONEAPI - MN.create
|
205
|
try {
|
206
|
Session session = getTestSession();
|
207
|
Identifier guid = new Identifier();
|
208
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
209
|
InputStream object = new ByteArrayInputStream(UNREGISTERED_SCHEMA_XML_INSTANCE.getBytes("UTF-8"));
|
210
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
211
|
sysmeta.setFormatId(formatId);
|
212
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
213
|
} catch (Exception e) {
|
214
|
assertTrue(e.getMessage().contains("<error>"));
|
215
|
assertTrue(e.getMessage().contains("http://www.w3schools.com"));
|
216
|
assertTrue(e.getMessage().contains("not registered"));
|
217
|
}
|
218
|
|
219
|
//DaaONEAPI - CN.create
|
220
|
Thread.sleep(200);
|
221
|
try {
|
222
|
Session session = getCNSession();
|
223
|
Identifier guid = new Identifier();
|
224
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
225
|
InputStream object = new ByteArrayInputStream(UNREGISTERED_SCHEMA_XML_INSTANCE.getBytes("UTF-8"));
|
226
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
227
|
sysmeta.setFormatId(formatId);
|
228
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
229
|
} catch(Exception e) {
|
230
|
assertTrue(e.getMessage().contains("<error>"));
|
231
|
assertTrue(e.getMessage().contains("http://www.w3schools.com"));
|
232
|
assertTrue(e.getMessage().contains("not registered"));
|
233
|
}
|
234
|
}
|
235
|
|
236
|
|
237
|
/**
|
238
|
* Test to insert an eml 201 document
|
239
|
* @throws Exception
|
240
|
*/
|
241
|
public void testEML201 () throws Exception{
|
242
|
String title = "it is a test";
|
243
|
String emlVersion = EML2_0_1;
|
244
|
String eml200 = getTestEmlDoc(title, emlVersion);
|
245
|
//System.out.println("the eml document is \n"+eml200);
|
246
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
247
|
formatId.setValue("eml://ecoinformatics.org/eml-2.0.1");
|
248
|
//Metacat API
|
249
|
String docid = generateDocumentId() + ".1";
|
250
|
try {
|
251
|
m.login(username, password);
|
252
|
String response = m.insert(docid, new StringReader(eml200), null);
|
253
|
assertTrue(response.contains(docid));
|
254
|
} catch (MetacatException e) {
|
255
|
fail("The test failed since "+e.getMessage());
|
256
|
}
|
257
|
Thread.sleep(200);
|
258
|
//DaaONEAPI - MN.create
|
259
|
try {
|
260
|
Session session = getTestSession();
|
261
|
Identifier guid = new Identifier();
|
262
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
263
|
InputStream object = new ByteArrayInputStream(eml200.getBytes("UTF-8"));
|
264
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
265
|
sysmeta.setFormatId(formatId);
|
266
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
267
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
268
|
} catch (Exception e) {
|
269
|
fail("The test failed since "+e.getMessage());
|
270
|
}
|
271
|
|
272
|
//DaaONEAPI - CN.create
|
273
|
Thread.sleep(200);
|
274
|
try {
|
275
|
Session session = getCNSession();
|
276
|
Identifier guid = new Identifier();
|
277
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
278
|
InputStream object = new ByteArrayInputStream(eml200.getBytes("UTF-8"));
|
279
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
280
|
sysmeta.setFormatId(formatId);
|
281
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
282
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
283
|
} catch(Exception e) {
|
284
|
fail("The test failed since "+e.getMessage());
|
285
|
}
|
286
|
|
287
|
//insert a invalid eml 201
|
288
|
String invalidEml2 = eml200.replaceAll("access", "access1");
|
289
|
//System.out.println(""+invalidEml2);
|
290
|
docid = generateDocumentId() + ".1";
|
291
|
try {
|
292
|
m.login(username, password);
|
293
|
String response = m.insert(docid, new StringReader(invalidEml2), null);
|
294
|
fail("We can't get here since the document is invalid.");
|
295
|
} catch (MetacatException e) {
|
296
|
assertTrue(e.getMessage().contains("<error>"));
|
297
|
assertTrue(e.getMessage().contains("access1"));
|
298
|
}
|
299
|
}
|
300
|
|
301
|
/**
|
302
|
* Test to insert an eml 211 document
|
303
|
* @throws Exception
|
304
|
*/
|
305
|
public void testEML211 () throws Exception{
|
306
|
String title = "it is a test";
|
307
|
String emlVersion = EML2_1_1;
|
308
|
String eml211 = getTestEmlDoc(title, emlVersion);
|
309
|
System.out.println("the eml document is \n"+eml211);
|
310
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
311
|
formatId.setValue("eml://ecoinformatics.org/eml-2.1.1");
|
312
|
//Metacat API
|
313
|
String docid = generateDocumentId() + ".1";
|
314
|
try {
|
315
|
m.login(username, password);
|
316
|
String response = m.insert(docid, new StringReader(eml211), null);
|
317
|
assertTrue(response.contains(docid));
|
318
|
} catch (MetacatException e) {
|
319
|
fail("The test failed since "+e.getMessage());
|
320
|
}
|
321
|
Thread.sleep(200);
|
322
|
//DaaONEAPI - MN.create
|
323
|
try {
|
324
|
Session session = getTestSession();
|
325
|
Identifier guid = new Identifier();
|
326
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
327
|
InputStream object = new ByteArrayInputStream(eml211.getBytes("UTF-8"));
|
328
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
329
|
sysmeta.setFormatId(formatId);
|
330
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
331
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
332
|
} catch (Exception e) {
|
333
|
fail("The test failed since "+e.getMessage());
|
334
|
}
|
335
|
|
336
|
//DaaONEAPI - CN.create
|
337
|
Thread.sleep(200);
|
338
|
try {
|
339
|
Session session = getCNSession();
|
340
|
Identifier guid = new Identifier();
|
341
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
342
|
InputStream object = new ByteArrayInputStream(eml211.getBytes("UTF-8"));
|
343
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
344
|
sysmeta.setFormatId(formatId);
|
345
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
346
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
347
|
} catch(Exception e) {
|
348
|
fail("The test failed since "+e.getMessage());
|
349
|
}
|
350
|
|
351
|
//insert a invalid eml 201
|
352
|
String invalidEml2 = eml211.replaceAll("access", "access1");
|
353
|
//System.out.println(""+invalidEml2);
|
354
|
docid = generateDocumentId() + ".1";
|
355
|
try {
|
356
|
m.login(username, password);
|
357
|
String response = m.insert(docid, new StringReader(invalidEml2), null);
|
358
|
fail("We can't get here since the document is invalid.");
|
359
|
} catch (MetacatException e) {
|
360
|
assertTrue(e.getMessage().contains("<error>"));
|
361
|
assertTrue(e.getMessage().contains("access1"));
|
362
|
}
|
363
|
}
|
364
|
|
365
|
/**
|
366
|
* Test to insert a non-eml document but its namespace is registered.
|
367
|
* @throws Exception
|
368
|
*/
|
369
|
public void testRegisteredNamespaceOrFormatIdSchema() throws Exception {
|
370
|
String xml = FileUtils.readFileToString(new File("./test/dryad-metadata-profile-sample.xml"), "UTF-8");
|
371
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
372
|
formatId.setValue("http://datadryad.org/profile/v3.1");
|
373
|
//Metacat API
|
374
|
String docid = generateDocumentId() + ".1";
|
375
|
try {
|
376
|
m.login(username, password);
|
377
|
String response = m.insert(docid, new StringReader(xml), null);
|
378
|
assertTrue(response.contains(docid));
|
379
|
} catch (MetacatException e) {
|
380
|
fail("The test failed since "+e.getMessage());
|
381
|
}
|
382
|
Thread.sleep(200);
|
383
|
//DaaONEAPI - MN.create
|
384
|
try {
|
385
|
Session session = getTestSession();
|
386
|
Identifier guid = new Identifier();
|
387
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
388
|
InputStream object = new ByteArrayInputStream(xml.getBytes("UTF-8"));
|
389
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
390
|
sysmeta.setFormatId(formatId);
|
391
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
392
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
393
|
} catch (Exception e) {
|
394
|
fail("The test failed since "+e.getMessage());
|
395
|
}
|
396
|
|
397
|
//DaaONEAPI - CN.create
|
398
|
Thread.sleep(200);
|
399
|
try {
|
400
|
Session session = getCNSession();
|
401
|
Identifier guid = new Identifier();
|
402
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
403
|
InputStream object = new ByteArrayInputStream(xml.getBytes("UTF-8"));
|
404
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
405
|
sysmeta.setFormatId(formatId);
|
406
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
407
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
408
|
} catch(Exception e) {
|
409
|
fail("The test failed since "+e.getMessage());
|
410
|
}
|
411
|
|
412
|
//insert a invalid dryad
|
413
|
String invalidXml = FileUtils.readFileToString(new File("./test/dryad-metadata-profile-invalid.xml"), "UTF-8");
|
414
|
//System.out.println(""+invalidEml2);
|
415
|
docid = generateDocumentId() + ".1";
|
416
|
try {
|
417
|
m.login(username, password);
|
418
|
String response = m.insert(docid, new StringReader(invalidXml), null);
|
419
|
fail("We can't get here since the document is invalid.");
|
420
|
} catch (MetacatException e) {
|
421
|
assertTrue(e.getMessage().contains("bad"));
|
422
|
assertTrue(e.getMessage().contains("<error>"));
|
423
|
}
|
424
|
|
425
|
}
|
426
|
|
427
|
public void testUnregisteredNoNamespaceSchema() throws Exception {
|
428
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
429
|
formatId.setValue("www.fgdc.gov/foo/");
|
430
|
String xml = UNREGISTERED_NONAMESPACE_SCHEMA_XML_INSTANCE;
|
431
|
//Metacat API
|
432
|
String docid = generateDocumentId() + ".1";
|
433
|
try {
|
434
|
m.login(username, password);
|
435
|
String response = m.insert(docid, new StringReader(xml), null);
|
436
|
fail("We shouldn't get there since the above statement should throw an exception.");
|
437
|
} catch (MetacatException e) {
|
438
|
assertTrue(e.getMessage().contains("<error>"));
|
439
|
assertTrue(e.getMessage().contains("http://www.fgdc.gov/metadata/foo.xsd"));
|
440
|
assertTrue(e.getMessage().contains("not registered"));
|
441
|
}
|
442
|
Thread.sleep(200);
|
443
|
//DaaONEAPI - MN.create
|
444
|
try {
|
445
|
Session session = getTestSession();
|
446
|
Identifier guid = new Identifier();
|
447
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
448
|
InputStream object = new ByteArrayInputStream(UNREGISTERED_NONAMESPACE_SCHEMA_XML_INSTANCE.getBytes("UTF-8"));
|
449
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
450
|
sysmeta.setFormatId(formatId);
|
451
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
452
|
} catch (Exception e) {
|
453
|
assertTrue(e.getMessage().contains("<error>"));
|
454
|
assertTrue(e.getMessage().contains("www.fgdc.gov/foo/"));
|
455
|
assertTrue(e.getMessage().contains("http://www.fgdc.gov/metadata/foo.xsd"));
|
456
|
assertTrue(e.getMessage().contains("not registered"));
|
457
|
}
|
458
|
|
459
|
//DaaONEAPI - CN.create
|
460
|
Thread.sleep(200);
|
461
|
try {
|
462
|
Session session = getCNSession();
|
463
|
Identifier guid = new Identifier();
|
464
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
465
|
InputStream object = new ByteArrayInputStream(UNREGISTERED_NONAMESPACE_SCHEMA_XML_INSTANCE.getBytes("UTF-8"));
|
466
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
467
|
sysmeta.setFormatId(formatId);
|
468
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
469
|
} catch(Exception e) {
|
470
|
assertTrue(e.getMessage().contains("<error>"));
|
471
|
assertTrue(e.getMessage().contains("www.fgdc.gov/foo/"));
|
472
|
assertTrue(e.getMessage().contains("http://www.fgdc.gov/metadata/foo.xsd"));
|
473
|
assertTrue(e.getMessage().contains("not registered"));
|
474
|
}
|
475
|
}
|
476
|
|
477
|
public void testRegisteredNoNamespaceSchema() throws Exception {
|
478
|
String xml = FileUtils.readFileToString(new File("./test/fgdc.xml"), "UTF-8");
|
479
|
ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
|
480
|
formatId.setValue("FGDC-STD-001-1998");
|
481
|
//Metacat API
|
482
|
String docid = generateDocumentId() + ".1";
|
483
|
try {
|
484
|
m.login(username, password);
|
485
|
String response = m.insert(docid, new StringReader(xml), null);
|
486
|
assertTrue(response.contains(docid));
|
487
|
} catch (MetacatException e) {
|
488
|
fail("The test failed since "+e.getMessage());
|
489
|
}
|
490
|
Thread.sleep(200);
|
491
|
//DaaONEAPI - MN.create
|
492
|
try {
|
493
|
Session session = getTestSession();
|
494
|
Identifier guid = new Identifier();
|
495
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
496
|
InputStream object = new ByteArrayInputStream(xml.getBytes("UTF-8"));
|
497
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
498
|
sysmeta.setFormatId(formatId);
|
499
|
Identifier pid = MNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
500
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
501
|
} catch (Exception e) {
|
502
|
fail("The test failed since "+e.getMessage());
|
503
|
}
|
504
|
|
505
|
//DaaONEAPI - CN.create
|
506
|
Thread.sleep(200);
|
507
|
try {
|
508
|
Session session = getCNSession();
|
509
|
Identifier guid = new Identifier();
|
510
|
guid.setValue("testCreate." + System.currentTimeMillis());
|
511
|
InputStream object = new ByteArrayInputStream(xml.getBytes("UTF-8"));
|
512
|
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
|
513
|
sysmeta.setFormatId(formatId);
|
514
|
Identifier pid = CNodeService.getInstance(request).create(session, guid, object, sysmeta);
|
515
|
assertTrue(pid.getValue().equals(guid.getValue()));
|
516
|
} catch(Exception e) {
|
517
|
fail("The test failed since "+e.getMessage());
|
518
|
}
|
519
|
|
520
|
//insert a invalid fgdc
|
521
|
String invalidXml = xml.replace("metadata", "metadata1");
|
522
|
//System.out.println(""+invalidEml2);
|
523
|
docid = generateDocumentId() + ".1";
|
524
|
try {
|
525
|
m.login(username, password);
|
526
|
String response = m.insert(docid, new StringReader(invalidXml), null);
|
527
|
fail("We can't get here since the document is invalid.");
|
528
|
} catch (MetacatException e) {
|
529
|
assertTrue(e.getMessage().contains("metadata1"));
|
530
|
assertTrue(e.getMessage().contains("<error>"));
|
531
|
}
|
532
|
}
|
533
|
|
534
|
}
|