Project

General

Profile

« Previous | Next » 

Revision 8782

stub for testing ORE augmentation - this generates an ORE, adds a "wasDerivedFrom" triple and saves to Metacat MN for indexing. https://projects.ecoinformatics.org/ecoinfo/issues/6548

View differences:

test/edu/ucsb/nceas/metacat/annotation/OrePackageTest.java
1
/**  '$RCSfile$'
2
 *  Copyright: 2010 Regents of the University of California and the
3
 *              National Center for Ecological Analysis and Synthesis
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 */
19
package edu.ucsb.nceas.metacat.annotation;
20

  
21
import java.io.ByteArrayInputStream;
22
import java.io.InputStream;
23
import java.net.URI;
24
import java.util.Arrays;
25
import java.util.HashMap;
26
import java.util.List;
27
import java.util.Map;
28

  
29
import junit.framework.Test;
30
import junit.framework.TestSuite;
31

  
32
import org.dataone.ore.ResourceMapFactory;
33
import org.dataone.service.types.v1.Identifier;
34
import org.dataone.service.types.v1.ObjectFormatIdentifier;
35
import org.dataone.service.types.v1.Session;
36
import org.dataone.service.types.v1.SystemMetadata;
37
import org.dspace.foresite.Predicate;
38
import org.dspace.foresite.ResourceMap;
39
import org.dspace.foresite.Triple;
40
import org.dspace.foresite.jena.TripleJena;
41

  
42
import edu.ucsb.nceas.metacat.dataone.D1NodeServiceTest;
43
import edu.ucsb.nceas.metacat.dataone.MNodeService;
44

  
45
public class OrePackageTest extends D1NodeServiceTest {
46

  
47
	
48
    private static final String ANNOTATION_TEST_DOC = "test/eml-sample-annotation.xml";
49

  
50
	/**
51
	 * constructor for the test
52
	 */
53
	public OrePackageTest(String name) {
54
		super(name);
55
	}
56

  
57
	/**
58
	 * Establish a testing framework by initializing appropriate objects
59
	 */
60
	public void setUp() throws Exception {
61
		super.setUp();
62
	}
63

  
64
	/**
65
	 * Release any objects after tests are complete
66
	 */
67
	public void tearDown() {
68
	}
69

  
70
	/**
71
	 * Create a suite of tests to be run together
72
	 */
73
	public static Test suite() {
74
		TestSuite suite = new TestSuite();
75
		suite.addTest(new DatapackageSummarizerTest("testGenerateAnnotation"));
76
		return suite;
77
	}
78
	
79
	
80
	/**
81
	 * Generate a single ORE+annotation
82
	 * @throws Exception
83
	 */
84
	public void testGenerateAnnotation() throws Exception {
85
		
86
		// add an EML package
87
		Identifier metadataPid = new Identifier();
88
		metadataPid.setValue("testOre.eml." + System.currentTimeMillis());
89
		Session session = getTestSession();
90
		try {
91
			InputStream object = new ByteArrayInputStream(this.getTestDocFromFile(ANNOTATION_TEST_DOC).getBytes("UTF-8"));
92
			SystemMetadata sysmeta = createSystemMetadata(metadataPid, session.getSubject(), object);
93
			ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
94
			formatId.setValue("eml://ecoinformatics.org/eml-2.0.0");
95
			sysmeta.setFormatId(formatId);
96
			Identifier pid = MNodeService.getInstance(request).create(session, metadataPid, object, sysmeta);
97
			assertEquals(metadataPid.getValue(), pid.getValue());
98
		} catch (Exception e) {
99
			e.printStackTrace();
100
			fail("Could not add metadata test file: " + e.getMessage());
101
		}
102

  
103
		// generate the ORE for the EML metadata + data
104
		Map<Identifier, List<Identifier>> resources = new HashMap<Identifier, List<Identifier>>();
105
		Identifier resourceMapPid = new Identifier();
106
		resourceMapPid.setValue("resourceMap_" + metadataPid.getValue());
107
		Identifier dataIdentifier = new Identifier();
108
		dataIdentifier.setValue("derivedData.1.1");
109
		List<Identifier> dataPids = Arrays.asList(dataIdentifier);
110
		resources.put(metadataPid, dataPids);
111
		
112
		ResourceMap resourceMap = ResourceMapFactory.getInstance().createResourceMap(resourceMapPid , resources);
113
		
114
		// augment the ORE package with triples describing the derivation
115
		Triple triple = new TripleJena();
116
		triple.initialise(new URI(dataIdentifier.getValue()));
117
		Predicate predicate = new Predicate(new URI("http://www.w3.org/ns/prov#wasDerivedFrom"));
118
		triple.relate(predicate , new URI("https://cn.dataone.or/cn/v1/resolve/data.1.1"));
119
		resourceMap.addTriple(triple);
120

  
121
		// get the RDF content
122
		String rdfContent = ResourceMapFactory.getInstance().serializeResourceMap(resourceMap);
123
		
124
		// save the ORE+annotation (adjust formatId as needed)
125
		Identifier annotationPid = new Identifier();
126
		annotationPid.setValue("http://annotation/" + metadataPid.getValue());
127
		try {
128
			InputStream object = new ByteArrayInputStream(rdfContent.getBytes("UTF-8"));
129
			SystemMetadata sysmeta = createSystemMetadata(annotationPid, session.getSubject(), object);
130
			ObjectFormatIdentifier formatId = new ObjectFormatIdentifier();
131
			formatId.setValue("http://www.w3.org/TR/rdf-syntax-grammar");
132
			sysmeta.setFormatId(formatId);
133
			Identifier pid = MNodeService.getInstance(request).create(session, annotationPid, object, sysmeta);
134
			assertEquals(annotationPid.getValue(), pid.getValue());
135
		} catch (Exception e) {
136
			e.printStackTrace();
137
			fail("Could not add annotation test file: " + e.getMessage());
138
		}
139
		
140
		// TODO: check that it was parsed by metacat-index
141
	}
142

  
143
}
0 144

  

Also available in: Unified diff