diff --git a/pom.xml b/pom.xml index e512503..b05e565 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ io.jenkins.tools.bom bom-${jenkins.baseline}.x - 3944.v1a_e4f8b_452db_ + 4136.vca_c3202a_7fd1 import pom @@ -108,7 +108,6 @@ io.jenkins.plugins okhttp-api - 4.11.0-183.va_87fc7a_89810 io.jenkins.plugins @@ -124,7 +123,6 @@ org.jenkins-ci.plugins antisamy-markup-formatter - 173.v680e3a_b_69ff3 true diff --git a/src/test/java/io/jenkins/plugins/restlistparam/RestValueServiceTest.java b/src/test/java/io/jenkins/plugins/restlistparam/RestValueServiceTest.java index 2536abb..56b266a 100644 --- a/src/test/java/io/jenkins/plugins/restlistparam/RestValueServiceTest.java +++ b/src/test/java/io/jenkins/plugins/restlistparam/RestValueServiceTest.java @@ -5,17 +5,22 @@ import io.jenkins.plugins.restlistparam.model.ValueItem; import io.jenkins.plugins.restlistparam.model.ResultContainer; import io.jenkins.plugins.restlistparam.model.ValueOrder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + // Task for later: more unit tests here (preferably replace integration tests) -public class RestValueServiceTest { +class RestValueServiceTest { + @Test - public void successfulGetIntegrationTest() { + void successfulGetIntegrationTest() { ResultContainer> test = RestValueService - .get("http://api.github.com/repos/jellyfin/jellyfin/tags?per_page=3", + .get("https://api.github.com/repos/jellyfin/jellyfin/tags?per_page=3", null, MimeType.APPLICATION_JSON, 0, @@ -23,12 +28,12 @@ public void successfulGetIntegrationTest() { "$", null, ValueOrder.NONE); - Assert.assertFalse(test.getErrorMsg().isPresent()); - Assert.assertEquals(3, test.getValue().size()); + assertFalse(test.getErrorMsg().isPresent()); + assertEquals(3, test.getValue().size()); } @Test - public void unsuccessfulGetIntegrationTest() { + void unsuccessfulGetIntegrationTest() { ResultContainer> test = RestValueService .get("https://gitlab.example.com/api/v4/projects/gitlab-org%2Fgitlab-runner/releases", null, @@ -38,8 +43,8 @@ public void unsuccessfulGetIntegrationTest() { "$", null, ValueOrder.NONE); - Assert.assertNotNull(test); - Assert.assertTrue(test.getErrorMsg().isPresent()); - Assert.assertEquals(0, test.getValue().size()); + assertNotNull(test); + assertTrue(test.getErrorMsg().isPresent()); + assertEquals(0, test.getValue().size()); } } diff --git a/src/test/java/io/jenkins/plugins/restlistparam/TestConst.java b/src/test/java/io/jenkins/plugins/restlistparam/TestConst.java index 752a2e9..246050c 100644 --- a/src/test/java/io/jenkins/plugins/restlistparam/TestConst.java +++ b/src/test/java/io/jenkins/plugins/restlistparam/TestConst.java @@ -1,188 +1,203 @@ package io.jenkins.plugins.restlistparam; public class TestConst { - public static final String validTestJson = "[\n" + - " {\n" + - " \"name\": \"v10.6.4\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4\",\n" + - " \"commit\": {\n" + - " \"sha\": \"b49cd1d3017f23fc75703829ac2ea1d45d8a4881\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40\"\n" + - " },\n" + - " {\n" + - " \"name\": \"v10.6.3\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3\",\n" + - " \"commit\": {\n" + - " \"sha\": \"16e3bd094f4c7c1b485ef164bf0a32267b7542c0\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z\"\n" + - " },\n" + - " {\n" + - " \"name\": \"v10.6.2\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2\",\n" + - " \"commit\": {\n" + - " \"sha\": \"973fcdbaa11002b5d110bb45d09e7bf218bc3611\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y\"\n" + - " }\n" + - "]\n"; + public static final String validTestJson = """ + [ + { + "name": "v10.6.4", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4", + "commit": { + "sha": "b49cd1d3017f23fc75703829ac2ea1d45d8a4881", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40" + }, + { + "name": "v10.6.3", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3", + "commit": { + "sha": "16e3bd094f4c7c1b485ef164bf0a32267b7542c0", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z" + }, + { + "name": "v10.6.2", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2", + "commit": { + "sha": "973fcdbaa11002b5d110bb45d09e7bf218bc3611", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y" + } + ] + """; - public static final String numberLikeTestJson = "[\n" + - " {\n" + - " \"name\": \"2024.19\",\n" + - " },\n" + - " {\n" + - " \"name\": \"2024.20\",\n" + - " },\n" + - " {\n" + - " \"name\": \"2024.0\",\n" + - " }\n" + - "]\n"; + public static final String numberLikeTestJson = """ + [ + { + "name": "2024.19", + }, + { + "name": "2024.20", + }, + { + "name": "2024.0", + } + ] + """; - public static final String numberValuesTestJson = "[\n" + - " {\n" + - " \"value\": 1.0\n" + - " },\n" + - " {\n" + - " \"value\": 10\n" + - " },\n" + - " {\n" + - " \"value\": 11.50\n" + - " }\n" + - "]\n"; + public static final String numberValuesTestJson = """ + [ + { + "value": 1.0 + }, + { + "value": 10 + }, + { + "value": 11.50 + } + ] + """; - public static final String mixedTypeValuesTestJson = "[\n" + - " {\n" + - " \"value\": 1.0\n" + - " },\n" + - " {\n" + - " \"value\": 10\n" + - " },\n" + - " {\n" + - " \"value\": \"11.50\"\n" + - " },\n" + - " {\n" + - " \"value\": true\n" + - " },\n" + - " {\n" + - " \"value\": false\n" + - " }\n" + - "]\n"; + public static final String mixedTypeValuesTestJson = """ + [ + { + "value": 1.0 + }, + { + "value": 10 + }, + { + "value": "11.50" + }, + { + "value": true + }, + { + "value": false + } + ] + """; - public static final String validJsonValueItem = "{" + - "\"name\":\"v10.6.4\"," + - "\"zipball_url\":\"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4\"," + - "\"tarball_url\":\"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4\"," + - "\"commit\":{" + - "\"sha\":\"b49cd1d3017f23fc75703829ac2ea1d45d8a4881\"," + - "\"url\":\"https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881\"" + - "}," + - "\"node_id\":\"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40\"" + - "}"; + public static final String validJsonValueItem = """ + { + "name": "v10.6.4", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4", + "commit": { + "sha": "b49cd1d3017f23fc75703829ac2ea1d45d8a4881", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40" + } + """; - public static final String invalidTestJson = "[\n" + - " {\n" + - " \"name\": \"v10.6.4\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4\",\n" + - " \"commit\": {\n" + - " \"sha\": \"b49cd1d3017f23fc75703829ac2ea1d45d8a4881\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40\"\n" + - " },\n" + - " {\n" + - " \"name\": \"v10.6.3\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3\",\n" + - " \"commit\": {\n" + - " \"sha\": \"16e3bd094f4c7c1b485ef164bf0a32267b7542c0\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z\"\n" + - " },\n" + - " {\n" + - " \"name\": \"v10.6.2\",\n" + - " \"zipball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2\",\n" + - " \"tarball_url\": \"https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2\",\n" + - " \"commit\": {\n" + - " \"sha\": \"973fcdbaa11002b5d110bb45d09e7bf218bc3611\",\n" + - " \"url\": \"https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611\"\n" + - " },\n" + - " \"node_id\": \"MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y\"\n" + - " }\n"; + public static final String invalidTestJson = """ + [ + { + "name": "v10.6.4", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4", + "commit": { + "sha": "b49cd1d3017f23fc75703829ac2ea1d45d8a4881", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40" + }, + { + "name": "v10.6.3", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3", + "commit": { + "sha": "16e3bd094f4c7c1b485ef164bf0a32267b7542c0", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z" + }, + { + "name": "v10.6.2", + "zipball_url": "https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2", + "tarball_url": "https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2", + "commit": { + "sha": "973fcdbaa11002b5d110bb45d09e7bf218bc3611", + "url": "https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611" + }, + "node_id": "MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y" + } + """; - public static final String validTestXml = "\n" + - "\n" + - " \n" + - " v10.6.4\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4\n" + - " \n" + - " b49cd1d3017f23fc75703829ac2ea1d45d8a4881\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40\n" + - " \n" + - " \n" + - " v10.6.3\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3\n" + - " \n" + - " 16e3bd094f4c7c1b485ef164bf0a32267b7542c0\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z\n" + - " \n" + - " \n" + - " v10.6.2\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2\n" + - " \n" + - " 973fcdbaa11002b5d110bb45d09e7bf218bc3611\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y\n" + - " \n" + - ""; + public static final String validTestXml = """ + + + + v10.6.4 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4 + + b49cd1d3017f23fc75703829ac2ea1d45d8a4881 + https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40 + + + v10.6.3 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3 + + 16e3bd094f4c7c1b485ef164bf0a32267b7542c0 + https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z + + + v10.6.2 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2 + + 973fcdbaa11002b5d110bb45d09e7bf218bc3611 + https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y + + """; - public static final String invalidTestXml = "\n" + - "\n" + - " \n" + - " v10.6.4\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4\n" + - " \n" + - " b49cd1d3017f23fc75703829ac2ea1d45d8a4881\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40\n" + - " \n" + - " \n" + - " v10.6.3\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3\n" + - " \n" + - " 16e3bd094f4c7c1b485ef164bf0a32267b7542c0\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z\n" + - " \n" + - " \n" + - " v10.6.2\n" + - " https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2\n" + - " https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2\n" + - " \n" + - " 973fcdbaa11002b5d110bb45d09e7bf218bc3611\n" + - " https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611\n" + - " \n" + - " MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y\n" + - " \n"; + public static final String invalidTestXml = """ + + + + v10.6.4 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.4 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.4 + + b49cd1d3017f23fc75703829ac2ea1d45d8a4881 + https://api.github.com/repos/jellyfin/jellyfin/commits/b49cd1d3017f23fc75703829ac2ea1d45d8a4881 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi40 + + + v10.6.3 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.3 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.3 + + 16e3bd094f4c7c1b485ef164bf0a32267b7542c0 + https://api.github.com/repos/jellyfin/jellyfin/commits/16e3bd094f4c7c1b485ef164bf0a32267b7542c0 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4z + + + v10.6.2 + https://api.github.com/repos/jellyfin/jellyfin/zipball/v10.6.2 + https://api.github.com/repos/jellyfin/jellyfin/tarball/v10.6.2 + + 973fcdbaa11002b5d110bb45d09e7bf218bc3611 + https://api.github.com/repos/jellyfin/jellyfin/commits/973fcdbaa11002b5d110bb45d09e7bf218bc3611 + + MDM6UmVmMTYxMDEyMDE5OnJlZnMvdGFncy92MTAuNi4y + + """; } diff --git a/src/test/java/io/jenkins/plugins/restlistparam/ValueResolverTest.java b/src/test/java/io/jenkins/plugins/restlistparam/ValueResolverTest.java index b80fb8e..9e96d11 100644 --- a/src/test/java/io/jenkins/plugins/restlistparam/ValueResolverTest.java +++ b/src/test/java/io/jenkins/plugins/restlistparam/ValueResolverTest.java @@ -5,153 +5,157 @@ import io.jenkins.plugins.restlistparam.model.MimeType; import io.jenkins.plugins.restlistparam.model.ResultContainer; import io.jenkins.plugins.restlistparam.model.ValueItem; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.util.HashMap; import java.util.List; -public class ValueResolverTest { +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ValueResolverTest { // Json-Path Tests @Test - public void resolveJsonPathTest() { + void resolveJsonPathTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.validTestJson, "$.*.name", "$"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(3, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(3, res.getValue().size()); + assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, res.getValue().stream().map(ValueItem::getValue).toArray()); - Assert.assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, + assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, res.getValue().stream().map(ValueItem::getDisplayValue).toArray()); } @Test - public void resolveJsonPathNumberLikeValuesTest() { + void resolveJsonPathNumberLikeValuesTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.numberLikeTestJson, "$.*.name", "$"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(3, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"2024.19", "2024.20", "2024.0"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(3, res.getValue().size()); + assertArrayEquals(new String[]{"2024.19", "2024.20", "2024.0"}, res.getValue().stream().map(ValueItem::getValue).toArray()); - Assert.assertArrayEquals(new String[]{"2024.19", "2024.20", "2024.0"}, + assertArrayEquals(new String[]{"2024.19", "2024.20", "2024.0"}, res.getValue().stream().map(ValueItem::getDisplayValue).toArray()); } @Test - public void resolveJsonPathNumberValuesTest() { + void resolveJsonPathNumberValuesTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.numberValuesTestJson, "$.*.value", "$"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(3, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"1.0", "10", "11.5"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(3, res.getValue().size()); + assertArrayEquals(new String[]{"1.0", "10", "11.5"}, res.getValue().stream().map(ValueItem::getValue).toArray()); // trailing 0 and decimal points are shaved off numbers by JSONStringer - Assert.assertArrayEquals(new String[]{"1", "10", "11.5"}, + assertArrayEquals(new String[]{"1", "10", "11.5"}, res.getValue().stream().map(ValueItem::getDisplayValue).toArray()); } @Test - public void resolveJsonPathMixedTypeValuesTest() { + void resolveJsonPathMixedTypeValuesTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.mixedTypeValuesTestJson, "$.*.value", "$"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(5, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"1.0", "10", "11.50", "true", "false"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(5, res.getValue().size()); + assertArrayEquals(new String[]{"1.0", "10", "11.50", "true", "false"}, res.getValue().stream().map(ValueItem::getValue).toArray()); // trailing 0 and decimal points are shaved off numbers by JSONStringer - Assert.assertArrayEquals(new String[]{"1", "10", "11.50", "true", "false"}, + assertArrayEquals(new String[]{"1", "10", "11.50", "true", "false"}, res.getValue().stream().map(ValueItem::getDisplayValue).toArray()); } @Test - public void resolveJsonPathWithDifferentDisplayExpressionTest() { + void resolveJsonPathWithDifferentDisplayExpressionTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.validTestJson, "$.*", "$.name"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(3, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(3, res.getValue().size()); + assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, res.getValue().stream().map(ValueItem::getValue).map(JsonPath::parse).map(context -> context.read("$.name")).toArray()); - Assert.assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, + assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, res.getValue().stream().map(ValueItem::getDisplayValue).toArray()); } @Test - public void emptyJsonPathResultsTest() { + void emptyJsonPathResultsTest() { ResultContainer> res = ValueResolver.resolveJsonPath("[]", "$.*", "$"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void resolveJsonPathError1Test() { + void resolveJsonPathError1Test() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.validTestJson, "$.", "$"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void resolveJsonPathError2Test() { + void resolveJsonPathError2Test() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.validTestJson, "$.name", "$"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void invalidJsonErrorTest() { + void invalidJsonErrorTest() { ResultContainer> res = ValueResolver.resolveJsonPath(TestConst.invalidTestJson, "$.*.name", "$"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void displayJsonValueFuncTest() { + void displayJsonValueFuncTest() { String displayValue = ValueResolver.parseDisplayValue(MimeType.APPLICATION_JSON, TestConst.validJsonValueItem, "$.name"); - Assert.assertEquals("v10.6.4", displayValue); + assertEquals("v10.6.4", displayValue); } // xPath Tests @Test - public void resolveXPathTest() { + void resolveXPathTest() { ResultContainer> res = ValueResolver.resolveXPath(TestConst.validTestXml, "//row/name", "/"); - Assert.assertNotNull(res); - Assert.assertFalse(res.getErrorMsg().isPresent()); - Assert.assertEquals(3, res.getValue().size()); - Assert.assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, + assertNotNull(res); + assertFalse(res.getErrorMsg().isPresent()); + assertEquals(3, res.getValue().size()); + assertArrayEquals(new String[]{"v10.6.4", "v10.6.3", "v10.6.2"}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void emptyXPathResultTest() { + void emptyXPathResultTest() { ResultContainer> res = ValueResolver.resolveXPath(TestConst.validTestXml, "//row_name", "/"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void resolveXPathErrorTest() { + void resolveXPathErrorTest() { ResultContainer> res = ValueResolver.resolveXPath(TestConst.validTestXml, "\\row_name", "/"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } @Test - public void invalidXMLErrorTest() { + void invalidXMLErrorTest() { ResultContainer> res = ValueResolver.resolveXPath(TestConst.invalidTestXml, "//row/name", "/"); - Assert.assertNotNull(res); - Assert.assertTrue(res.getErrorMsg().isPresent()); - Assert.assertEquals(0, res.getValue().size()); - Assert.assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); + assertNotNull(res); + assertTrue(res.getErrorMsg().isPresent()); + assertEquals(0, res.getValue().size()); + assertArrayEquals(new String[]{}, res.getValue().stream().map(ValueItem::getValue).toArray()); } }