diff --git a/CHANGELOG.md b/CHANGELOG.md index 75be326..362b929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [11.2.1] - 2023-11-16 + +**Breaking Change:** If you use the EngineUrl#path method with a query parameter, an IllegalArgumentException will be thrown. +Please use the EngineUrl#queryParam method instead. + ## [11.2.0] - 2023-11-15 ### Added diff --git a/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/EngineUrl.java b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/EngineUrl.java index 421aa9e..12ca7f7 100644 --- a/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/EngineUrl.java +++ b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/EngineUrl.java @@ -20,6 +20,8 @@ import javax.ws.rs.core.UriBuilder; +import org.apache.commons.lang3.StringUtils; + /** * This is a Util to build URLs against the designer (localhost:8081) or a test * engine. @@ -75,23 +77,28 @@ public static EngineUrl create() { } public static String createProcessUrl(String path) { - return create().process(path).toUrl(); + var parts = splitQueryFromPath(path); + return create().process(parts.path).toUrl() + parts.query; } public static String createRestUrl(String path) { - return create().rest(path).toUrl(); + var parts = splitQueryFromPath(path); + return create().rest(parts.path).toUrl() + parts.query; } public static String createWebServiceUrl(String path) { - return create().webService(path).toUrl(); + var parts = splitQueryFromPath(path); + return create().webService(parts.path).toUrl() + parts.query; } public static String createStaticViewUrl(String path) { - return create().staticView(path).toUrl(); + var parts = splitQueryFromPath(path); + return create().staticView(parts.path).toUrl() + parts.query; } public static String createCaseMapUrl(String path) { - return create().caseMap(path).toUrl(); + var parts = splitQueryFromPath(path); + return create().caseMap(parts.path).toUrl() + parts.query; } public EngineUrl base(String base) { @@ -130,6 +137,9 @@ public EngineUrl servlet(SERVLET servlet) { } public EngineUrl path(String path) { + if (StringUtils.contains(path, "?")) { + throw new IllegalArgumentException("Adding query parameters via the path method will not work, please use the queryParam method or encode the '?' with '%3F'."); + } this.path = path; return this; } @@ -161,6 +171,18 @@ private String getServletPath() { return ""; } + private static PathAndQuery splitQueryFromPath(String pathWithQuery) { + if (pathWithQuery == null) { + return new PathAndQuery("", ""); + } + var path = StringUtils.substringBefore(pathWithQuery, "?"); + var query = StringUtils.substringAfter(pathWithQuery, "?"); + if (query.length() > 0) { + query = "?" + query; + } + return new PathAndQuery(path, query); + } + /** * Gets base URL of a running engine. Returns URL of started * project-build-plugin test engine ({@value #TEST_ENGINE_URL}) or @@ -239,4 +261,5 @@ public static Boolean isDesigner() { } private static record QueryParam(String key, String value) {} + private static record PathAndQuery(String path, String query) {} } diff --git a/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestEngineUrl.java b/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestEngineUrl.java index df4736f..11a3187 100644 --- a/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestEngineUrl.java +++ b/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestEngineUrl.java @@ -1,14 +1,24 @@ package com.axonivy.ivy.webtest.engine; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.axonivy.ivy.webtest.engine.EngineUrl.SERVLET; import com.codeborne.selenide.Configuration; class TestEngineUrl { + private static String BASE_URL = "http://www.axonivy.com:8080/ivy/"; + private static String APP = "test"; + + @BeforeEach + void setup() { + System.setProperty(EngineUrl.TEST_ENGINE_URL, BASE_URL); + System.setProperty(EngineUrl.TEST_ENGINE_APP, APP); + } @AfterEach void cleanup() { @@ -20,6 +30,8 @@ void cleanup() { void designerUrls() { var remote = Configuration.remote; try { + System.clearProperty(EngineUrl.TEST_ENGINE_URL); + System.clearProperty(EngineUrl.TEST_ENGINE_APP); Configuration.remote = null; String baseUrl = "http://localhost:8081/"; assertThat(EngineUrl.createRestUrl("")).isEqualTo(baseUrl + EngineUrl.DESIGNER + "/api"); @@ -35,15 +47,11 @@ void designerUrls() { @Test void engineUrls() { - String baseUrl = "http://www.axonivy.com:8080/ivy/"; - String app = "test"; - System.setProperty(EngineUrl.TEST_ENGINE_URL, baseUrl); - System.setProperty(EngineUrl.TEST_ENGINE_APP, app); - assertThat(EngineUrl.createRestUrl("")).isEqualTo(baseUrl + app + "/api"); - assertThat(EngineUrl.createWebServiceUrl("")).isEqualTo(baseUrl + app + "/ws"); - assertThat(EngineUrl.createProcessUrl("")).isEqualTo(baseUrl + app + "/pro"); - assertThat(EngineUrl.createStaticViewUrl("")).isEqualTo(baseUrl + app + "/faces/view"); - assertThat(EngineUrl.createCaseMapUrl("")).isEqualTo(baseUrl + app + "/casemap"); + assertThat(EngineUrl.createRestUrl("")).isEqualTo(BASE_URL + APP + "/api"); + assertThat(EngineUrl.createWebServiceUrl("")).isEqualTo(BASE_URL + APP + "/ws"); + assertThat(EngineUrl.createProcessUrl("")).isEqualTo(BASE_URL + APP + "/pro"); + assertThat(EngineUrl.createStaticViewUrl("")).isEqualTo(BASE_URL + APP + "/faces/view"); + assertThat(EngineUrl.createCaseMapUrl("")).isEqualTo(BASE_URL + APP + "/casemap"); assertThat(EngineUrl.isDesigner()).isEqualTo(false); } @@ -67,11 +75,15 @@ void urlBuidler() { @Test void queryParam() { - String baseUrl = "http://www.axonivy.com:8080/ivy/"; - String app = "test"; - System.setProperty(EngineUrl.TEST_ENGINE_URL, baseUrl); - System.setProperty(EngineUrl.TEST_ENGINE_APP, app); var url = EngineUrl.create().staticView("abc.xhtml").queryParam("userName", "crazy user").toUrl(); - assertThat(url).isEqualTo(baseUrl + app + "/faces/view/abc.xhtml?userName=crazy+user"); + assertThat(url).isEqualTo(BASE_URL + APP + "/faces/view/abc.xhtml?userName=crazy+user"); + } + + @Test + void queryParamInPath() { + assertThatThrownBy(() -> EngineUrl.create().path("bla?embedInFrame")).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Adding query parameters via the path method will not work"); + assertThat(EngineUrl.createProcessUrl("start.ivp?locale=en&format=DE")).isEqualTo("http://www.axonivy.com:8080/ivy/test/pro/start.ivp?locale=en&format=DE"); + assertThat(EngineUrl.createRestUrl("variable/myVar?value=new")).isEqualTo("http://www.axonivy.com:8080/ivy/test/api/variable/myVar?value=new"); } }