From 767455ad6fefb17c5b415910546a068c36553272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Meier?= Date: Wed, 8 Jan 2025 13:31:36 +0100 Subject: [PATCH] Finish test code and add CI workflow --- .github/workflows/ci.yaml | 27 +++++++ pom.xml | 76 +++++++------------ .../java/ExportServiceControllerTest.java | 68 ++++++++++++++++- 3 files changed, 120 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..b72aac3 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,27 @@ +name: CI + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: maven + + - name: Build and run tests with Maven + run: mvn clean compile test \ No newline at end of file diff --git a/pom.xml b/pom.xml index 81293fb..fcf72c6 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ 21 UTF-8 2025-01-02T12:10:36+01:00 + 5.15.2 @@ -25,16 +26,10 @@ org.springframework.boot spring-boot-starter-web - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-validation - - + + + + org.springdoc springdoc-openapi-starter-webmvc-ui @@ -46,11 +41,11 @@ jackson-databind-nullable 0.2.6 - - com.google.code.gson - gson - 2.11.0 - + + + + + org.openscience.cdk cdk-bundle @@ -63,11 +58,11 @@ main-6a6cddc02c-1 - - org.apache.commons - commons-configuration2 - 2.11.0 - + + + + + edu.ucdavis.fiehnlab.splash core @@ -116,6 +111,12 @@ protobuf-java 4.28.2 + + org.mockito + mockito-core + ${mockito.version} + test + @@ -161,35 +162,12 @@ - org.codehaus.mojo - build-helper-maven-plugin - 3.6.0 - - - add-source - generate-sources - - add-source - - - - target/generated-sources/openapi/src/main/java - - - - - add-test-source - generate-test-sources - - add-test-source - - - - target/generated-sources/openapi/src/main/java - - - - + org.apache.maven.plugins + maven-surefire-plugin + 3.5.2 + + -javaagent:${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar + diff --git a/src/test/java/ExportServiceControllerTest.java b/src/test/java/ExportServiceControllerTest.java index b9b4e14..f0225fd 100644 --- a/src/test/java/ExportServiceControllerTest.java +++ b/src/test/java/ExportServiceControllerTest.java @@ -23,14 +23,78 @@ public void testGetVersion() throws Exception { .andExpect(jsonPath("$").value(startsWith("export service "))); } + String nist_msp = """ +Name: Rutin +Synon: 2-(3,4-dihydroxyphenyl)-5,7-dihydroxy-3-[(2S,3R,4S,5S,6R)-3,4,5-trihydroxy-6-[[(2R,3R,4R,5R,6S)-3,4,5-trihydroxy-6-methyloxan-2-yl]oxymethyl]oxan-2-yl]oxychromen-4-one +DB#: MSBNK-IPB_Halle-PB001341 +InChIKey: IKGXIBQEEMLURG-NVPNHPEKSA-N +InChI: InChI=1S/C27H30O16/c1-8-17(32)20(35)22(37)26(40-8)39-7-15-18(33)21(36)23(38)27(42-15)43-25-19(34)16-13(31)5-10(28)6-14(16)41-24(25)9-2-3-11(29)12(30)4-9/h2-6,8,15,17-18,20-23,26-33,35-38H,7H2,1H3/t8-,15+,17-,18+,20+,21-,22+,23+,26+,27-/m0/s1 +SMILES: C[C@H]1[C@@H]([C@H]([C@H]([C@@H](O1)OC[C@@H]2[C@H]([C@@H]([C@H]([C@@H](O2)OC3=C(OC4=CC(=CC(=C4C3=O)O)O)C5=CC(=C(C=C5)O)O)O)O)O)O)O)O +Precursor_type: [M+H]+ +Spectrum_type: MS2 +Instrument_type: LC-ESI-QTOF +Instrument: API QSTAR Pulsar i +Ion_mode: POSITIVE +Collision_energy: 10 eV +Formula: C27H30O16 +MW: 610 +ExactMass: 610.15338 +Comments: Parent=-1 +Splash: splash10-0wmi-0009506000-98ca7f7c8f3072af4481 +Num Peaks: 5 +147.063 11 +303.050 999 +449.108 64 +465.102 587 +611.161 669 + +"""; + @Test - public void testCreateConversionTask() throws Exception { + public void testCreateConversionTaskNistMSP() throws Exception { String requestBody = "{ \"record_list\": [\"MSBNK-IPB_Halle-PB001341\"], \"format\": \"nist_msp\" }"; mockMvc.perform(post("/convert") .contentType("application/json") .content(requestBody)) .andExpect(status().isOk()) - .andExpect(content().contentType("application/octet-stream")); + .andExpect(content().contentType("application/octet-stream")) + .andExpect(content().string(nist_msp)); + } + + String riken_msp = """ +NAME : Rutin +PRECURSORMZ:\s +PRECURSORTYPE: [M+H]+ +FORMULA: C27H30O16 +INCHIKEY: IKGXIBQEEMLURG-NVPNHPEKSA-N +INCHI: InChI=1S/C27H30O16/c1-8-17(32)20(35)22(37)26(40-8)39-7-15-18(33)21(36)23(38)27(42-15)43-25-19(34)16-13(31)5-10(28)6-14(16)41-24(25)9-2-3-11(29)12(30)4-9/h2-6,8,15,17-18,20-23,26-33,35-38H,7H2,1H3/t8-,15+,17-,18+,20+,21-,22+,23+,26+,27-/m0/s1 +SMILES: C[C@H]1[C@@H]([C@H]([C@H]([C@@H](O1)OC[C@@H]2[C@H]([C@@H]([C@H]([C@@H](O2)OC3=C(OC4=CC(=CC(=C4C3=O)O)O)C5=CC(=C(C=C5)O)O)O)O)O)O)O)O +RETENTIONTIME: 0 +INSTRUMENTTYPE: LC-ESI-QTOF +INSTRUMENT: API QSTAR Pulsar i +IONMODE: Positive +LINKS: INCHIKEY:IKGXIBQEEMLURG-NVPNHPEKSA-N; KEGG:C05625; PUBCHEM:CID:5280805; COMPTOX:DTXSID3022326 +Comment: DB#=MSBNK-IPB_Halle-PB001341; origin=MassBank; IPB_RECORD: 541; Annotation confident structure +Splash: splash10-0wmi-0009506000-98ca7f7c8f3072af4481 +Num Peaks: 5 +147.063 121.684 +303.050 10000.000 +449.108 657.368 +465.102 5884.210 +611.161 6700.000 + +"""; + + @Test + public void testCreateConversionTaskRikenMSP() throws Exception { + String requestBody = "{ \"record_list\": [\"MSBNK-IPB_Halle-PB001341\"], \"format\": \"riken_msp\" }"; + + mockMvc.perform(post("/convert") + .contentType("application/json") + .content(requestBody)) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/octet-stream")) + .andExpect(content().string(riken_msp)); } } \ No newline at end of file