1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.view;
|
10
|
|
11
|
import java.io.BufferedWriter;
|
12
|
import java.io.ByteArrayOutputStream;
|
13
|
import java.io.InputStreamReader;
|
14
|
import java.io.OutputStreamWriter;
|
15
|
import java.io.StringReader;
|
16
|
import java.io.Writer;
|
17
|
import java.net.URI;
|
18
|
import java.util.ArrayList;
|
19
|
import java.util.HashMap;
|
20
|
import java.util.HashSet;
|
21
|
import java.util.List;
|
22
|
import java.util.Map;
|
23
|
import java.util.Set;
|
24
|
|
25
|
import javax.xml.transform.stream.StreamResult;
|
26
|
|
27
|
import org.custommonkey.xmlunit.XMLAssert;
|
28
|
import org.custommonkey.xmlunit.XMLUnit;
|
29
|
import org.joda.time.DateTime;
|
30
|
import org.joda.time.DateTimeZone;
|
31
|
import org.junit.Before;
|
32
|
import org.junit.Test;
|
33
|
import org.springframework.oxm.Marshaller;
|
34
|
import org.unitils.UnitilsJUnit4;
|
35
|
import org.unitils.spring.annotation.SpringApplicationContext;
|
36
|
import org.unitils.spring.annotation.SpringBeanByName;
|
37
|
import org.unitils.spring.annotation.SpringBeanByType;
|
38
|
|
39
|
import com.github.dozermapper.core.Mapper;
|
40
|
|
41
|
import eu.etaxonomy.cdm.remote.dto.dc.Relation;
|
42
|
import eu.etaxonomy.cdm.remote.dto.namecatalogue.NameInformation;
|
43
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.InfoItem;
|
44
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.Relationship;
|
45
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.SpeciesProfileModel;
|
46
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.StringType;
|
47
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonConcept;
|
48
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;
|
49
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonRelationshipTerm;
|
50
|
import eu.etaxonomy.cdm.remote.dto.tdwg.voc.Team;
|
51
|
import eu.etaxonomy.remote.dto.rdf.Rdf;
|
52
|
|
53
|
@SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/applicationContext-test.xml")
|
54
|
public class RdfViewTest extends UnitilsJUnit4 {
|
55
|
|
56
|
@SpringBeanByName
|
57
|
private Marshaller marshaller;
|
58
|
|
59
|
@SpringBeanByName
|
60
|
private Marshaller rdfMarshaller;
|
61
|
|
62
|
@SpringBeanByType
|
63
|
private Mapper mapper;
|
64
|
|
65
|
private Rdf rdf;
|
66
|
private TaxonConcept taxonConcept;
|
67
|
private SpeciesProfileModel speciesProfileModel;
|
68
|
|
69
|
@Before
|
70
|
public void setUp() throws Exception {
|
71
|
XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
|
72
|
XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
|
73
|
XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
74
|
XMLUnit.setIgnoreWhitespace(true);
|
75
|
|
76
|
taxonConcept = new TaxonConcept();
|
77
|
|
78
|
TaxonName taxonName = new TaxonName();
|
79
|
taxonName.setAuthorship("authorship");
|
80
|
taxonName.setNameComplete("Aus aus");
|
81
|
taxonName.setIdentifier(new URI("urn:lsid:example.org:names:1"));
|
82
|
taxonConcept.setHasName(taxonName);
|
83
|
taxonConcept.setIdentifier(new URI("urn:lsid:example.org:taxonconcepts:1"));
|
84
|
taxonConcept.setTitle("Lorem ipsum");
|
85
|
taxonConcept.setCreated(new DateTime(2004, 12, 25, 12, 0, 0, 0,DateTimeZone.UTC));
|
86
|
|
87
|
Relation relation = new Relation();
|
88
|
relation.setResource(new URI("http://www.example.org/"));
|
89
|
taxonConcept.setRelation(relation);
|
90
|
// PublicationCitation publicationCitation = new PublicationCitation();
|
91
|
taxonConcept.setPublishedIn("Lorem ipsum dolor");
|
92
|
|
93
|
Team team = new Team();
|
94
|
team.setTitle("team name");
|
95
|
|
96
|
taxonConcept.setAccordingTo(team);
|
97
|
|
98
|
TaxonRelationshipTerm taxonRelationshipTerm = new TaxonRelationshipTerm();
|
99
|
taxonRelationshipTerm.setIdentifier(new URI("http://rs.e-taxonomy.eu/voc/TaxonRelationshipTerm.rdf"));
|
100
|
Set<Relationship> relationships = new HashSet<>();
|
101
|
Relationship relationship = new Relationship();
|
102
|
relationship.setRelationshipCategory(taxonRelationshipTerm);
|
103
|
TaxonConcept t = new TaxonConcept();
|
104
|
t.setIdentifier(new URI("urn:lsid:example.org:taxonconcepts:2"));
|
105
|
t.setTitle("Dolor sic amet");
|
106
|
relationship.setToTaxon(t);
|
107
|
//relationship.setFromTaxon(taxonConcept);
|
108
|
relationships.add(relationship);
|
109
|
|
110
|
taxonConcept.setHasRelationship(relationships);
|
111
|
|
112
|
SpeciesProfileModel speciesProfileModel1 = new SpeciesProfileModel();
|
113
|
speciesProfileModel1.setIdentifier(new URI("urn:lsid:example.org:descriptions:1"));
|
114
|
speciesProfileModel1.setTitle("Description of Aus aus");
|
115
|
|
116
|
Set<SpeciesProfileModel> speciesProfileModels = new HashSet<>();
|
117
|
speciesProfileModels.add(speciesProfileModel1);
|
118
|
taxonConcept.setDescribedBy(speciesProfileModels);
|
119
|
rdf = new Rdf();
|
120
|
|
121
|
speciesProfileModel = new SpeciesProfileModel();
|
122
|
InfoItem infoItem = new InfoItem();
|
123
|
StringType englishDescription = new StringType();
|
124
|
englishDescription.setLang("en");
|
125
|
englishDescription.setValue("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tincidunt pretium quam, id tristique sem iaculis vitae. Vestibulum pharetra eros in ligula rutrum imperdiet. In lorem dui, cursus a suscipit in, pulvinar eget nisl. Phasellus ut nunc eu mauris adipiscing luctus non vel lorem. Suspendisse volutpat faucibus ante, nec bibendum libero consectetur sed. Nullam non posuere neque. Nulla egestas ullamcorper mauris nec tincidunt. Duis id nibh justo. Mauris vel felis et mi eleifend auctor a ac dui. Morbi in urna leo, eu varius lorem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi mollis nunc eget purus ullamcorper eget pulvinar sapien bibendum. Donec et velit augue, eu pretium mauris. Maecenas lorem leo, malesuada vitae tempor a, gravida quis dolor. Pellentesque lacus velit, sagittis quis posuere ac, rutrum a lacus. Cras dolor ligula, hendrerit at porta sed, posuere euismod mi. Sed sit amet velit turpis.");
|
126
|
Map<Object,StringType> hasContent = new HashMap<>();
|
127
|
hasContent.put(englishDescription.getValue(),englishDescription);
|
128
|
infoItem.setHasContent(hasContent);
|
129
|
Set<InfoItem> infoItems = new HashSet<>();
|
130
|
infoItems.add(infoItem);
|
131
|
speciesProfileModel.setHasInformation(infoItems);
|
132
|
}
|
133
|
|
134
|
@Test
|
135
|
public void testMarshalRdf() throws Exception {
|
136
|
rdf.addThing(taxonConcept);
|
137
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
138
|
Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8" ));
|
139
|
marshaller.marshal(rdf, new StreamResult(writer));
|
140
|
writer.close();
|
141
|
|
142
|
String resource = "/eu/etaxonomy/cdm/remote/view/RdfViewTest.rdf";
|
143
|
System.out.println(new String(outputStream.toByteArray()));
|
144
|
|
145
|
XMLAssert.assertXMLEqual(
|
146
|
new InputStreamReader(this.getClass().getResourceAsStream(resource)),
|
147
|
new StringReader(new String(outputStream.toByteArray())));
|
148
|
}
|
149
|
|
150
|
@Test
|
151
|
public void testMarshalSPM() throws Exception {
|
152
|
rdf.addThing(speciesProfileModel);
|
153
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
154
|
Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8" ));
|
155
|
marshaller.marshal(rdf, new StreamResult(writer));
|
156
|
writer.close();
|
157
|
|
158
|
//TODO is this not yet implemented or why is it commented (uncommenting results in diff error)
|
159
|
// String resource = "/eu/etaxonomy/cdm/remote/view/RdfViewTest.rdf";
|
160
|
// System.out.println(new String(outputStream.toByteArray()));
|
161
|
// XMLAssert.assertXMLEqual(new InputStreamReader(this.getClass().getResourceAsStream(resource)),new StringReader(new String(outputStream.toByteArray())));
|
162
|
}
|
163
|
|
164
|
@Test
|
165
|
public void testNameInformationRdf() throws Exception {
|
166
|
|
167
|
if(!OaiPmhViewTest.dozerXsdIsAvailable()){
|
168
|
return;
|
169
|
}
|
170
|
|
171
|
Map<String,List<NameInformation>> model = new HashMap<>();
|
172
|
List<NameInformation> niList = new ArrayList<>();
|
173
|
NameInformation ni = new NameInformation();
|
174
|
ni.setRequest("64cf8cf8-f56a-4411-8f49-c3dc95ea257a");
|
175
|
ni.setResponse("Platalea leucorodia Linnaeus, 1758",
|
176
|
"Platalea leucorodia",
|
177
|
"Species",
|
178
|
new HashSet<>(),
|
179
|
null,
|
180
|
new HashSet<>(),
|
181
|
new HashSet<>(),
|
182
|
new HashSet<>());
|
183
|
ni.getResponse().addToTaxonUuids("1a5bcb42-146f-42e5-9136-1b21d170163e");
|
184
|
niList.add(ni);
|
185
|
model.put("64cf8cf8-f56a-4411-8f49-c3dc95ea257a", niList);
|
186
|
RdfView rdfView = new RdfView();
|
187
|
rdfView.setMapper(mapper);
|
188
|
rdfView.setRdfMarshaller(marshaller);
|
189
|
rdf = rdfView.buildRdf(model);
|
190
|
|
191
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
192
|
Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8" ));
|
193
|
rdfMarshaller.marshal(rdf, new StreamResult(writer));
|
194
|
writer.close();
|
195
|
System.out.println(new String(outputStream.toByteArray()));
|
196
|
|
197
|
String resource = "/eu/etaxonomy/cdm/remote/view/NameInformationTest.rdf";
|
198
|
XMLAssert.assertXMLEqual(new InputStreamReader(this.getClass().getResourceAsStream(resource)),new StringReader(new String(outputStream.toByteArray())));
|
199
|
}
|
200
|
}
|