001
014
015 package com.liferay.portlet.shopping.util.test;
016
017 import com.liferay.portal.kernel.test.util.RandomTestUtil;
018 import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
019 import com.liferay.portal.kernel.test.util.TestPropsValues;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.service.ServiceContext;
022 import com.liferay.portlet.shopping.model.ShoppingCategory;
023 import com.liferay.portlet.shopping.model.ShoppingCategoryConstants;
024 import com.liferay.portlet.shopping.model.ShoppingItem;
025 import com.liferay.portlet.shopping.model.ShoppingItemField;
026 import com.liferay.portlet.shopping.model.ShoppingItemPrice;
027 import com.liferay.portlet.shopping.service.ShoppingCategoryServiceUtil;
028 import com.liferay.portlet.shopping.service.ShoppingItemServiceUtil;
029
030 import java.io.File;
031
032 import java.util.ArrayList;
033 import java.util.List;
034
035
038 public class ShoppingTestUtil {
039
040 public static ShoppingCategory addCategory(long groupId) throws Exception {
041 return addCategory(
042 groupId, ShoppingCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
043 }
044
045 public static ShoppingCategory addCategory(
046 long groupId, long parentCategoryId)
047 throws Exception {
048
049 ServiceContext serviceContext =
050 ServiceContextTestUtil.getServiceContext(groupId);
051
052 return addCategory(
053 RandomTestUtil.randomString(), parentCategoryId, serviceContext);
054 }
055
056 public static ShoppingCategory addCategory(ServiceContext serviceContext)
057 throws Exception {
058
059 return ShoppingCategoryServiceUtil.addCategory(
060 TestPropsValues.getUserId(), RandomTestUtil.randomString(),
061 StringPool.BLANK, serviceContext);
062 }
063
064 public static ShoppingCategory addCategory(
065 String name, long groupId, long parentCategoryId)
066 throws Exception {
067
068 ServiceContext serviceContext =
069 ServiceContextTestUtil.getServiceContext(groupId);
070
071 return addCategory(name, parentCategoryId, serviceContext);
072 }
073
074 public static ShoppingCategory addCategory(
075 String name, long parentCategoryId, ServiceContext serviceContext)
076 throws Exception {
077
078 return ShoppingCategoryServiceUtil.addCategory(
079 parentCategoryId, name, StringPool.BLANK, serviceContext);
080 }
081
082 public static ShoppingItem addItem(long groupId) throws Exception {
083 return addItem(
084 groupId, ShoppingCategoryConstants.DEFAULT_PARENT_CATEGORY_ID);
085 }
086
087 public static ShoppingItem addItem(long groupId, long parentCategoryId)
088 throws Exception {
089
090 ServiceContext serviceContext =
091 ServiceContextTestUtil.getServiceContext(groupId);
092
093 return addItem(
094 RandomTestUtil.randomString(), parentCategoryId, serviceContext);
095 }
096
097 public static ShoppingItem addItem(
098 String name, long groupId, long parentCategoryId)
099 throws Exception {
100
101 ServiceContext serviceContext =
102 ServiceContextTestUtil.getServiceContext(groupId);
103
104 return addItem(name, parentCategoryId, serviceContext);
105 }
106
107 public static ShoppingItem addItem(
108 String name, long parentCategoryId, ServiceContext serviceContext)
109 throws Exception {
110
111 long groupId = serviceContext.getScopeGroupId();
112 String sku = RandomTestUtil.randomString();
113 String description = RandomTestUtil.randomString();
114 String properties = StringPool.BLANK;
115 String fieldsQuantities = RandomTestUtil.randomString();
116 boolean requiresShipping = RandomTestUtil.randomBoolean();
117 int stockQuantity = RandomTestUtil.randomInt();
118 boolean featured = RandomTestUtil.randomBoolean();
119 Boolean sale = RandomTestUtil.randomBoolean();
120 boolean smallImage = false;
121 String smallImageURL = null;
122 File smallImageFile = null;
123 boolean mediumImage = false;
124 String mediumImageURL = null;
125 File mediumImageFile = null;
126 boolean largeImage = false;
127 String largeImageURL = null;
128 File largeImageFile = null;
129 List<ShoppingItemField> itemFields = new ArrayList<>();
130 List<ShoppingItemPrice> itemPrices = new ArrayList<>();
131
132 return ShoppingItemServiceUtil.addItem(
133 groupId, parentCategoryId, sku, name, description, properties,
134 fieldsQuantities, requiresShipping, stockQuantity, featured, sale,
135 smallImage, smallImageURL, smallImageFile, mediumImage,
136 mediumImageURL, mediumImageFile, largeImage, largeImageURL,
137 largeImageFile, itemFields, itemPrices, serviceContext);
138 }
139
140 }