1
|
/**
|
2
|
* Copyright (C) 2015 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.taxeditor.service;
|
10
|
|
11
|
import java.io.FileOutputStream;
|
12
|
import java.io.IOException;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.junit.Assert;
|
18
|
import org.junit.Test;
|
19
|
import org.unitils.dbunit.annotation.DataSet;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
22
|
import eu.etaxonomy.cdm.io.common.ExportResult;
|
23
|
import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
|
24
|
import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
26
|
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.service.IIOService;
|
28
|
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
|
29
|
|
30
|
/**
|
31
|
* @author cmathew
|
32
|
* @date 31 Jul 2015
|
33
|
*
|
34
|
*/
|
35
|
@DataSet
|
36
|
public class IOServiceExportTest extends BaseRemotingTest {
|
37
|
|
38
|
private final IIOService ioService = CdmApplicationState.getIOService();
|
39
|
|
40
|
@Test
|
41
|
public void exportJaxbTest() throws IOException {
|
42
|
JaxbExportConfigurator config = JaxbExportConfigurator.NewInstance(null, null);
|
43
|
ExportResult result = ioService.export(config);
|
44
|
List<byte[]> dataList = result.getExportData();
|
45
|
Assert.assertEquals(1, dataList.size());
|
46
|
byte[] exportData = dataList.get(0);
|
47
|
String savePath = "target/exportjaxb.xml";
|
48
|
FileOutputStream stream = null;
|
49
|
|
50
|
stream = new FileOutputStream(savePath);
|
51
|
stream.write(exportData);
|
52
|
stream.close();
|
53
|
}
|
54
|
|
55
|
@Test
|
56
|
public void exportSDDTest() throws IOException {
|
57
|
SDDExportConfigurator config = SDDExportConfigurator.NewInstance(null, null, null);
|
58
|
ExportResult result = ioService.export(config);
|
59
|
List<byte[]> dataList = result.getExportData();
|
60
|
Assert.assertEquals(1, dataList.size());
|
61
|
byte[] exportData = dataList.get(0);
|
62
|
String savePath = "target/exportsdd.xml";
|
63
|
FileOutputStream stream = null;
|
64
|
|
65
|
stream = new FileOutputStream(savePath);
|
66
|
stream.write(exportData);
|
67
|
stream.close();
|
68
|
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void exportCSVTest() throws IOException {
|
73
|
HashSet<UUID> set = new HashSet<UUID>();
|
74
|
set.add(UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab"));
|
75
|
CsvDemoExportConfigurator config = CsvDemoExportConfigurator.NewInstance(null, null);
|
76
|
config.setClassificationUuids(set);
|
77
|
config.setDoTaxa(true);
|
78
|
config.setHasHeaderLines(true);
|
79
|
config.setClassification(true);
|
80
|
config.setTaxonName(true);
|
81
|
config.setAuthor(true);
|
82
|
config.setRank(true);
|
83
|
config.setLastChange(true);
|
84
|
|
85
|
ExportResult result = ioService.export(config);
|
86
|
List<byte[]> dataList = result.getExportData();
|
87
|
Assert.assertEquals(1, dataList.size());
|
88
|
byte[] exportData = dataList.get(0);
|
89
|
String savePath = "target/exportcsv.xml";
|
90
|
saveToFile(savePath, exportData);
|
91
|
}
|
92
|
|
93
|
@Test
|
94
|
public void exportCSVNameTest() throws IOException {
|
95
|
CsvNameExportConfigurator config = CsvNameExportConfigurator.NewInstance(null,null);
|
96
|
ExportResult result = ioService.export(config);
|
97
|
List<byte[]> dataList = result.getExportData();
|
98
|
Assert.assertEquals(1, dataList.size());
|
99
|
byte[] exportData = dataList.get(0);
|
100
|
String savePath = "target/exportcsvname.xml";
|
101
|
saveToFile(savePath, exportData);
|
102
|
}
|
103
|
|
104
|
@Test
|
105
|
public void exportCSVPrintTest() throws IOException {
|
106
|
CsvNameExportConfigurator config = CsvNameExportConfigurator.NewInstance(null,null);
|
107
|
config.setNamesOnly(false);
|
108
|
config.setClassificationUUID(UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab"));
|
109
|
ExportResult result = ioService.export(config);
|
110
|
List<byte[]> dataList = result.getExportData();
|
111
|
Assert.assertEquals(1, dataList.size());
|
112
|
byte[] exportData = dataList.get(0);
|
113
|
String savePath = "target/exportcsvprint.xml";
|
114
|
saveToFile(savePath, exportData);
|
115
|
}
|
116
|
|
117
|
private static void saveToFile(String filePath, byte[] data) throws IOException {
|
118
|
FileOutputStream stream = null;
|
119
|
stream = new FileOutputStream(filePath);
|
120
|
stream.write(data);
|
121
|
stream.close();
|
122
|
}
|
123
|
}
|