From ae51820e4f8b261cb1efca28e1b6b7445c063a0b Mon Sep 17 00:00:00 2001 From: Christian Strebel Date: Tue, 31 Dec 2024 16:41:56 +0100 Subject: [PATCH] Format and Clean up Java source code as defined in ADR-029 Done by Eclipse's 'Source Clean Up' function with the options enabled: - Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Convert control statement bodies to block - Convert to enhanced 'for' loops only if the loop variable is used - Convert to enhanced 'for' loops - Convert if/else if/else chain to switch - Add elements in collections without loop - Add final modifier to private fields - Use instanceof keyword instead of Class.isInstance() - Exit loop earlier - Make inner classes static where possible - Convert StringBuffer to StringBuilder for local variables - Use String.replace() instead of String.replaceAll() when possible - String.isBlank() rather than String.strip().isEmpty() - Use lazy logical operator (&& and ||) - Primitive comparison - Primitive parsing - Primitive serialization - Use boolean literals instead of Boolean.TRUE/FALSE when used as a primitive - Remove unused imports - Add missing '@OverRide' annotations - Add missing '@OverRide' annotations to implementations of interface methods - Add missing '@deprecated' annotations - Remove unnecessary casts - Remove redundant modifiers - Remove redundant semicolons - Implicit comparator - Remove unnecessary array creation for varargs - Create array with curly - Remove variable assignment before return - Convert loop into if - Remove unnecessary '$NON-NLS$' tags - Organize imports - Format source code - Remove trailing white spaces on all lines - Remove redundant String.substring() parameter - Use Arrays.fill() when possible - Remove overridden assignment - Remove redundant super() call in constructor - Remove unreachable block - Operate on Maps directly - Initialize collection at creation - Initialize map at creation - Avoid Object.equals() or String.equalsIgnoreCase() on null objects - Compare to zero - Pull out a duplicate 'if' from an if/else - Use pattern matching for instanceof - Convert to switch expression where possible - Simplify lambda expression and method reference syntax - Use Comparator.comparing() - Use String.join() - Use diamond operator --- .../ivy/webtest/primeui/widget/Accordion.java | 4 +- .../ivy/webtest/primeui/widget/Dialog.java | 6 +- .../primeui/widget/SelectBooleanCheckbox.java | 2 +- .../primeui/widget/SelectCheckboxMenu.java | 6 +- .../primeui/widget/SelectManyCheckbox.java | 18 +-- .../webtest/primeui/widget/SelectOneMenu.java | 2 +- .../primeui/widget/SelectOneRadio.java | 8 +- .../ivy/webtest/primeui/widget/Table.java | 2 +- .../ivy/webtest/primeui/ShowcaseUtil.java | 72 ++++------ .../ivy/webtest/primeui/TestPrimeUi.java | 128 ++++++++---------- .../demo/test/WebTestAppFixtureIT.java | 2 +- .../ivy/webtest/IvyTestRuntimeProps.java | 10 +- .../ivy/webtest/IvyWebTestExtension.java | 17 +-- .../ivy/webtest/engine/BaseEngineUrl.java | 24 ++-- .../axonivy/ivy/webtest/engine/EngineUrl.java | 13 +- .../ivy/webtest/engine/WebAppFixture.java | 50 +++---- .../ivy/webtest/engine/TestBaseEngineUrl.java | 11 +- .../ivy/webtest/engine/TestEngineUrl.java | 14 +- 18 files changed, 181 insertions(+), 208 deletions(-) diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Accordion.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Accordion.java index f233982..3f3b077 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Accordion.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Accordion.java @@ -45,7 +45,7 @@ public Accordion toggleTab(String tabName) { accordionTab(tabName).click(); String tabContentId = StringUtils.removeEnd(accordionTab(tabName).getAttribute("id"), "_header"); $(By.id(tabContentId)).should(match("accordion should not animate", - el -> !el.getAttribute("style").contains("overflow"))); + el -> !el.getAttribute("style").contains("overflow"))); $(By.id(tabContentId)).shouldBe(attribute("aria-hidden", previousState)); return this; } @@ -86,6 +86,6 @@ public boolean isTabOpen(String tabName) { private SelenideElement accordionTab(String tabName) { return $(By.id(accordionId)).findAll(".ui-accordion-header").find(text(tabName)).shouldBe(visible, - enabled); + enabled); } } diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Dialog.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Dialog.java index 2cc7888..88a0c0f 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Dialog.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Dialog.java @@ -1,12 +1,12 @@ /* * Copyright (C) 2021 Axon Ivy AG - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectBooleanCheckbox.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectBooleanCheckbox.java index 91a8bbc..783db43 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectBooleanCheckbox.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectBooleanCheckbox.java @@ -102,4 +102,4 @@ public boolean isDisabled() { private SelenideElement checkbox() { return $(By.id(booleanCheckboxId)).find(".ui-chkbox-box").shouldBe(visible); } -} \ No newline at end of file +} diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectCheckboxMenu.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectCheckboxMenu.java index 7da9a2a..e89fb22 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectCheckboxMenu.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectCheckboxMenu.java @@ -39,7 +39,7 @@ public SelectCheckboxMenu selectAllItems() { openCheckboxPanel(); $(By.id(checkBoxMenuId + "_panel")).find(".ui-widget-header .ui-chkbox-box").shouldBe(visible).click(); $(By.id(checkBoxMenuId + "_panel")).find(".ui-widget-header .ui-chkbox-box") - .shouldHave(cssClass("ui-state-active")); + .shouldHave(cssClass("ui-state-active")); closeCheckboxPanel(); return this; } @@ -80,13 +80,13 @@ public SelectCheckboxMenu itemsShouldBeSelected(String... labels) { private void selectItemInternal(String label) { $(By.id(checkBoxMenuId + "_panel")).findAll(".ui-selectcheckboxmenu-items li") - .find(text(label)).find(".ui-chkbox-box").shouldBe(visible).click(); + .find(text(label)).find(".ui-chkbox-box").shouldBe(visible).click(); checkThatLabelIsSelected(label); } private void checkThatLabelIsSelected(String label) { $(By.id(checkBoxMenuId + "_panel")).findAll(".ui-selectcheckboxmenu-items li") - .find(text(label)).find(".ui-chkbox-box").shouldHave(cssClass("ui-state-active")); + .find(text(label)).find(".ui-chkbox-box").shouldHave(cssClass("ui-state-active")); } private void openCheckboxPanel() { diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectManyCheckbox.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectManyCheckbox.java index 540b138..701388a 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectManyCheckbox.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectManyCheckbox.java @@ -46,9 +46,9 @@ public SelectManyCheckbox(By manyCheckbox) { @Deprecated public List getSelectedCheckboxes() { return $(By.id(manyCheckboxId)).shouldBe(visible).findAll(".ui-chkbox-box") - .filter(cssClass("ui-state-active")) - .asDynamicIterable().stream().map(e -> e.parent().parent().find("label").getText()) - .collect(Collectors.toList()); + .filter(cssClass("ui-state-active")) + .asDynamicIterable().stream().map(e -> e.parent().parent().find("label").getText()) + .collect(Collectors.toList()); } /** @@ -56,11 +56,11 @@ public List getSelectedCheckboxes() { * @param condition condition * @return SelectManyCheckbox */ - public SelectManyCheckbox shouldBe(WebElementsCondition condition) { + public SelectManyCheckbox shouldBe(WebElementsCondition condition) { var elements = $(By.id(manyCheckboxId)).shouldBe(visible).findAll(".ui-chkbox-box") - .filter(cssClass("ui-state-active")) - .asDynamicIterable().stream().map(e -> e.parent().parent().find("label")) - .collect(Collectors.toList()); + .filter(cssClass("ui-state-active")) + .asDynamicIterable().stream().map(e -> e.parent().parent().find("label")) + .collect(Collectors.toList()); var collection = new WebElementsCollectionWrapper(WebDriverRunner.driver(), elements); new ElementsCollection(collection).shouldBe(condition); return this; @@ -74,7 +74,7 @@ public SelectManyCheckbox shouldBe(WebElementsCondition condition) { @Deprecated public boolean isManyCheckboxDisabled() { return $(By.id(manyCheckboxId)).shouldBe(visible).findAll(".ui-chkbox-box").asDynamicIterable().stream() - .anyMatch(e -> e.has(cssClass("ui-state-disabled"))); + .anyMatch(e -> e.has(cssClass("ui-state-disabled"))); } /** @@ -123,6 +123,6 @@ public SelectManyCheckbox clear() { private SelenideElement getCheckboxForLabel(String value) { return $(By.id(manyCheckboxId)).findAll("label").find(exactText(value)).parent().find(".ui-chkbox-box") - .shouldBe(visible); + .shouldBe(visible); } } diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneMenu.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneMenu.java index 6dd03ab..f835f54 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneMenu.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneMenu.java @@ -86,7 +86,7 @@ public String getSelectedItem() { private void selectItem(final String label) { $(By.id(oneMenuId)).find("span.ui-icon.ui-icon-triangle-1-s").shouldBe(visible).click(); $(By.id(oneMenuId + "_panel")).should(match("menupanel should not animate", - el -> !el.getAttribute("style").contains("opacity"))); + el -> !el.getAttribute("style").contains("opacity"))); $(By.id(oneMenuId + "_items")).shouldBe(visible); $(By.id(oneMenuId + "_items")).findAll("li").find(exactText(label)).shouldBe(visible, enabled).click(); $(By.id(oneMenuId + "_items")).shouldNotBe(visible); diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneRadio.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneRadio.java index 0561828..3da0844 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneRadio.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/SelectOneRadio.java @@ -73,14 +73,14 @@ public SelectOneRadio selectItemByLabel(final String label) { */ public SelectOneRadio selectedValueShouldBe(WebElementCondition condition) { $(By.id(oneRadioId)).findAll(".ui-radiobutton-box").find(Condition.cssClass("ui-state-active")) - .parent().find("div > input").shouldBe(condition); + .parent().find("div > input").shouldBe(condition); return this; } @Deprecated public String getSelectedValue() { return $(By.id(oneRadioId)).findAll(".ui-radiobutton-box").find(Condition.cssClass("ui-state-active")) - .parent().find("div > input").getValue(); + .parent().find("div > input").getValue(); } private SelenideElement radioById(String id) { @@ -89,11 +89,11 @@ private SelenideElement radioById(String id) { private SelenideElement radioByValue(String value) { return $(By.cssSelector("input[type='radio'][value='" + value + "']")).parent().parent() - .find("div.ui-radiobutton-box").shouldBe(visible); + .find("div.ui-radiobutton-box").shouldBe(visible); } private SelenideElement radioByLabel(String label) { return $(By.id(oneRadioId)).findAll("label").find(exactText(label)).parent() - .find("div.ui-radiobutton-box").shouldBe(visible); + .find("div.ui-radiobutton-box").shouldBe(visible); } } diff --git a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Table.java b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Table.java index 4959a43..d72b664 100644 --- a/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Table.java +++ b/primeui-tester/src/main/java/com/axonivy/ivy/webtest/primeui/widget/Table.java @@ -135,4 +135,4 @@ private void fillInput(By id, String search) { $(id).shouldBe(visible).clear(); $(id).shouldBe(visible).sendKeys(search); } -} \ No newline at end of file +} diff --git a/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/ShowcaseUtil.java b/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/ShowcaseUtil.java index fa16819..feba9ac 100644 --- a/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/ShowcaseUtil.java +++ b/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/ShowcaseUtil.java @@ -18,92 +18,76 @@ import com.codeborne.selenide.Selenide; import com.codeborne.selenide.SelenideElement; -public class ShowcaseUtil -{ +public class ShowcaseUtil { private static String baseShowcaseUrl = "https://primefaces.org/showcase/ui/"; - public static Showcase open(Showcase showcase) - { + public static Showcase open(Showcase showcase) { Selenide.open(baseShowcaseUrl + showcase.url); return showcase; } - public static enum Showcase - { - CHECKBOX ("input/booleanCheckbox.xhtml", ".ui-selectbooleancheckbox"), - ONEMENU ("input/oneMenu.xhtml", ".ui-selectonemenu"), - CHECKBOXMENU ("input/checkboxMenu.xhtml", ".ui-selectcheckboxmenu"), - MANYCHECKBOX ("input/manyCheckbox.xhtml", ".ui-selectmanycheckbox"), - ONERADIO ("input/oneRadio.xhtml", ".ui-selectoneradio"), - TABLE ("data/datatable/filter.xhtml", ".ui-datatable"), - ACCORDION ("panel/accordionPanel.xhtml", ".ui-accordion"), - INPUTNUMBER ("input/inputNumber.xhtml", ".ui-inputnumber"); - - private String url; - private String selector; - - Showcase(String url, String selector) - { + public enum Showcase { + CHECKBOX("input/booleanCheckbox.xhtml", ".ui-selectbooleancheckbox"), + ONEMENU("input/oneMenu.xhtml", ".ui-selectonemenu"), + CHECKBOXMENU("input/checkboxMenu.xhtml", ".ui-selectcheckboxmenu"), + MANYCHECKBOX("input/manyCheckbox.xhtml", ".ui-selectmanycheckbox"), + ONERADIO("input/oneRadio.xhtml", ".ui-selectoneradio"), + TABLE("data/datatable/filter.xhtml", ".ui-datatable"), + ACCORDION("panel/accordionPanel.xhtml", ".ui-accordion"), + INPUTNUMBER("input/inputNumber.xhtml", ".ui-inputnumber"); + + private final String url; + private final String selector; + + Showcase(String url, String selector) { this.url = url; this.selector = selector; } - public SelectBooleanCheckbox checkbox(String label) - { + public SelectBooleanCheckbox checkbox(String label) { return PrimeUi.selectBooleanCheckbox(elementId($$(selector).find(text(label)))); } - public SelectOneMenu oneMenu() - { + public SelectOneMenu oneMenu() { return PrimeUi.selectOne(firstElement()); } - public SelectOneMenu oneMenuEditable() - { + public SelectOneMenu oneMenuEditable() { var oneMenuEditable = $$("label").find(exactText("Editable")).parent().find(".ui-selectonemenu"); return PrimeUi.selectOne(elementId(oneMenuEditable)); } - - public SelectCheckboxMenu checkboxMenu() - { + public SelectCheckboxMenu checkboxMenu() { return PrimeUi.selectCheckboxMenu(firstElement()); } - public SelectManyCheckbox manyCheckbox() - { + public SelectManyCheckbox manyCheckbox() { return PrimeUi.selectManyCheckbox(firstElement()); } - public SelectOneRadio radio() - { + public SelectOneRadio radio() { return PrimeUi.selectOneRadio(firstElement()); } - public Table table() - { + public Table table() { return PrimeUi.table(firstElement()); } - public Accordion accordion() - { + public Accordion accordion() { return PrimeUi.accordion(firstElement()); } - public InputNumber inputNumber() - { + public InputNumber inputNumber() { return PrimeUi.inputNumber(firstElement()); } - private By firstElement() - { + private By firstElement() { return elementId($$(selector).filter(visible).first()); } - private By elementId(SelenideElement element) - { + private By elementId(SelenideElement element) { return By.id(element.attr("id")); } } -} \ No newline at end of file +} diff --git a/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/TestPrimeUi.java b/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/TestPrimeUi.java index 276888c..26ed7ca 100644 --- a/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/TestPrimeUi.java +++ b/primeui-tester/src/test/java/com/axonivy/ivy/webtest/primeui/TestPrimeUi.java @@ -21,80 +21,71 @@ /** * Class to test PrimeUi. Tests on the official Primefaces Showcase. */ -public class TestPrimeUi -{ +public class TestPrimeUi { @BeforeAll - static void setup() - { + static void setup() { Configuration.browser = "firefox"; Configuration.headless = true; Configuration.reportsFolder = "target/selenide/reports"; } @Test - void testSelectOneMenu() - { + void testSelectOneMenu() { String option = "Option1"; var menu = ShowcaseUtil.open(Showcase.ONEMENU).oneMenu() - .selectedItemShould(exactText("Select One")) - .selectItemByLabel("Option2") - .selectedItemShould(exactText("Option2")) - .selectItemByValue(option) - .selectedItemShould(exactText(option)); + .selectedItemShould(exactText("Select One")) + .selectItemByLabel("Option2") + .selectedItemShould(exactText("Option2")) + .selectItemByValue(option) + .selectedItemShould(exactText(option)); assertThat(menu.getSelectedItem()).isEqualTo(option); } @Test - void testSelectOneMenuEditable() - { + void testSelectOneMenuEditable() { String option = "New York"; var menu = ShowcaseUtil.open(Showcase.ONEMENU).oneMenuEditable() - .selectItemByLabel("Select One") - .selectedItemShould(exactValue("Select One")) - .selectItemByValue(option) - .selectedItemShould(exactValue(option)); + .selectItemByLabel("Select One") + .selectedItemShould(exactValue("Select One")) + .selectItemByValue(option) + .selectedItemShould(exactValue(option)); assertThat(menu.getSelectedItem()).isEqualTo(option); } @Test - void testSelectCheckBoxMenu_all() - { + void testSelectCheckBoxMenu_all() { ShowcaseUtil.open(Showcase.CHECKBOXMENU).checkboxMenu() - .selectAllItems() - .itemsShouldBeSelected("Brasilia"); + .selectAllItems() + .itemsShouldBeSelected("Brasilia"); } @Test - void testSelectCheckBoxMenu_itemByValue() - { + void testSelectCheckBoxMenu_itemByValue() { ShowcaseUtil.open(Showcase.CHECKBOXMENU).checkboxMenu() - .selectItemsByValue("Miami") - .itemsShouldBeSelected("Miami"); + .selectItemsByValue("Miami") + .itemsShouldBeSelected("Miami"); } @Test - void testSelectCheckBoxMenu_itemsByValue() - { + void testSelectCheckBoxMenu_itemsByValue() { ShowcaseUtil.open(Showcase.CHECKBOXMENU).checkboxMenu() - .selectItemsByValue("Miami", "Brasilia") - .itemsShouldBeSelected("Miami", "Brasilia"); + .selectItemsByValue("Miami", "Brasilia") + .itemsShouldBeSelected("Miami", "Brasilia"); } @Test - void testSelectBooleanCheckBox() - { + void testSelectBooleanCheckBox() { ShowcaseUtil.open(Showcase.CHECKBOX).checkbox("Basic") - .shouldBeChecked(false) - .setChecked() - .shouldBeChecked(true) - .removeChecked() - .shouldBeChecked(false); + .shouldBeChecked(false) + .setChecked() + .shouldBeChecked(true) + .removeChecked() + .shouldBeChecked(false); } @Test - void testSelectManyCheckbox() - { + void testSelectManyCheckbox() { var manyCheckbox = ShowcaseUtil.open(Showcase.MANYCHECKBOX).manyCheckbox(); manyCheckbox.shouldBeDisabled(false); manyCheckbox.shouldBe(empty); @@ -105,57 +96,52 @@ void testSelectManyCheckbox() } @Test - void testSelectOneRadio() throws Exception - { + void testSelectOneRadio() throws Exception { ShowcaseUtil.open(Showcase.ONERADIO).radio() - .selectItemById($$(".ui-selectoneradio").filter(visible).first().attr("id") + ":0") - .selectedValueShouldBe(exactValue("Option1")) - .selectItemByValue("Option2") - .selectedValueShouldBe(exactValue("Option2")) - .selectItemByLabel("Option3") - .selectedValueShouldBe(exactValue("Option3")); + .selectItemById($$(".ui-selectoneradio").filter(visible).first().attr("id") + ":0") + .selectedValueShouldBe(exactValue("Option1")) + .selectItemByValue("Option2") + .selectedValueShouldBe(exactValue("Option2")) + .selectItemByLabel("Option3") + .selectedValueShouldBe(exactValue("Option3")); } @Test - void testTableWithValue() throws Exception - { + void testTableWithValue() throws Exception { var table = ShowcaseUtil.open(Showcase.TABLE).table(); table.column(0).shouldBe(sizeGreaterThan(5)); var firstCell = table.valueAt(0, 0); var secondCell = firstCell; - for (var i = 1; firstCell.equals(secondCell); i++) - { + for (var i = 1; firstCell.equals(secondCell); i++) { secondCell = table.valueAt(i, 0); } table.searchColumn(0, firstCell) - .contains(firstCell) - .containsNot(secondCell) - .column(0).shouldBe(sizeLessThan(5)); - //searchGlobal seems not to work on new PrimeFaces Showcase yet. + .contains(firstCell) + .containsNot(secondCell) + .column(0).shouldBe(sizeLessThan(5)); + // searchGlobal seems not to work on new PrimeFaces Showcase yet. } @Test - void testAccordion() - { + void testAccordion() { ShowcaseUtil.open(Showcase.ACCORDION).accordion() - .toggleTab("Header I") - .tabShouldBe("Header I", false) - .openTab("Header I") - .tabShouldBe("Header I", true) - .openTab("Header II") - .tabShouldBe("Header I", false) - .tabShouldBe("Header II", true); + .toggleTab("Header I") + .tabShouldBe("Header I", false) + .openTab("Header I") + .tabShouldBe("Header I", true) + .openTab("Header II") + .tabShouldBe("Header I", false) + .tabShouldBe("Header II", true); } @Test - void testInputNumber() - { + void testInputNumber() { ShowcaseUtil.open(Showcase.INPUTNUMBER).inputNumber() - .should(exactValue("0.00")) - .setValue("5") - .should(exactValue("5.00")) - .setValue("3.14") - .should(exactValue("3.14")); + .should(exactValue("0.00")) + .setValue("5") + .should(exactValue("5.00")) + .setValue("3.14") + .should(exactValue("3.14")); } -} \ No newline at end of file +} diff --git a/web-tester-fixture/src_test/com/axonivy/demo/test/WebTestAppFixtureIT.java b/web-tester-fixture/src_test/com/axonivy/demo/test/WebTestAppFixtureIT.java index 6453fac..02d3041 100644 --- a/web-tester-fixture/src_test/com/axonivy/demo/test/WebTestAppFixtureIT.java +++ b/web-tester-fixture/src_test/com/axonivy/demo/test/WebTestAppFixtureIT.java @@ -62,4 +62,4 @@ private void assertVariable(String variable) { $(By.id("form:variable")).shouldBe(exactText(variable)); } -} \ No newline at end of file +} diff --git a/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyTestRuntimeProps.java b/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyTestRuntimeProps.java index 93dabb8..1f34f68 100644 --- a/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyTestRuntimeProps.java +++ b/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyTestRuntimeProps.java @@ -4,14 +4,16 @@ class IvyTestRuntimeProps { - /** keep sync with ivy.core resource - * ch.ivyteam.ivy.bpm.exec.client.restricted.IvyTestRuntime.IvyTestRuntimeIO#RESOURCE_NAME */ + /** + * keep sync with ivy.core resource + * ch.ivyteam.ivy.bpm.exec.client.restricted.IvyTestRuntime.IvyTestRuntimeIO#RESOURCE_NAME + */ private static final String RT_PROPS = "ivyTestRuntime.properties"; public static void loadToSystem() { var rtProps = loadProps(); rtProps.propertyNames().asIterator().forEachRemaining(it -> { - var key = (String)it; + var key = (String) it; System.setProperty(key, rtProps.getProperty(key)); }); } @@ -19,7 +21,7 @@ public static void loadToSystem() { public static Properties loadProps() { var props = new Properties(); ClassLoader loader = IvyWebTestExtension.class.getClassLoader(); - try(var in = loader.getResourceAsStream(RT_PROPS)) { + try (var in = loader.getResourceAsStream(RT_PROPS)) { if (in != null) { props.load(in); } diff --git a/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyWebTestExtension.java b/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyWebTestExtension.java index 0b7026a..953df28 100644 --- a/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyWebTestExtension.java +++ b/web-tester/src/main/java/com/axonivy/ivy/webtest/IvyWebTestExtension.java @@ -15,6 +15,7 @@ */ package com.axonivy.ivy.webtest; +import java.lang.reflect.Method; import java.util.Optional; import org.apache.commons.lang3.BooleanUtils; @@ -50,23 +51,23 @@ public void beforeEach(ExtensionContext context) throws Exception { private boolean headless(ExtensionContext context) { return context.getConfigurationParameter("ivy.selenide.headless") - .map(param -> BooleanUtils.toBoolean(param)) - .orElseGet(() -> findAnnotation(context).map(a -> a.headless()) - .orElse(HEADLESS_DEFAULT)); + .map(BooleanUtils::toBoolean) + .orElseGet(() -> findAnnotation(context).map(IvyWebTest::headless) + .orElse(HEADLESS_DEFAULT)); } private String browser(ExtensionContext context) { return context.getConfigurationParameter("ivy.selenide.browser") - .orElseGet(() -> findAnnotation(context).map(a -> a.browser()) - .orElse(BROWSER_DEFAULT)); + .orElseGet(() -> findAnnotation(context).map(IvyWebTest::browser) + .orElse(BROWSER_DEFAULT)); } private String reportFolder(ExtensionContext context) { String methodDir = context.getTestClass().map(c -> c.getName() + "/").orElse("") + - context.getTestMethod().map(m -> m.getName()).orElse(""); + context.getTestMethod().map(Method::getName).orElse(""); String reportDir = context.getConfigurationParameter("ivy.selenide.reportfolder") - .orElseGet(() -> findAnnotation(context).map(a -> a.reportFolder()) - .orElse(REPORT_FOLDER_DEFAULT)); + .orElseGet(() -> findAnnotation(context).map(IvyWebTest::reportFolder) + .orElse(REPORT_FOLDER_DEFAULT)); return StringUtils.appendIfMissing(reportDir, "/") + methodDir; } diff --git a/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/BaseEngineUrl.java b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/BaseEngineUrl.java index 3c4bf02..d7ec660 100644 --- a/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/BaseEngineUrl.java +++ b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/BaseEngineUrl.java @@ -42,12 +42,12 @@ static String url() { private String evaluate() { var engineUrl = System.getProperty(TEST_ENGINE_URL); if (engineUrl == null || engineUrl.isBlank()) { - System.err.println("Missing system property '"+TEST_ENGINE_URL+"' falling back to '"+DEFAULT_URL+"'."); + System.err.println("Missing system property '" + TEST_ENGINE_URL + "' falling back to '" + DEFAULT_URL + "'."); engineUrl = DEFAULT_URL; } try { return evaluate(engineUrl); - } catch(Exception ex) { + } catch (Exception ex) { return engineUrl; } } @@ -67,8 +67,8 @@ private String evaluate(String engine) throws URISyntaxException, UnknownHostExc private boolean isLocalHost(URI engineUri) { String host = engineUri.getHost(); return "localhost".equalsIgnoreCase(host) || - "127.0.0.1".equals(host) || - "[::1]".equals(host); + "127.0.0.1".equals(host) || + "[::1]".equals(host); } private boolean seleniumRunsOnDifferentHost(URI engineUri) throws URISyntaxException { @@ -79,17 +79,17 @@ private boolean seleniumRunsOnDifferentHost(URI engineUri) throws URISyntaxExcep URI remoteUri = new URI(Configuration.remote); var remoteHost = remoteUri.getHost(); return remoteHost != null && - !remoteHost.equalsIgnoreCase(engineUri.getHost()); + !remoteHost.equalsIgnoreCase(engineUri.getHost()); } private URI replaceHost(URI engineUri, String hostName) throws URISyntaxException { return new URI( - engineUri.getScheme(), - engineUri.getUserInfo(), - hostName, - engineUri.getPort(), - engineUri.getPath(), - engineUri.getQuery(), - engineUri.getFragment()); + engineUri.getScheme(), + engineUri.getUserInfo(), + hostName, + engineUri.getPort(), + engineUri.getPath(), + engineUri.getQuery(), + engineUri.getFragment()); } } 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 12ca7f7..bba87a9 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 @@ -31,12 +31,12 @@ */ @SuppressWarnings("hiding") public class EngineUrl { - public static enum SERVLET { + public enum SERVLET { PROCESS("pro"), REST("api"), WEBSERVICE("ws"), STATIC_VIEW("faces/view"), CASEMAP("casemap"); final String path; - private SERVLET(String path) { + SERVLET(String path) { this.path = path; } } @@ -49,7 +49,7 @@ private SERVLET(String path) { private String app; private SERVLET servlet; private String path = ""; - private List queryParams = new ArrayList<>(); + private final List queryParams = new ArrayList<>(); private EngineUrl() { this.base = base(); @@ -155,9 +155,9 @@ public String toUrl() { UriBuilder builder() { var builder = UriBuilder.fromUri(base) - .path(app) - .path(getServletPath()) - .path(path); + .path(app) + .path(getServletPath()) + .path(path); for (var queryParam : queryParams) { builder = builder.queryParam(queryParam.key, queryParam.value); } @@ -261,5 +261,6 @@ 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/main/java/com/axonivy/ivy/webtest/engine/WebAppFixture.java b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/WebAppFixture.java index 110b2f5..1d4a03b 100644 --- a/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/WebAppFixture.java +++ b/web-tester/src/main/java/com/axonivy/ivy/webtest/engine/WebAppFixture.java @@ -46,13 +46,13 @@ *

  * {@literal @IvyWebTest}
  * class Test {
- *   {@literal @Test}
- *   void test(WebAppFixture fixture) {
- *     open(EngineUrl.create().toUrl());
- *     $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
- *     fixture.login("test", "test");
- *     $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
- *   }
+ *   {@literal @Test}
+ *   void test(WebAppFixture fixture) {
+ *     open(EngineUrl.create().toUrl());
+ *     $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
+ *     fixture.login("test", "test");
+ *     $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
+ *   }
  * }
  * 
