1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.service;
|
11
|
|
12
|
import java.io.FileNotFoundException;
|
13
|
import java.io.FileOutputStream;
|
14
|
import java.io.IOException;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.junit.Assert;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
24
|
import eu.etaxonomy.cdm.api.service.INameService;
|
25
|
import eu.etaxonomy.cdm.io.common.ExportResult;
|
26
|
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
|
28
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
29
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
30
|
import eu.etaxonomy.cdm.io.service.IIOService;
|
31
|
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
|
32
|
|
33
|
/**
|
34
|
* @author cmathew
|
35
|
* @date 31 Jul 2015
|
36
|
*
|
37
|
*/
|
38
|
@DataSet
|
39
|
public class IOServiceExportTest extends BaseRemotingTest {
|
40
|
|
41
|
private final IIOService ioService = CdmApplicationState.getIOService();
|
42
|
private final INameService nameService = CdmApplicationState.getCurrentAppConfig().getNameService();
|
43
|
|
44
|
@Test
|
45
|
public void exportJaxbTest() {
|
46
|
JaxbExportConfigurator config = JaxbExportConfigurator.NewInstance(null, null);
|
47
|
ExportResult result = ioService.export(config);
|
48
|
List<byte[]> dataList = result.getExportData();
|
49
|
Assert.assertEquals(1, dataList.size());
|
50
|
byte[] exportData = dataList.get(0);
|
51
|
String savePath = "target/exportjaxb.xml";
|
52
|
FileOutputStream stream = null;
|
53
|
try {
|
54
|
stream = new FileOutputStream(savePath);
|
55
|
stream.write(exportData);
|
56
|
} catch (FileNotFoundException e) {
|
57
|
e.printStackTrace();
|
58
|
} catch (IOException e) {
|
59
|
e.printStackTrace();
|
60
|
} finally {
|
61
|
try {
|
62
|
if(stream != null) {
|
63
|
stream.close();
|
64
|
}
|
65
|
} catch (IOException e) {
|
66
|
e.printStackTrace();
|
67
|
}
|
68
|
}
|
69
|
|
70
|
}
|
71
|
|
72
|
@Test
|
73
|
public void exportSDDTest() {
|
74
|
SDDExportConfigurator config = SDDExportConfigurator.NewInstance(null, null, null);
|
75
|
ExportResult result = ioService.export(config);
|
76
|
List<byte[]> dataList = result.getExportData();
|
77
|
Assert.assertEquals(1, dataList.size());
|
78
|
byte[] exportData = dataList.get(0);
|
79
|
String savePath = "target/exportsdd.xml";
|
80
|
FileOutputStream stream = null;
|
81
|
try {
|
82
|
stream = new FileOutputStream(savePath);
|
83
|
stream.write(exportData);
|
84
|
} catch (FileNotFoundException e) {
|
85
|
e.printStackTrace();
|
86
|
} catch (IOException e) {
|
87
|
e.printStackTrace();
|
88
|
} finally {
|
89
|
try {
|
90
|
if(stream != null) {
|
91
|
stream.close();
|
92
|
}
|
93
|
} catch (IOException e) {
|
94
|
e.printStackTrace();
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
|
99
|
@Test
|
100
|
public void exportCSVTest() {
|
101
|
HashSet<UUID> set = new HashSet<UUID>();
|
102
|
set.add(UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab"));
|
103
|
CsvDemoExportConfigurator config = CsvDemoExportConfigurator.NewInstance(null, null);
|
104
|
config.setClassificationUuids(set);
|
105
|
config.setDoTaxa(true);
|
106
|
config.setHasHeaderLines(true);
|
107
|
config.setClassification(true);
|
108
|
config.setTaxonName(true);
|
109
|
config.setAuthor(true);
|
110
|
config.setRank(true);
|
111
|
config.setLastChange(true);
|
112
|
|
113
|
ExportResult result = ioService.export(config);
|
114
|
List<byte[]> dataList = result.getExportData();
|
115
|
Assert.assertEquals(1, dataList.size());
|
116
|
byte[] exportData = dataList.get(0);
|
117
|
String savePath = "target/exportcsv.xml";
|
118
|
saveToFile(savePath, exportData);
|
119
|
}
|
120
|
|
121
|
@Test
|
122
|
public void exportCSVNameTest() {
|
123
|
CsvNameExportConfigurator config = CsvNameExportConfigurator.NewInstance(null,null);
|
124
|
ExportResult result = ioService.export(config);
|
125
|
List<byte[]> dataList = result.getExportData();
|
126
|
Assert.assertEquals(1, dataList.size());
|
127
|
byte[] exportData = dataList.get(0);
|
128
|
String savePath = "target/exportcsvname.xml";
|
129
|
saveToFile(savePath, exportData);
|
130
|
}
|
131
|
|
132
|
@Test
|
133
|
public void exportCSVPrintTest() {
|
134
|
CsvNameExportConfigurator config = CsvNameExportConfigurator.NewInstance(null,null);
|
135
|
config.setNamesOnly(false);
|
136
|
config.setClassificationUUID(UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab"));
|
137
|
ExportResult result = ioService.export(config);
|
138
|
List<byte[]> dataList = result.getExportData();
|
139
|
Assert.assertEquals(1, dataList.size());
|
140
|
byte[] exportData = dataList.get(0);
|
141
|
String savePath = "target/exportcsvprint.xml";
|
142
|
saveToFile(savePath, exportData);
|
143
|
}
|
144
|
|
145
|
private static void saveToFile(String filePath, byte[] data) {
|
146
|
FileOutputStream stream = null;
|
147
|
try {
|
148
|
stream = new FileOutputStream(filePath);
|
149
|
stream.write(data);
|
150
|
} catch (FileNotFoundException e) {
|
151
|
e.printStackTrace();
|
152
|
} catch (IOException e) {
|
153
|
e.printStackTrace();
|
154
|
} finally {
|
155
|
try {
|
156
|
if(stream != null) {
|
157
|
stream.close();
|
158
|
}
|
159
|
} catch (IOException e) {
|
160
|
e.printStackTrace();
|
161
|
}
|
162
|
}
|
163
|
}
|
164
|
}
|