1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package fr.ifremer.isisfish.mexico.export;
27
28 import java.io.File;
29 import java.io.IOException;
30
31 import org.apache.commons.io.FileUtils;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.junit.Assert;
35 import org.junit.Test;
36 import org.nuiton.topia.TopiaContext;
37 import org.nuiton.topia.TopiaException;
38
39 import fr.ifremer.isisfish.AbstractIsisFishTest;
40 import fr.ifremer.isisfish.datastore.RegionStorage;
41 import fr.ifremer.isisfish.datastore.StorageException;
42 import fr.ifremer.isisfish.entities.FisheryRegion;
43 import fr.ifremer.isisfish.simulator.sensitivity.SensitivityUtils;
44
45
46
47
48
49
50
51
52
53
54 public class RegionExplorerTest extends AbstractIsisFishTest {
55
56
57 private static Log log = LogFactory.getLog(RegionExplorerTest.class);
58
59
60
61
62
63
64
65
66 @Test
67 public void testExportRegionFactorsAsXml() throws TopiaException, StorageException, IOException {
68
69
70 RegionStorage regionStorage = RegionStorage.getRegion("BaseMotosICA");
71 TopiaContext context = regionStorage.getStorage().beginTransaction();
72 FisheryRegion fisheryRegion = RegionStorage.getFisheryRegion(context);
73
74
75 File file = File.createTempFile("xmlexport-", ".xml");
76 file.deleteOnExit();
77 RegionExportFactorXML xmlFactorExport = new RegionExportFactorXML(file);
78
79
80 RegionExplorer explorer = new RegionExplorer();
81 explorer.explore(fisheryRegion, xmlFactorExport);
82 String xmlExport = FileUtils.readFileToString(file);
83
84 if (log.isDebugEnabled()) {
85 log.debug("Export xml is : \n" + xmlExport);
86 }
87
88
89
90 Assert.assertTrue("A factor has a null name", xmlExport.indexOf("name=\"null\"") == -1);
91
92
93
94
95
96
97 Assert.assertTrue("An equation factor is missing", xmlExport.indexOf("Population.Anchois_long.growth") != -1);
98
99
100 context.closeContext();
101 }
102
103
104
105
106
107
108
109
110
111 @Test
112 public void testAllEntityPresence() throws TopiaException, StorageException, IOException {
113
114 RegionStorage regionStorage = RegionStorage.getRegion("Golfe de Gascogne");
115 TopiaContext context = regionStorage.getStorage().beginTransaction();
116 FisheryRegion fisheryRegion = RegionStorage.getFisheryRegion(context);
117
118
119 File file = File.createTempFile("xmlexport-", ".xml");
120 file.deleteOnExit();
121 RegionExportFactorXML xmlFactorExport = new RegionExportFactorXML(file);
122
123
124 RegionExplorer explorer = new RegionExplorer();
125 explorer.explore(fisheryRegion, xmlFactorExport);
126 String xmlExport = FileUtils.readFileToString(file);
127
128
129
130 for (String property : SensitivityUtils.getProperties().stringPropertyNames()) {
131 String entityPart = property.substring(0, property.indexOf('.'));
132
133 if ("Variable".equals(entityPart)) {
134
135 continue;
136 }
137
138 Assert.assertTrue("Entity " + entityPart + " is not present in xml export", xmlExport.indexOf(entityPart) != -1);
139
140 String propertyPart = property.substring(property.indexOf('.'));
141 Assert.assertTrue("Property " + property + " is not present in xml export", xmlExport.indexOf(propertyPart) != -1);
142 }
143
144
145 context.closeContext();
146 }
147 }