Skip to content

Commit 3fed4ad

Browse files
committed
Add first version of /validate endpoint and tests.
1 parent 1a807dd commit 3fed4ad

4 files changed

Lines changed: 132 additions & 7 deletions

File tree

pom.xml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@
108108
</dependency>
109109
<dependency>
110110
<groupId>org.testcontainers</groupId>
111-
<artifactId>postgresql</artifactId>
112-
<version>1.21.3</version>
111+
<artifactId>testcontainers</artifactId>
113112
<scope>test</scope>
114113
</dependency>
115114
<dependency>
116115
<groupId>org.testcontainers</groupId>
117-
<artifactId>junit-jupiter</artifactId>
118-
<version>1.21.3</version>
116+
<artifactId>testcontainers-junit-jupiter</artifactId>
117+
<scope>test</scope>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.testcontainers</groupId>
121+
<artifactId>testcontainers-postgresql</artifactId>
119122
<scope>test</scope>
120123
</dependency>
121124
</dependencies>
@@ -133,8 +136,15 @@
133136
<groupId>org.apache.logging.log4j</groupId>
134137
<artifactId>log4j-bom</artifactId>
135138
<version>2.25.2</version>
139+
<type>pom</type>
136140
<scope>import</scope>
141+
</dependency>
142+
<dependency>
143+
<groupId>org.testcontainers</groupId>
144+
<artifactId>testcontainers-bom</artifactId>
145+
<version>2.0.2</version>
137146
<type>pom</type>
147+
<scope>import</scope>
138148
</dependency>
139149
</dependencies>
140150
</dependencyManagement>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package massbank_export_api.api;
2+
3+
import massbank.RecordParser;
4+
import org.petitparser.context.Result;
5+
import org.springframework.context.annotation.Primary;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.HashSet;
11+
12+
@Primary
13+
@Service
14+
public class ValidateApiDelegateImpl implements ValidateApiDelegate {
15+
16+
final RecordParser recordparser = new RecordParser(new HashSet<>());
17+
18+
@Override
19+
public ResponseEntity<Void> validatePost(String body) {
20+
Result result = recordparser.parse(body);
21+
if (result.isSuccess()) return new ResponseEntity<>(HttpStatus.OK);
22+
else {
23+
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
24+
}
25+
}
26+
27+
}

src/test/java/massbank_export_api/ExportApiControllerTest.java

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import org.springframework.test.context.DynamicPropertyRegistry;
1010
import org.springframework.test.context.DynamicPropertySource;
1111
import org.springframework.test.web.servlet.MockMvc;
12-
import org.testcontainers.containers.PostgreSQLContainer;
1312
import org.testcontainers.junit.jupiter.Testcontainers;
13+
import org.testcontainers.postgresql.PostgreSQLContainer;
1414

