Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPD-46233 wip #6169

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/apps/commerce/commerce-product-test-util/bnd.bnd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Bundle-Name: Liferay Commerce Product Test Utilities
Bundle-SymbolicName: com.liferay.commerce.product.test.util
Bundle-Version: 9.5.3
Bundle-Version: 10.0.0
Export-Package: com.liferay.commerce.product.test.util
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
@@ -1 +1 @@
version 6.5.0
version 7.0.0
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