Skip to content

Commit

Permalink
fix warning and test
Browse files Browse the repository at this point in the history
  • Loading branch information
phhung-axonivy committed Dec 17, 2024
1 parent c01a0ad commit 37fcf91
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public void saveProduct(Product product) {
DaoServiceRegistry.getProductRepoDAO().save(product);
}

@SuppressWarnings("unchecked")
private void addSelectOneMenuQueryFilter(Query<Product> query, String filterName, Map<String, FilterMeta> filters) {
if(filters.get(filterName) != null) {
if(filters.get(filterName).getFilterValue() instanceof ArrayList) {
Expand Down Expand Up @@ -312,8 +313,9 @@ private void addStringContainsQueryFilter(Query<Product> query, String filterNam
}
}

@SuppressWarnings("unchecked")
private void addDateRangeQueryFilter(Query<Product> query, String filterName, Map<String, FilterMeta> filters, boolean checkStatus) {
if(filters.get(filterName) != null) {
if(filters.get(filterName) != null) {
List<LocalDate> dateRange = (ArrayList<LocalDate>) filters.get(filterName).getFilterValue();
if(dateRange.size() > 1) {
Filter<Product> dateFilter = Ivy.repo().search(Product.class).dateTimeField(filterName).isAfterOrEqualTo(DateService.setTimeZero(dateRange.get(0))).and().dateTimeField(filterName).isBeforeOrEqualTo(DateService.setTimeMidnight(dateRange.get(1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private Map<String, FilterMeta> getFilterStateFromIUser() {

return filters;
}


@SuppressWarnings({ "rawtypes", "unchecked" })
private void setDropdownFilterValue(Entry<String, FilterMeta> filter, int filterSize, Class clazz) {
Object[] resultObjectArray = new Object[filterSize];
List<String> statusList = (List<String>) filter.getValue().getFilterValue();
Expand All @@ -133,7 +134,8 @@ private void setDropdownFilterValue(Entry<String, FilterMeta> filter, int filter
}
filter.getValue().setFilterValue(resultObjectArray);
}


@SuppressWarnings("unchecked")
private void setDateFilterValue(Entry<String, FilterMeta> filter, String... filterNames) {
for(String filterName : filterNames) {
if(filterName.equals(filter.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.request.IHttpRequest;
import ch.ivyteam.ivy.security.SecurityManagerFactory;
import ch.ivyteam.ivy.security.exec.Sudo;
import ch.ivyteam.ivy.workflow.IProcessStart;


Expand Down Expand Up @@ -86,7 +86,7 @@ public static String getFullLinkBySignatureAndPattern(String signature, String p
public static List<String> getFullLinksBySignature(String signature) {
List<String> links = new ArrayList<>();
try {
SecurityManagerFactory.getSecurityManager().executeAsSystem(() -> {
Sudo.get(() -> {
if (Ivy.request() instanceof IHttpRequest){
HttpServletRequest httpReq = ((IHttpRequest)Ivy.request()).getHttpServletRequest();
Set<IProcessStart> processStarts = Ivy.wf().findProcessStartsBySignature(signature);
Expand Down
1 change: 1 addition & 0 deletions master-detail-test/config/users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<userConfig>
<user>
<username>tester</username>
<password>tester</password>
<fullName>Tester</fullName>
</user>
</userConfig>
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,61 @@
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

import javax.inject.Named;

import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.openqa.selenium.By;

import com.axonivy.ivy.webtest.IvyWebTest;
import com.axonivy.ivy.webtest.engine.EngineUrl;
import com.codeborne.selenide.Selenide;

import ch.ivyteam.ivy.environment.IvyTest;
import ch.ivyteam.ivy.security.IUser;

/**
* This Stateful Datatable Demo Web test will: 1_ generate the test data in the
* business repo. 2_ login into the system with "Tester" user. 3_ start
* "showProductList" process 4_ verify that the table of "Products" is
* displayed. 5_ add a New "Product" into the business repo.
*
*/
@IvyTest
@IvyWebTest
@TestMethodOrder(OrderAnnotation.class)
public class ProductListDemoWebIT {
private static final String TESTER_USER_NAME = "tester";
private static final String TESTER_PASSWORD = "tester";

@Test
@Order(1)
@BeforeEach
public void createTestData() {
// valid links can be copied from the start page of the internal web-browser
open(EngineUrl.createProcessUrl("master-detail-demo/1887B5D187E6060D/createTestData.ivp"));

}

@Test
@Order(2)
public void showDatatableRepo(@Named("tester") IUser tester) {
assertThat(tester.getDisplayName()).isEqualTo("Tester");

open(EngineUrl.base() + "/dev-workflow-ui/faces/loginTable.xhtml");

$(By.xpath("//tr[@data-rk='Tester']")).$(By.tagName("td")).shouldBe(visible).click();
public void showDatatableRepo() {
loginWithTesterUser();

openProductList();
var sizeOfTable = $(By.id("form:productTable_data")).$$(By.cssSelector("tr")).size();
assertTrue(sizeOfTable > 0);

addNewProduct();
// Wait 1 second to save data
Selenide.sleep(1000);

openProductList();
var sizeOfTableAfterAddedNewProduct = $(By.id("form:productTable_data")).$$(By.cssSelector("tr")).size();
assertTrue(sizeOfTableAfterAddedNewProduct == sizeOfTable + 1);
}

private void loginWithTesterUser() {
open(EngineUrl.base() + "/dev-workflow-ui/faces/login.xhtml");
$(By.id("loginForm:userName")).shouldBe(visible).sendKeys(TESTER_USER_NAME);
$(By.id("loginForm:password")).shouldBe(visible).sendKeys(TESTER_PASSWORD);
$(By.id("loginForm:login")).shouldBe(visible).click();
var sessionUserName = $(By.id("sessionUserName"));
sessionUserName.shouldBe(visible);
assertTrue(TESTER_USER_NAME.equals(sessionUserName.getText()));
}

private void openProductList() {
// valid links can be copied from the start page of the internal web-browser
open(EngineUrl.createProcessUrl("master-detail-demo/188341B154DAFDDD/showProductList.ivp"));
// verify that the registration was successful.
$(By.id("form:productTable")).shouldBe(visible, text("List of products"));
$(By.id("form:productTable_data")).shouldBe(visible);
}

@Test
@Order(3)
public void addNewProduct() {
private void addNewProduct() {
// valid links can be copied from the start page of the internal web-browser
open(EngineUrl.createProcessUrl("master-detail-demo/188341B154DAFDDD/showProductList.ivp"));

Expand Down

0 comments on commit 37fcf91

Please sign in to comment.