From 0bc6a8f40ebd99f2df5fdd0d45d3a88cfb3fbef3 Mon Sep 17 00:00:00 2001 From: rodche Date: Sat, 1 Oct 2022 00:18:39 -0400 Subject: [PATCH] Refs #32: - removed .travis; - fixed gradle build (jdk-17, but java8 compatible; - updated github workflow; - there's no need to build the server using jdk-8 or jdk-11 anymore; - using Spring Boot 2.5.0 (later versions conflicts with old Swagger2 lib) --- .github/workflows/Build.yml | 15 ++-- .travis.yml | 7 -- build.gradle | 21 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/factoid/web/Controller.java | 7 +- .../converter/BiopaxToFactoidTest.java | 10 +-- .../converter/FactoidToBiopaxTest.java | 2 +- src/test/java/factoid/converter/Simplify.java | 4 - .../java/factoid/model/BioPAXModelTest.java | 74 +++++++------------ src/test/java/factoid/web/ControllerT.java | 27 ++++--- 10 files changed, 64 insertions(+), 105 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 3e99a33..6b40661 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -15,23 +15,22 @@ on: jobs: build: runs-on: ubuntu-latest - - name: Java ${{ matrix.config.java }} + +# env: +# _JAVA_OPTIONS: "--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED" + + name: Build with Gradle strategy: fail-fast: false - matrix: - config: - - {java: 8} - - {java: 11} steps: - uses: actions/checkout@v2 - name: Set up JDK uses: actions/setup-java@v2 with: - java-version: ${{ matrix.config.java }} - distribution: 'adopt' + java-version: 17 + distribution: 'temurin' cache: gradle - name: Build with Gradle run: | diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9bf24e4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -sudo: false -script: ./gradlew build -jdk: - - openjdk8 - - openjdk11 -notifications: - slack: pathwaycommons:EDRQfFuGFr8Xn93M5xNMPVRB diff --git a/build.gradle b/build.gradle index 4af359c..66ef44c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - springBootVersion = '2.2.6.RELEASE' + springBootVersion = '2.5.0' } repositories { maven { @@ -23,7 +23,7 @@ repositories { url "https://oss.sonatype.org/content/groups/public/" } maven { - url "https://www.biopax.org/m2repo/releases/" + url "https://jitpack.io" } } @@ -32,19 +32,18 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' runtimeOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' - implementation 'org.biopax.paxtools:sbgn-converter:5.2.1-SNAPSHOT' - implementation 'com.google.code.gson:gson:2.8.2' - implementation 'org.apache.commons:commons-collections4:4.1' + implementation 'org.biopax.paxtools:sbgn-converter:5.3.0-SNAPSHOT' + implementation 'com.google.code.gson:gson:2.9.0' + implementation 'org.apache.commons:commons-collections4:4.4' implementation 'io.springfox:springfox-swagger2:2.7.0' implementation 'io.springfox:springfox-swagger-ui:2.7.0' - //java 9+ does not have Jax B Dependents - implementation 'javax.xml.bind:jaxb-api:2.3.0' - implementation 'com.sun.xml.bind:jaxb-core:2.3.0' - implementation 'com.sun.xml.bind:jaxb-impl:2.3.0' + implementation 'javax.xml.bind:jaxb-api:2.3.1' + implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1' + implementation 'com.sun.xml.bind:jaxb-impl:2.3.6' implementation 'javax.activation:activation:1.1.1' } -sourceCompatibility = 1.8 +sourceCompatibility = 8 group = 'pathwaycommons' -version = '0.4.0' +version = '0.2.2' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6623300..8fad3f5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/factoid/web/Controller.java b/src/main/java/factoid/web/Controller.java index 53c96f6..c8bc35e 100644 --- a/src/main/java/factoid/web/Controller.java +++ b/src/main/java/factoid/web/Controller.java @@ -37,10 +37,7 @@ public class Controller { produces = "application/vnd.biopax.rdf+xml" ) public String jsonToBiopax( - @ApiParam("Factoid document content (JSON string)") @RequestBody String body - //TODO: add url/path options as needed -// , @ApiParam("test") @RequestParam(required = false) String test - ) { + @ApiParam("Factoid document content (JSON string)") @RequestBody String body) { // Add templates to converter by the reader FactoidToBiopax converter = new FactoidToBiopax(); try { @@ -107,7 +104,7 @@ public String biopaxToFactoid( BiopaxToFactoid converter = new BiopaxToFactoid(); try { InputStream is = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8)); - Model model = new SimpleIOHandler().convertFromOWL(is); + Model model = new SimpleIOHandler().convertFromOWL(is); return converter.convert(model).toString(); } catch (IllegalStateException | JsonSyntaxException | JsonIOException e) { throw new ConverterException(HttpStatus.BAD_REQUEST, e.getMessage()); diff --git a/src/test/java/factoid/converter/BiopaxToFactoidTest.java b/src/test/java/factoid/converter/BiopaxToFactoidTest.java index cdb92e4..a3aff33 100644 --- a/src/test/java/factoid/converter/BiopaxToFactoidTest.java +++ b/src/test/java/factoid/converter/BiopaxToFactoidTest.java @@ -1,9 +1,5 @@ package factoid.converter; - -import static org.junit.Assert.assertThat; -import static org.hamcrest.Matchers.*; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -16,12 +12,14 @@ import org.biopax.paxtools.io.BioPAXIOHandler; import org.biopax.paxtools.io.SimpleIOHandler; import org.biopax.paxtools.model.Model; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class BiopaxToFactoidTest { @Test @@ -49,7 +47,7 @@ public void testToJson() throws IOException { } } - assertThat(entityIds1, is(entityIds2)); + assertEquals(entityIds1, entityIds2); } diff --git a/src/test/java/factoid/converter/FactoidToBiopaxTest.java b/src/test/java/factoid/converter/FactoidToBiopaxTest.java index a1ff31d..212e9c5 100644 --- a/src/test/java/factoid/converter/FactoidToBiopaxTest.java +++ b/src/test/java/factoid/converter/FactoidToBiopaxTest.java @@ -13,7 +13,7 @@ import org.biopax.paxtools.model.*; import org.biopax.paxtools.model.level3.*; import org.biopax.paxtools.model.level3.Process; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.FileReader; diff --git a/src/test/java/factoid/converter/Simplify.java b/src/test/java/factoid/converter/Simplify.java index 08a682d..184f686 100644 --- a/src/test/java/factoid/converter/Simplify.java +++ b/src/test/java/factoid/converter/Simplify.java @@ -32,10 +32,6 @@ import org.biopax.paxtools.model.level3.ProteinReference; import org.biopax.paxtools.model.level3.SimplePhysicalEntity; import org.biopax.paxtools.model.level3.TemplateReactionRegulation; -import org.biopax.paxtools.model.level3.Xref; - -import com.google.common.io.Resources; -import com.sun.xml.bind.v2.model.core.Element; public class Simplify { public static void main(String[] args) throws FileNotFoundException { diff --git a/src/test/java/factoid/model/BioPAXModelTest.java b/src/test/java/factoid/model/BioPAXModelTest.java index 8861d90..de632ea 100644 --- a/src/test/java/factoid/model/BioPAXModelTest.java +++ b/src/test/java/factoid/model/BioPAXModelTest.java @@ -1,8 +1,8 @@ package factoid.model; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashSet; import java.util.Set; @@ -15,7 +15,7 @@ import org.biopax.paxtools.model.level3.Protein; import org.biopax.paxtools.model.level3.ProteinReference; import org.biopax.paxtools.model.level3.SmallMoleculeReference; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class BioPAXModelTest { @@ -40,21 +40,21 @@ public void addPhysicalEntityTest() throws NoSuchFieldException, SecurityExcepti Protein prot1 = model.getOrCreatePhysicalEntity(Protein.class, protName, protRef, modificationTypes, null); - assertTrue("Protein is added to the model", innerModel.contains(prot1)); - assertEquals("Protein name is set", prot1.getDisplayName(), protName); - assertEquals("Protein reference is set", protRef, prot1.getEntityReference()); - assertEquals("Protein modification types are set", modificationTypes.size(), prot1.getFeature().size()); - assertEquals("Protein reference has a new modification", 1, protRef.getEntityFeature().size()); + assertTrue(innerModel.contains(prot1), "Protein is added to the model"); + assertEquals(prot1.getDisplayName(), protName, "Protein name is set"); + assertEquals(protRef, prot1.getEntityReference(), "Protein reference is set"); + assertEquals(modificationTypes.size(), prot1.getFeature().size(), "Protein modification types are set"); + assertEquals(1, protRef.getEntityFeature().size(), "Protein reference has a new modification"); Protein prot2 = model.getOrCreatePhysicalEntity(Protein.class, protName, protRef, modificationTypes, null); - assertEquals("No duplication in adding the second Protein with same features", prot1, prot2); + assertEquals(prot1, prot2, "No duplication in adding the second Protein with same features"); Protein prot3 = model.getOrCreatePhysicalEntity(Protein.class, protName, protRef); - assertNotEquals("A new protein is added with no modification", prot1, prot3); + assertNotEquals(prot1, prot3, "A new protein is added with no modification"); Protein prot4 = model.getOrCreatePhysicalEntity(Protein.class, protName, protRef, modificationTypes2, null); - assertNotEquals("A new protein is added with with different modifications", prot1, prot4); - assertEquals("Protein reference has a new modification", 2, protRef.getEntityFeature().size()); + assertNotEquals(prot1, prot4, "A new protein is added with with different modifications"); + assertEquals(2, protRef.getEntityFeature().size(), "Protein reference has a new modification"); } @Test @@ -72,41 +72,19 @@ public void addEntityReferenceTest() { XrefModel commonXref = new XrefModel("common-xref", "uniprot"); ProteinReference protRef1 = model.getOrCreateEntityReference(ProteinReference.class, commonName, commonXref); - assertTrue("Protein reference is added to the model", innerModel.contains(protRef1)); - assertEquals("Protein reference name is set", commonName, protRef1.getDisplayName()); + assertTrue(innerModel.contains(protRef1), "Protein reference is added to the model"); + assertEquals(commonName, protRef1.getDisplayName(), "Protein reference name is set"); ProteinReference protRef2 = model.getOrCreateEntityReference(ProteinReference.class, commonName, commonXref); - assertEquals("No duplication in adding second protein modification with same name", protRef1, protRef2); + assertEquals(protRef1, protRef2, "No duplication in adding second protein modification with same name"); SmallMoleculeReference smRef = model.getOrCreateEntityReference(SmallMoleculeReference.class, commonName, commonXref); - assertNotEquals("A new small molecule reference is added that has an existing protein reference name", protRef2, smRef); + assertNotEquals(protRef2, smRef, "A new small molecule reference is added that has an existing protein reference name"); ProteinReference protRef3 = model.getOrCreateEntityReference(ProteinReference.class, uniqueName, commonXref); - assertNotEquals("A new protein is added with a new name", protRef1, protRef3); + assertNotEquals(protRef1, protRef3, "A new protein is added with a new name"); } -// @Test -// public void addCellularLocationVocabularyTest() { -// -// BioPAXModel model = new BioPAXModel(); -// -// // Underlying PAXTools model -// Model innerModel = model.getPaxtoolsModel(); -// -// String commonLocationName = "location1"; -// String uniqueLocationName = "location2"; -// -// CellularLocationVocabulary clv1 = model.getOrCreateCellularLocationVocabulary(commonLocationName); -// assertTrue("Cellular location vocabulary is added to the model", innerModel.contains(clv1)); -// assertEquals("Cellular location vocabulary has the name", 1, clv1.getTerm().size()); -// -// CellularLocationVocabulary clv2 = model.getOrCreateCellularLocationVocabulary(commonLocationName); -// assertEquals("No duplication in adding the second cellular location with the same name", clv1, clv2); -// -// CellularLocationVocabulary clv3 = model.getOrCreateCellularLocationVocabulary(uniqueLocationName); -// assertNotEquals("A new cellular location is added with a new name", clv1, clv3); -// } - @Test public void addConversionTest() { @@ -120,10 +98,10 @@ public void addConversionTest() { Protein right = model.addNew(Protein.class); Conversion conversion = model.addNewConversion(Conversion.class, left, right, dir); - assertTrue("Conversion is added to the model", innerModel.contains(conversion)); - assertTrue("Coversions left side is set", conversion.getLeft().contains(left)); - assertTrue("Coversions right side is set", conversion.getRight().contains(right)); - assertEquals("Conversion direction is set", dir, conversion.getConversionDirection()); + assertTrue(innerModel.contains(conversion), "Conversion is added to the model"); + assertTrue(conversion.getLeft().contains(left), "Coversions left side is set"); + assertTrue(conversion.getRight().contains(right), "Coversions right side is set"); + assertEquals(dir, conversion.getConversionDirection(), "Conversion direction is set"); } @Test @@ -142,10 +120,10 @@ public void addControlTest() { Control control = model.addNewControl(Control.class, controller, controlled, controlType); - assertTrue("Control is added to the model", innerModel.contains(control)); - assertTrue("Controller is set", control.getController().contains(controller)); - assertTrue("Controlled is set", control.getControlled().contains(controlled)); - assertEquals("Control type is set", controlType, control.getControlType()); + assertTrue(innerModel.contains(control), "Control is added to the model"); + assertTrue(control.getController().contains(controller), "Controller is set"); + assertTrue(control.getControlled().contains(controlled), "Controlled is set"); + assertEquals(controlType, control.getControlType(), "Control type is set"); } } diff --git a/src/test/java/factoid/web/ControllerT.java b/src/test/java/factoid/web/ControllerT.java index 44f09c3..2745348 100644 --- a/src/test/java/factoid/web/ControllerT.java +++ b/src/test/java/factoid/web/ControllerT.java @@ -1,7 +1,7 @@ package factoid.web; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -9,18 +9,16 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @Import(Application.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class ControllerT { @@ -36,7 +34,7 @@ public void testJsonToBiopax() throws IOException { HttpEntity request = new HttpEntity<>(data, headers); String res = template.postForObject("/v2/json-to-biopax", request, String.class); assertNotNull(res); - assertThat(res, containsString("biopax-level3.owl#")); + assertTrue(res.contains("biopax-level3.owl#")); } @Test @@ -47,7 +45,7 @@ public void testJsonToSbgn() throws IOException { HttpEntity request = new HttpEntity<>(data, headers); String res = template.postForObject("/v2/json-to-sbgn", request, String.class); assertNotNull(res); - assertThat(res, containsString("http://sbgn.org/libsbgn/")); + assertTrue(res.contains("http://sbgn.org/libsbgn/")); } @Test @@ -58,7 +56,7 @@ public void testBiopaxToSbgn() throws IOException { HttpEntity request = new HttpEntity<>(data, headers); String res = template.postForObject("/v2/biopax-to-sbgn", request, String.class); assertNotNull(res); - assertThat(res, containsString("http://sbgn.org/libsbgn/")); + assertTrue(res.contains("http://sbgn.org/libsbgn/")); } @Test @@ -68,8 +66,10 @@ public void testBiopaxToFactoid() throws IOException { headers.set("Content-Type", "application/vnd.biopax.rdf+xml"); HttpEntity request = new HttpEntity<>(data, headers); String res = template.postForObject("/v2/biopax-to-json", request, String.class); - assertNotNull(res); - assertThat(res, containsString("interaction")); + assertAll( + () -> assertNotNull(res), + () -> assertTrue(res.contains("interaction")) + ); } @Test @@ -80,7 +80,6 @@ public void testBiopaxUrlToFactoid() throws IOException { HttpEntity request = new HttpEntity<>(url, headers); String res = template.postForObject("/v2/biopax-url-to-json", request, String.class); assertNotNull(res); - // this line works fine with unit tests but weirdly blocking the build so commented it out for now. -// assertThat(res, containsString("interaction")); + assertTrue(res.contains("interaction")); } }