* @since 10.0.14 @@ -70,10 +70,10 @@ public class WebAppFixture { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   open(EngineUrl.create().toUrl());
-   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
-   *   fixture.login("test", "test");
-   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
+   *   open(EngineUrl.create().toUrl());
+   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
+   *   fixture.login("test", "test");
+   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
    * }
    * 
* @param username the name of the user @@ -98,10 +98,10 @@ public void login(String username, String password) { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   open(EngineUrl.create().toUrl());
-   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
-   *   fixture.logout();
-   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
+   *   open(EngineUrl.create().toUrl());
+   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("Developer"));
+   *   fixture.logout();
+   *   $(By.id("sessionUserName")).shouldBe(Condition.exactText("test"));
    * }
    * 
*/ @@ -120,7 +120,7 @@ public void logout() { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   fixture.var("myVar", "myNewValue");
+   *   fixture.var("myVar", "myNewValue");
    * }
    * 
*/ @@ -139,9 +139,9 @@ public void var(String name, String value) { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   fixture.var("myVar", "myNewValue");
-   *   //do some tests
-   *   fixture.resetVar("myVar");
+   *   fixture.var("myVar", "myNewValue");
+   *   //do some tests
+   *   fixture.resetVar("myVar");
    * }
    * 
*/ @@ -161,7 +161,7 @@ public void resetVar(String name) { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   fixture.config("RestClients.MyRestClient.Url", "${ivy.app.baseurl}/api/myCoolMockService");
+   *   fixture.config("RestClients.MyRestClient.Url", "${ivy.app.baseurl}/api/myCoolMockService");
    * }
    * 
