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.simulator.launcher;
27
28 import java.io.File;
29 import java.net.URL;
30 import java.util.List;
31
32 import org.apache.commons.lang3.StringUtils;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.junit.Assert;
36 import org.junit.Ignore;
37 import org.junit.Test;
38 import org.nuiton.topia.TopiaContext;
39
40 import fr.ifremer.isisfish.AbstractIsisFishTest;
41 import fr.ifremer.isisfish.datastore.ResultStorage;
42 import fr.ifremer.isisfish.datastore.SimulationStorage;
43 import fr.ifremer.isisfish.entities.Result;
44 import fr.ifremer.isisfish.simulator.SimulationControl;
45 import fr.ifremer.isisfish.types.TimeStep;
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 @Ignore
62 public class SimulationServiceIT extends AbstractIsisFishTest {
63
64
65 private static Log log = LogFactory.getLog(SimulationServiceIT.class);
66
67
68
69
70
71
72
73
74 protected void testSimulate(String zipName) throws Exception {
75
76 int resultChecked = 0;
77
78
79 File zip = new File(zipName);
80
81
82 String name = "simulation-test-" + System.currentTimeMillis();
83 SimulationStorage simRef = SimulationStorage.importAndRenameZip(zip, name + "-ref");
84
85
86 SimulationStorage sim = SimulationStorage.importAndRenameZip(zip, name + "-temp");
87
88 try {
89
90 TopiaContext tx = sim.getStorage().beginTransaction();
91 tx.execute("DELETE from " + Result.class.getName());
92 tx.commitTransaction();
93 tx.closeContext();
94
95
96 SimulationControl control = new SimulationControl(sim.getName());
97 control.setStep(new TimeStep());
98 InProcessSimulatorLauncher launcher = new InProcessSimulatorLauncher();
99 sim = launcher.localSimulate(control, sim);
100
101
102 if (!StringUtils.isEmpty(sim.getInformation().getException())) {
103 Assert.fail(sim.getInformation().getException());
104 }
105
106
107 ResultStorage resultRef = simRef.getResultStorage();
108 ResultStorage result = sim.getResultStorage();
109
110 List<String> resultNames = resultRef.getResultName();
111 Assert.assertEquals(resultNames, result.getResultName());
112
113 TimeStep lastStep = resultRef.getLastStep();
114
115
116 if (log.isInfoEnabled()) {
117 log.info("Check result ...");
118 }
119
120 for (TimeStep step = new TimeStep(0); step.beforeOrEquals(lastStep); step = step.next()) {
121 for (String resultName : resultNames) {
122 if (log.isDebugEnabled()) {
123 log.debug("Check result " + step + " " + resultName);
124 }
125 Assert.assertEquals("Date " + step.getStep() + " result " + resultName,
126 resultRef.getMatrix(step, resultName),
127 result.getMatrix(step, resultName));
128
129 resultChecked++;
130 }
131 }
132
133
134 Assert.assertEquals("All expected results have not been checked !", resultNames.size() * 12 * 5, resultChecked);
135
136 } finally {
137
138 simRef.getStorage().closeContext();
139 sim.getStorage().closeContext();
140
141 simRef.delete(false);
142 sim.delete(false);
143 }
144
145
146 Assert.assertTrue("At least some result must be done", resultChecked > 100);
147 }
148
149
150
151
152
153
154
155
156
157
158
159 @Test
160 public void testSimlateGdG() throws Exception {
161 URL zipURL = this.getClass().getResource("sim_test-gdg-3.2-3.3.zip");
162 testSimulate(zipURL.getFile());
163 }
164
165
166
167
168
169
170
171
172
173
174
175 @Test
176 public void testSimlateICA() throws Exception {
177 URL zipURL = this.getClass().getResource("sim_test-ica-3.2-3.3.zip");
178 testSimulate(zipURL.getFile());
179 }
180 }