|
1 | 1 | /** Elixir BioHackathon 2022 */
|
2 | 2 | package com.elixir.biohackaton.ISAToSRA;
|
3 | 3 |
|
| 4 | +import com.elixir.biohackaton.ISAToSRA.receipt.MarsReceiptException; |
4 | 5 | import com.elixir.biohackaton.ISAToSRA.receipt.isamodel.*;
|
5 |
| -import com.elixir.biohackaton.ISAToSRA.receipt.marsmodel.*; |
6 | 6 | import com.elixir.biohackaton.ISAToSRA.sra.model.Receipt;
|
7 | 7 | import com.elixir.biohackaton.ISAToSRA.sra.service.MarsReceiptService;
|
8 | 8 | import com.fasterxml.jackson.databind.ObjectMapper;
|
|
15 | 15 | class EnaReceiptToMarsTest {
|
16 | 16 |
|
17 | 17 | @Test
|
18 |
| - void convertToMars() { |
19 |
| - try { |
| 18 | + void convertToMars_validInput() { |
| 19 | + String enaReceiptFilePath = "../../test-data/ena-receipt.json"; |
| 20 | + String marsReceiptPath = "../../test-data/mars-ena-receipt.json"; |
| 21 | + convertToMars(enaReceiptFilePath, marsReceiptPath); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void convertToMars_invalidInput() { |
| 26 | + String enaReceiptFilePath = "../../test-data/ena-receipt-invalid.json"; |
| 27 | + String marsReceiptPath = "../../test-data/mars-ena-receipt-invalid.json"; |
| 28 | + convertToMars(enaReceiptFilePath, marsReceiptPath); |
| 29 | + } |
20 | 30 |
|
21 |
| - // Reading Inputs |
22 |
| - String enaReceiptFilePath = "../../test-data/ena-receipt.json"; |
23 |
| - String isaJsonFilePath = "../../test-data/biosamples-input-isa.json"; |
24 |
| - String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath()); |
25 |
| - String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath()); |
| 31 | + void convertToMars(final String enaReceiptFilePath, final String marsReceiptPath) { |
| 32 | + ObjectMapper jsonMapper = new ObjectMapper(); |
| 33 | + MarsReceiptService marsReceiptService = new MarsReceiptService(); |
| 34 | + try { |
| 35 | + try { |
| 36 | + // Reading Inputs |
| 37 | + String receiptFile = Files.readString(new File(enaReceiptFilePath).toPath()); |
| 38 | + String isaJsonFilePath = "../../test-data/biosamples-modified-isa.json"; |
| 39 | + String isaJsonFile = Files.readString(new File(isaJsonFilePath).toPath()); |
26 | 40 |
|
27 |
| - // Mapping inputs to the proper objects |
28 |
| - ObjectMapper jsonMapper = new ObjectMapper(); |
29 |
| - Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class); |
30 |
| - IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class); |
| 41 | + // Mapping inputs to the proper objects |
| 42 | + Receipt receipt = jsonMapper.readValue(receiptFile, Receipt.class); |
| 43 | + IsaJson isaJson = jsonMapper.readValue(isaJsonFile, IsaJson.class); |
31 | 44 |
|
32 |
| - // Converting ENA receipt to MARS receipt |
33 |
| - MarsReceiptService marsReceiptService = new MarsReceiptService(); |
34 |
| - MarsReceipt marsReceipt = marsReceiptService.convertReceiptToMars(receipt, isaJson); |
| 45 | + // Converting ENA receipt to MARS receipt |
| 46 | + marsReceiptService.convertReceiptToMars(receipt, isaJson); |
| 47 | + } catch (MarsReceiptException e) { |
| 48 | + marsReceiptService.setMarsReceiptErrors(e.getError()); |
| 49 | + } catch (Exception e) { |
| 50 | + marsReceiptService.setMarsReceiptErrors(e.getMessage()); |
| 51 | + } |
35 | 52 |
|
36 | 53 | // Saving the result as a Json file
|
37 |
| - String marsReceiptPath = "../../test-data/mars-ena-receipt.json"; |
38 |
| - Files.write(new File(marsReceiptPath).toPath(), jsonMapper.writeValueAsBytes(marsReceipt)); |
39 |
| - } catch (Exception ex) { |
40 |
| - System.console().printf("%s", ex); |
| 54 | + Files.write( |
| 55 | + new File(marsReceiptPath).toPath(), |
| 56 | + jsonMapper.writeValueAsBytes(marsReceiptService.getMarsReceipt())); |
| 57 | + } catch (Exception e) { |
| 58 | + e.printStackTrace(); |
41 | 59 | }
|
42 | 60 | }
|
43 | 61 | }
|
0 commit comments