*/ @@ -180,9 +180,9 @@ public void config(String name, String value) { *

    * {@literal @Test}
    * void test(WebAppFixture fixture) {
-   *   fixture.config("RestClients.MyRestClient.Url", "${ivy.app.baseurl}/api/myCoolMockService");
-   *   //do some tests
-   *   fixture.resetConfig("RestClients.MyRestClient.Url");
+   *   fixture.config("RestClients.MyRestClient.Url", "${ivy.app.baseurl}/api/myCoolMockService");
+   *   //do some tests
+   *   fixture.resetConfig("RestClients.MyRestClient.Url");
    * }
    * 
*/ @@ -202,8 +202,8 @@ private static UriBuilder configRestUrl() { private void sendRequest(HttpRequest.Builder requestBuilder) throws Exception { var client = HttpClient.newBuilder().build(); var request = requestBuilder - .header("Authorization", basicAuth("admin", "admin")) - .header("X-Requested-By", "webtest").build(); + .header("Authorization", basicAuth("admin", "admin")) + .header("X-Requested-By", "webtest").build(); var response = client.send(request, BodyHandlers.ofString()); if (response.statusCode() > 399) { throw new RuntimeException("Couldn't send web app fixture request (status code: " + response.statusCode() + "): " + response.body()); diff --git a/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestBaseEngineUrl.java b/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestBaseEngineUrl.java index 2d6ad71..0666f46 100644 --- a/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestBaseEngineUrl.java +++ b/web-tester/src/test/java/com/axonivy/ivy/webtest/engine/TestBaseEngineUrl.java @@ -46,13 +46,12 @@ void systemProperty_noValidUri() { .isEqualTo("gugus sugus"); } - @Test void driverRemote() throws UnknownHostException { Configuration.remote = "http://selenium:5678/wd/hub"; assertThat(BaseEngineUrl.url()) .as("Selenium is running remote therefore replace localhost in engine url with explicit host name") - .isEqualTo("http://"+hostName()+":8081/"); + .isEqualTo("http://" + hostName() + ":8081/"); } @Test @@ -69,7 +68,7 @@ void driverRemote_ivyLocalIp4() throws UnknownHostException { System.setProperty(BaseEngineUrl.TEST_ENGINE_URL, "http://127.0.0.1:8081/"); assertThat(BaseEngineUrl.url()) .as("Selenium is running remote therefore replace localhost in engine url with explicit host name") - .isEqualTo("http://"+hostName()+":8081/"); + .isEqualTo("http://" + hostName() + ":8081/"); } @Test @@ -78,11 +77,11 @@ void driverRemote_ivyLocalIp6() throws UnknownHostException { System.setProperty(BaseEngineUrl.TEST_ENGINE_URL, "http://[::1]:8080/ivy"); assertThat(BaseEngineUrl.url()) .as("Selenium is running remote therefore replace localhost in engine url with explicit host name") - .isEqualTo("http://"+hostName()+":8080/ivy"); + .isEqualTo("http://" + hostName() + ":8080/ivy"); } @Test - void driverLocal() { + void driverLocal() { Configuration.remote = "http://localhost:5678/wd/hub"; assertThat(BaseEngineUrl.url()) .as("Selenium is running local no need to replace localhost") @@ -90,7 +89,7 @@ void driverLocal() { } @Test - void driverRemote_ivyRemote() { + void driverRemote_ivyRemote() { Configuration.remote = "http://localhost:5678/wd/hub"; System.setProperty(BaseEngineUrl.TEST_ENGINE_URL, "http://dev.axonivy.com:9090/ivy"); assertThat(BaseEngineUrl.url()) 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 11a3187..4fdaca4 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 @@ -60,17 +60,17 @@ void urlBuidler() { String baseUrl = "http://test/"; String app = "bla"; assertThat(EngineUrl.create().base(baseUrl).app(app).process("/test.ivp").toUrl()) - .isEqualTo(baseUrl + app + "/pro/test.ivp"); + .isEqualTo(baseUrl + app + "/pro/test.ivp"); assertThat(EngineUrl.create().base(baseUrl).app(app).process("test.ivp").toUrl()) - .isEqualTo(baseUrl + app + "/pro/test.ivp"); + .isEqualTo(baseUrl + app + "/pro/test.ivp"); assertThat(EngineUrl.create().base(baseUrl).app("").path("test").toUrl()).isEqualTo(baseUrl + "test"); assertThat(EngineUrl.create().base(baseUrl).app(app).servlet(null).path("test").toUrl()) - .isEqualTo(baseUrl + app + "/test"); + .isEqualTo(baseUrl + app + "/test"); assertThat( - EngineUrl.create().base("http://base").app("app").servlet(SERVLET.PROCESS).path("path").toUrl()) - .isEqualTo("http://base/app/pro/path"); + EngineUrl.create().base("http://base").app("app").servlet(SERVLET.PROCESS).path("path").toUrl()) + .isEqualTo("http://base/app/pro/path"); assertThat(EngineUrl.create().base("http://base/").app("/app/").servlet(SERVLET.PROCESS).path("/path/") - .toUrl()).isEqualTo("http://base/app/pro/path/"); + .toUrl()).isEqualTo("http://base/app/pro/path/"); } @Test @@ -82,7 +82,7 @@ void queryParam() { @Test void queryParamInPath() { assertThatThrownBy(() -> EngineUrl.create().path("bla?embedInFrame")).isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Adding query parameters via the path method will not work"); + .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"); }