Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-ale-sbarra committed Jan 23, 2025
1 parent f5831be commit 0d2adf8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public ProductEntityModel(List<EntityField> entityFields) {
new CollectionEntityField(
new StringEntityField(
"categoryNames", locale -> "assetCategoryNames")),
new CollectionEntityField(
new StringEntityField("gtins", locale -> CPField.GTINS)),
new CollectionEntityField(
new StringEntityField(
"specificationNames",
locale -> CPField.SPECIFICATION_NAMES)),
new CollectionEntityField(
new StringEntityField(
"specificationValues",
locale -> CPField.SPECIFICATION_VALUES_NAMES)),
new CollectionEntityField(
new StringEntityField("tags", locale -> "assetTagNames")),
new ComplexEntityField("customFields", entityFields),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.ProductVirtualSettings;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.ProductVirtualSettingsFileEntry;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.Sku;
import com.liferay.headless.commerce.admin.catalog.client.pagination.Page;
import com.liferay.headless.commerce.admin.catalog.client.pagination.Pagination;
import com.liferay.headless.commerce.admin.catalog.client.problem.Problem;
import com.liferay.headless.commerce.admin.catalog.client.resource.v1_0.ProductResource;
import com.liferay.headless.commerce.core.util.LanguageUtils;
import com.liferay.petra.function.transform.TransformUtil;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.service.ServiceContext;
Expand Down Expand Up @@ -166,11 +169,68 @@ public void testGetProductByExternalReferenceCodeByVersion()
public void testGetProductByVersion() throws Exception {
}

@Ignore
@Override
@Test
public void testGetProductsPage() throws Exception {
super.testGetProductsPage();
_testGetProductsPage();
_testGetProductsPageWithFilter();
}

private void _testGetProductsPageWithFilter() throws Exception {
Page<Product> page = productResource.getProductsPage(
null, null, Pagination.of(1, 10), null);

long totalCount = page.getTotalCount();

Product product1 = testGetProductsPage_addProduct(_randomProductWithSku());

Product product2 = testGetProductsPage_addProduct(randomProduct());

page = productResource.getProductsPage(
null, null, Pagination.of(1, 10), null);

Assert.assertEquals(totalCount + 2, page.getTotalCount());

assertContains(product1, (List<Product>)page.getItems());
assertContains(product2, (List<Product>)page.getItems());
assertValid(page, testGetProductsPage_getExpectedActions());

page = productResource.getProductsPage(null,
"(gtins/any(x:contains(x, 'GTIN-TEST')))",
Pagination.of(1, 10), null);

Assert.assertEquals(totalCount + 1, page.getTotalCount());

assertContains(product1, (List<Product>)page.getItems());
assertValid(page, testGetProductsPage_getExpectedActions());

productResource.deleteProduct(product1.getProductId());

productResource.deleteProduct(product2.getProductId());
}

private void _testGetProductsPage() throws Exception {
Page<Product> page = productResource.getProductsPage(
null, null, Pagination.of(1, 10), null);

long totalCount = page.getTotalCount();

Product product1 = testGetProductsPage_addProduct(randomProduct());

Product product2 = testGetProductsPage_addProduct(randomProduct());

page = productResource.getProductsPage(
null, null, Pagination.of(1, 10), null);

Assert.assertEquals(totalCount + 2, page.getTotalCount());

assertContains(product1, (List<Product>)page.getItems());
assertContains(product2, (List<Product>)page.getItems());
assertValid(page, testGetProductsPage_getExpectedActions());

productResource.deleteProduct(product1.getProductId());

productResource.deleteProduct(product2.getProductId());
}

@Ignore
Expand Down Expand Up @@ -457,8 +517,7 @@ private Product _randomProductWithSku() throws Exception {
expirationDate = RandomTestUtil.nextDate();
externalReferenceCode = StringUtil.toLowerCase(
RandomTestUtil.randomString());
gtin = StringUtil.toLowerCase(
RandomTestUtil.randomString());
gtin = "GTIN-TEST";
height = RandomTestUtil.randomDouble();
inventoryLevel = RandomTestUtil.randomInt();
manufacturerPartNumber = StringUtil.toLowerCase(
Expand Down Expand Up @@ -727,4 +786,4 @@ private void _testPostProductWithWorkflowSingleApprover() throws Exception {
private WorkflowDefinitionLinkLocalService
_workflowDefinitionLinkLocalService;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.liferay.headless.commerce.delivery.catalog.internal.odata.entity.v1_0;

import com.liferay.commerce.product.constants.CPField;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.odata.entity.CollectionEntityField;
import com.liferay.portal.odata.entity.ComplexEntityField;
Expand All @@ -30,6 +31,16 @@ public ProductEntityModel(List<EntityField> entityFields) {
new CollectionEntityField(
new StringEntityField(
"categoryNames", locale -> "assetCategoryNames")),
new CollectionEntityField(
new StringEntityField("gtins", locale -> CPField.GTINS)),
new CollectionEntityField(
new StringEntityField(
"specificationNames",
locale -> CPField.SPECIFICATION_NAMES)),
new CollectionEntityField(
new StringEntityField(
"specificationValues",
locale -> CPField.SPECIFICATION_VALUES_NAMES)),
new CollectionEntityField(
new StringEntityField("tags", locale -> "assetTagNames")),
new ComplexEntityField("customFields", entityFields),
Expand Down

0 comments on commit 0d2adf8

Please sign in to comment.