|
25 | 25 | import org.breedinginsight.model.Program; |
26 | 26 | import org.breedinginsight.model.Species; |
27 | 27 | import org.breedinginsight.services.SpeciesService; |
| 28 | +import org.breedinginsight.utilities.FileUtil; |
28 | 29 | import org.breedinginsight.utilities.response.mappers.GermplasmQueryMapper; |
29 | 30 | import org.jooq.DSLContext; |
30 | 31 | import org.junit.jupiter.api.*; |
| 32 | +import org.junit.jupiter.params.ParameterizedTest; |
| 33 | +import org.junit.jupiter.params.provider.CsvSource; |
| 34 | +import tech.tablesaw.api.Table; |
31 | 35 |
|
32 | 36 | import javax.inject.Inject; |
| 37 | +import java.io.ByteArrayInputStream; |
33 | 38 | import java.io.File; |
34 | 39 | import java.time.OffsetDateTime; |
35 | 40 | import java.util.ArrayList; |
36 | 41 | import java.util.List; |
37 | 42 | import java.util.Map; |
| 43 | +import java.util.Objects; |
38 | 44 |
|
39 | 45 | import static io.micronaut.http.HttpRequest.GET; |
40 | 46 | import static io.micronaut.http.HttpRequest.POST; |
@@ -237,7 +243,38 @@ public void getAllGermplasmListsSuccess() { |
237 | 243 | } |
238 | 244 | } |
239 | 245 | } |
| 246 | + @ParameterizedTest |
| 247 | + @CsvSource(value = {"CSV", "XLSX", "XLS"}) |
| 248 | + @SneakyThrows |
| 249 | + public void germplasmListExport(String extension) { |
| 250 | + String programId = validProgram.getId().toString(); |
| 251 | + String germplasmListDbId = fetchGermplasmListDbId(programId); |
| 252 | + |
| 253 | + // Build the endpoint to get germplasm by germplasm list. |
| 254 | + String endpoint = String.format("/programs/%s/germplasm/lists/%s/export?fileExtension=%s", programId, germplasmListDbId, extension); |
| 255 | + |
| 256 | + // Get germplasm by list. |
| 257 | + Flowable<HttpResponse<byte[]>> call = client.exchange( |
| 258 | + GET(endpoint).cookie(new NettyCookie("phylo-token", "test-registered-user")), byte[].class |
| 259 | + ); |
240 | 260 |
|
| 261 | + HttpResponse<byte[]> response = call.blockingFirst(); |
| 262 | + |
| 263 | + assertEquals(HttpStatus.OK, response.getStatus()); |
| 264 | + |
| 265 | + |
| 266 | + ByteArrayInputStream bodyStream = new ByteArrayInputStream(Objects.requireNonNull(response.body())); |
| 267 | + |
| 268 | + Table download = Table.create(); |
| 269 | + if (extension.equals("CSV")) { |
| 270 | + download = FileUtil.parseTableFromCsv(bodyStream); |
| 271 | + } |
| 272 | + if (extension.equals("XLS") || extension.equals("XLSX")) { |
| 273 | + download = FileUtil.parseTableFromExcel(bodyStream, 0); |
| 274 | + } |
| 275 | + int dataSize = download.rowCount(); |
| 276 | + assertEquals(3, dataSize, "Wrong number of germplasm were returned"); |
| 277 | + } |
241 | 278 | @Test |
242 | 279 | @SneakyThrows |
243 | 280 | public void getAllGermplasmByListSuccess() { |
|
0 commit comments