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 4fb6d05
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ public static CPOptionValue addCPOptionValue(CPOption cpOption, String key)
ServiceContextTestUtil.getServiceContext());
}

public static CPSpecificationOption addCPSpecificationOption(long groupId)
public static CPSpecificationOption addCPSpecificationOption(
long groupId, boolean facetable)
throws PortalException {

ServiceContext serviceContext =
Expand All @@ -750,7 +751,7 @@ public static CPSpecificationOption addCPSpecificationOption(long groupId)
return CPSpecificationOptionLocalServiceUtil.addCPSpecificationOption(
RandomTestUtil.randomString(), serviceContext.getUserId(), 0, null,
RandomTestUtil.randomLocaleStringMap(),
RandomTestUtil.randomLocaleStringMap(), false,
RandomTestUtil.randomLocaleStringMap(), facetable,
RandomTestUtil.randomString(), RandomTestUtil.randomDouble(),
serviceContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ public void testCopyCPDefinition() throws PortalException {
true);

CPSpecificationOption cpSpecificationOption =
CPTestUtil.addCPSpecificationOption(_commerceCatalog.getGroupId());
CPTestUtil.addCPSpecificationOption(
_commerceCatalog.getGroupId(), false);

CPDefinitionSpecificationOptionValue
cpDefinitionSpecificationOptionValue1 =
Expand Down
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 @@ -14,19 +14,25 @@
import com.liferay.commerce.price.list.service.CommercePriceListLocalService;
import com.liferay.commerce.product.model.CPDefinition;
import com.liferay.commerce.product.model.CPInstance;
import com.liferay.commerce.product.model.CPOptionCategory;
import com.liferay.commerce.product.model.CPSpecificationOption;
import com.liferay.commerce.product.model.CommerceCatalog;
import com.liferay.commerce.product.model.CommerceChannel;
import com.liferay.commerce.product.service.CPDefinitionLocalService;
import com.liferay.commerce.product.service.CommerceCatalogLocalServiceUtil;
import com.liferay.commerce.product.test.util.CPTestUtil;
import com.liferay.commerce.product.type.simple.constants.SimpleCPTypeConstants;
import com.liferay.commerce.product.type.virtual.constants.VirtualCPTypeConstants;
import com.liferay.commerce.test.util.CommerceTestUtil;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.Product;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.ProductAccountGroup;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.ProductChannel;
import com.liferay.headless.commerce.admin.catalog.client.dto.v1_0.ProductSpecification;
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;
Expand All @@ -43,6 +49,7 @@
import com.liferay.portal.kernel.util.Base64;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
Expand Down Expand Up @@ -112,6 +119,11 @@ public void setUp() throws Exception {
_commerceCatalog.getGroupId(), user.getUserId(),
commerceCurrency.getCode(), "promotion",
RandomTestUtil.randomString(), serviceContext);

_cpOptionCategory = CPTestUtil.addCPOptionCategory(
testGroup.getGroupId());
_cpSpecificationOption = CPTestUtil.addCPSpecificationOption(
testGroup.getGroupId(), true);
}

@After
Expand Down Expand Up @@ -166,11 +178,11 @@ public void testGetProductByExternalReferenceCodeByVersion()
public void testGetProductByVersion() throws Exception {
}

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

@Ignore
Expand Down Expand Up @@ -431,6 +443,42 @@ protected Product testPostProductClone_addProduct(Product product)
return productResource.postProduct(product);
}

private Product _randomProductWithProductSpecification() throws Exception {
return new Product() {
{
active = true;
catalogId = _commerceCatalog.getCommerceCatalogId();
description = LanguageUtils.getLanguageIdMap(
RandomTestUtil.randomLocaleStringMap());
externalReferenceCode = StringUtil.toLowerCase(
RandomTestUtil.randomString());
name = LanguageUtils.getLanguageIdMap(
RandomTestUtil.randomLocaleStringMap());
productType = SimpleCPTypeConstants.NAME;
productSpecifications = new ProductSpecification[] {
new ProductSpecification() {
{
externalReferenceCode =
RandomTestUtil.randomString();
label = LanguageUtils.getLanguageIdMap(
RandomTestUtil.randomLocaleStringMap());
optionCategoryExternalReferenceCode =
_cpOptionCategory.getExternalReferenceCode();
priority = RandomTestUtil.randomDouble();
specificationKey = _cpSpecificationOption.getKey();
value = LanguageUtils.getLanguageIdMap(
HashMapBuilder.put(
LocaleUtil.getDefault(), "test"
).build());
}
}
};
shortDescription = LanguageUtils.getLanguageIdMap(
RandomTestUtil.randomLocaleStringMap());
}
};
}

private Product _randomProductWithSku() throws Exception {
return new Product() {
{
Expand All @@ -457,8 +505,7 @@ private Product _randomProductWithSku() throws Exception {
expirationDate = RandomTestUtil.nextDate();
externalReferenceCode = StringUtil.toLowerCase(
RandomTestUtil.randomString());
gtin = StringUtil.toLowerCase(
RandomTestUtil.randomString());
gtin = "test";
height = RandomTestUtil.randomDouble();
inventoryLevel = RandomTestUtil.randomInt();
manufacturerPartNumber = StringUtil.toLowerCase(
Expand All @@ -483,6 +530,74 @@ private Product _randomProductWithSku() throws Exception {
};
}

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());
}

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(
_randomProductWithProductSpecification());

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, 'test')))", Pagination.of(1, 10),
null);

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

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

page = productResource.getProductsPage(
null, "(specificationValues/any(x:contains(x, 'test')))",
Pagination.of(1, 10), null);

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

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

productResource.deleteProduct(product1.getProductId());

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

private Product _testPatchProduct_addProduct() throws Exception {
return productResource.postProduct(randomProduct());
}
Expand Down Expand Up @@ -720,6 +835,12 @@ private void _testPostProductWithWorkflowSingleApprover() throws Exception {
@Inject
private CPDefinitionLocalService _cpDefinitionLocalService;

@DeleteAfterTestRun
private CPOptionCategory _cpOptionCategory;

@DeleteAfterTestRun
private CPSpecificationOption _cpSpecificationOption;

@Inject
private UserLocalService _userLocalService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void setUp() throws Exception {
_cpOptionCategory = CPTestUtil.addCPOptionCategory(
testGroup.getGroupId());
_cpSpecificationOption = CPTestUtil.addCPSpecificationOption(
testGroup.getGroupId());
testGroup.getGroupId(), false);
}

@Override
Expand Down
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 4fb6d05

Please sign in to comment.