1515
import java.io.InputStream;
1616
import java.util.ArrayList;
@@ -29,7 +29,7 @@
2929
@Testcontainers
3030
public class ExportApiControllerTest {
3131

32-
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(
32+
static final PostgreSQLContainer postgres = new PostgreSQLContainer(
3333
"postgres:17-alpine"
3434
);
3535

@@ -419,4 +419,92 @@ public void testGetRawtext() throws Exception {
419419
.andExpect(content().string(expectedResponse));
420420
}
421421

422+
@Test
423+
public void testValidation() throws Exception {
424+
String validRecord = """
425+
ACCESSION: MSBNK-IPB_Halle-PB001341
426+
RECORD_TITLE: Rutin; LC-ESI-QTOF; MS2; CE:10 eV; [M+H]+
427+
DATE: 2016.01.19 (Created 2008.05.22, modified 2013.06.04)
428+
AUTHORS: Boettcher C, Institute of Plant Biochemistry, Halle, Germany
429+
LICENSE: CC BY-SA
430+
COMMENT: IPB_RECORD: 541
431+
COMMENT: CONFIDENCE confident structure
432+
CH$NAME: Rutin
433+
CH$NAME: 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
434+
CH$COMPOUND_CLASS: Natural Product; Flavonol
435+
CH$FORMULA: C27H30O16
436+
CH$EXACT_MASS: 610.15338
437+
CH$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
438+
CH$IUPAC: 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
439+
CH$LINK: INCHIKEY IKGXIBQEEMLURG-NVPNHPEKSA-N
440+
CH$LINK: KEGG C05625
441+
CH$LINK: PUBCHEM CID:5280805
442+
CH$LINK: COMPTOX DTXSID3022326
443+
CH$LINK: ChemOnt CHEMONTID:0001111; Organic compounds; Phenylpropanoids and polyketides; Flavonoids; Flavonoid glycosides
444+
AC$INSTRUMENT: API QSTAR Pulsar i
445+
AC$INSTRUMENT_TYPE: LC-ESI-QTOF
446+
AC$MASS_SPECTROMETRY: MS_TYPE MS2
447+
AC$MASS_SPECTROMETRY: ION_MODE POSITIVE
448+
AC$MASS_SPECTROMETRY: COLLISION_ENERGY 10 eV
449+
AC$MASS_SPECTROMETRY: IONIZATION ESI
450+
MS$FOCUSED_ION: PRECURSOR_TYPE [M+H]+
451+
PK$SPLASH: splash10-0wmi-0009506000-98ca7f7c8f3072af4481
452+
PK$NUM_PEAK: 5
453+
PK$PEAK: m/z int. rel.int.
454+
147.063 121.684 11
455+
303.050 10000.000 999
456+
449.108 657.368 64
457+
465.102 5884.210 587
458+
611.161 6700.000 669
459+
//
460+
""";
461+
462+
String invalidRecord = """
463+
ACCESSION: MSBNK-IPB_Halle-PB001341
464+
RECORD_TITLE: Rutin; LC-ESI-QTOF; MS2; CE:10 eV; [M+H]+
465+
DATE: 2016.01.19 (Created 2008.05.22, modified 2013.06.04)
466+
AUTHORS: Boettcher C, Institute of Plant Biochemistry, Halle, Germany
467+
LICENSE: CC BY-SA
468+
COMMENT: IPB_RECORD: 541
469+
COMMENT: CONFIDENCE confident structure
470+
CH$NAME: Rutin
471+
CH$NAME: 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
472+
CH$COMPOUND_CLASS: Natural Product; Flavonol
473+
CH$FORMULA: C27H30O16
474+
CH$EXACT_MASS: 610.15338
475+
CH$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
476+
CH$IUPAC: 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
477+
CH$LINK: INCHIKEY IKGXIBQEEMLURG-NVPNHPEKSA-N
478+
CH$LINK: KEGG C05625
479+
CH$LINK: PUBCHEM CID:5280805
480+
CH$LINK: COMPTOX DTXSID3022326
481+
CH$LINK: ChemOnt CHEMONTID:0001111; Organic compounds; Phenylpropanoids and polyketides; Flavonoids; Flavonoid glycosides
482+
AC$INSTRUMENT: API QSTAR Pulsar i
483+
AC$INSTRUMENT_TYPE: LC-ESI-QTOF
484+
AC$MASS_SPECTROMETRY: MS_TYPE MS2
485+
AC$MASS_SPECTROMETRY: ION_MODE POSITIVE
486+
AC$MASS_SPECTROMETRY: COLLISION_ENERGY 10 eV
487+
AC$MASS_SPECTROMETRY: IONIZATION ESI
488+
MS$FOCUSED_ION: PRECURSOR_TYPE [M+H]+
489+
PK$SPLASH: splash10-0wmi-0009506000-98ca7f7c8f3072af4481
490+
PK$NUM_PEAK: 5
491+
PK$PEAK: m/z int. rel.int.
492+
147.063 121.684 11
493+
303.050 10000.000 999
494+
449.108 657.368 64
495+
465.102 5884.210 587
496+
611.161 6700.000 669
497+
//
498+
""";
499+
mockMvc.perform(post("/validate")
500+
.contentType("text/plain")
501+
.content(validRecord))
502+
.andExpect(status().isOk());
503+
504+
mockMvc.perform(post("/validate")
505+
.contentType("text/plain")
506+
.content(invalidRecord))
507+
.andExpect(status().isUnprocessableEntity());
508+
}
509+
422510
}

src/test/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ DATA_DIRECTORY=${MB_DATA_DIRECTORY:src/test/resources/MassBank-data-test}
1212
# Database-specific configuration
1313
spring.datasource.driver-class-name=org.postgresql.Driver
1414

15-
spring.jpa.hibernate.ddl-auto=create-drop
15+
spring.jpa.hibernate.ddl-auto=create
1616
spring.jpa.properties.hibernate.format_sql=true
1717
logging.level.sql=warn

0 commit comments

Comments
 (0)