Search in sources :

Example 36 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class OrderBaseTest method setUpNamedOrder.

public Order setUpNamedOrder() throws AddToCartException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());
    Order order = orderService.createNamedOrderForCustomer("Boxes Named Order", customer);
    Product newProduct = addTestProduct("Cube Box", "Boxes");
    Category newCategory = newProduct.getDefaultCategory();
    order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 2), true);
    return order;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Category(org.broadleafcommerce.core.catalog.domain.Category) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Customer(org.broadleafcommerce.profile.core.domain.Customer) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 37 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method addTestProduct.

public Product addTestProduct(String productName, String categoryName, boolean active) {
    Calendar activeStartCal = Calendar.getInstance();
    activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
    Calendar activeEndCal = Calendar.getInstance();
    activeEndCal.add(Calendar.DAY_OF_YEAR, -1);
    Category category = new CategoryImpl();
    category.setName(categoryName);
    category.setActiveStartDate(activeStartCal.getTime());
    category = catalogService.saveCategory(category);
    Sku newSku = new SkuImpl();
    newSku.setName(productName);
    newSku.setRetailPrice(new Money(44.99));
    newSku.setActiveStartDate(activeStartCal.getTime());
    if (!active) {
        newSku.setActiveEndDate(activeEndCal.getTime());
    }
    newSku.setDiscountable(true);
    newSku = catalogService.saveSku(newSku);
    Product newProduct = new ProductImpl();
    newProduct.setDefaultCategory(category);
    newProduct.setDefaultSku(newSku);
    newProduct = catalogService.saveProduct(newProduct);
    return newProduct;
}
Also used : CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) Calendar(java.util.Calendar) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 38 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class OfferDataItemProvider method createOrderWithBundle.

/**
 * Create order with a bundle with two items.  Bundle has a quantity of 2.
 * Bundle item 1 has quantity of 2, bundle item 2 has quantity of 3
 * @return
 */
public Order createOrderWithBundle() {
    Order order = new OrderImpl();
    order.setId(getOrderId());
    Category category1 = new CategoryImpl();
    category1.setName("test1");
    category1.setId(1L);
    Product product1 = new ProductImpl();
    Sku sku1 = new SkuImpl();
    sku1.setName("test1");
    sku1.setId(1L);
    sku1.setDiscountable(true);
    sku1.setRetailPrice(new Money(10D));
    product1.setDefaultSku(sku1);
    CategoryProductXref xref1 = new CategoryProductXrefImpl();
    xref1.setProduct(product1);
    xref1.setCategory(category1);
    category1.getAllProductXrefs().add(xref1);
    Category category2 = new CategoryImpl();
    category2.setName("test2");
    category2.setId(2L);
    Product product2 = new ProductImpl();
    Sku sku2 = new SkuImpl();
    sku2.setName("test2");
    sku2.setId(2L);
    sku2.setDiscountable(true);
    sku2.setRetailPrice(new Money(10D));
    product2.setDefaultSku(sku2);
    CategoryProductXref xref2 = new CategoryProductXrefImpl();
    xref2.setProduct(product2);
    xref2.setCategory(category2);
    category2.getAllProductXrefs().add(xref2);
    ProductBundle pb = new ProductBundleImpl();
    pb.setPricingModel(ProductBundlePricingModelType.ITEM_SUM);
    BundleOrderItem bundleOrderItem = new BundleOrderItemImpl();
    bundleOrderItem.setCategory(category1);
    bundleOrderItem.setName("test1");
    bundleOrderItem.setOrder(order);
    bundleOrderItem.setOrderItemType(OrderItemType.DISCRETE);
    bundleOrderItem.setQuantity(2);
    bundleOrderItem.setId(getOrderItemId());
    bundleOrderItem.setOrder(order);
    bundleOrderItem.setRetailPrice(new Money(10D));
    bundleOrderItem.setProductBundle(pb);
    OrderItemPriceDetail priceDetail = new OrderItemPriceDetailImpl();
    priceDetail.setOrderItem(bundleOrderItem);
    priceDetail.setQuantity(2);
    bundleOrderItem.getOrderItemPriceDetails().add(priceDetail);
    order.getOrderItems().add(bundleOrderItem);
    DiscreteOrderItem orderItem1 = new DiscreteOrderItemImpl();
    orderItem1.setCategory(category1);
    orderItem1.setName("test1");
    orderItem1.setOrder(order);
    orderItem1.setOrderItemType(OrderItemType.DISCRETE);
    orderItem1.setProduct(product1);
    orderItem1.setQuantity(2);
    orderItem1.setSku(sku1);
    orderItem1.setId(getOrderItemId());
    orderItem1.setOrder(order);
    OrderItemPriceDetail priceDetail1 = new OrderItemPriceDetailImpl();
    priceDetail1.setOrderItem(orderItem1);
    priceDetail1.setQuantity(2);
    orderItem1.getOrderItemPriceDetails().add(priceDetail1);
    bundleOrderItem.getDiscreteOrderItems().add(orderItem1);
    DiscreteOrderItem orderItem2 = new DiscreteOrderItemImpl();
    orderItem2.setCategory(category2);
    orderItem2.setName("test2");
    orderItem2.setOrder(order);
    orderItem2.setOrderItemType(OrderItemType.DISCRETE);
    orderItem2.setProduct(product2);
    orderItem2.setQuantity(3);
    orderItem2.setSku(sku2);
    orderItem2.setId(getOrderItemId());
    orderItem2.setOrder(order);
    OrderItemPriceDetail priceDetail2 = new OrderItemPriceDetailImpl();
    priceDetail2.setOrderItem(orderItem2);
    priceDetail2.setQuantity(3);
    orderItem2.getOrderItemPriceDetails().add(priceDetail2);
    bundleOrderItem.getDiscreteOrderItems().add(orderItem2);
    Customer customer = new CustomerImpl();
    customer.setEmailAddress("test@test.com");
    customer.setFirstName("John");
    customer.setLastName("Tester");
    customer.setReceiveEmail(true);
    customer.setRegistered(true);
    order.setCustomer(customer);
    order.setEmailAddress("test@test.com");
    FulfillmentGroup fg1 = new FulfillmentGroupImpl();
    fg1.setId(1L);
    Address address1 = new AddressImpl();
    address1.setAddressLine1("123 Test Road");
    address1.setCity("Dallas");
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    address1.setCountry(country);
    address1.setIsoCountryAlpha2(isoCountry);
    address1.setDefault(true);
    address1.setFirstName("John");
    address1.setLastName("Tester");
    address1.setPostalCode("75244");
    Phone primary = new PhoneImpl();
    primary.setPhoneNumber("972-976-1234");
    address1.setPhonePrimary(primary);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setCountry(country);
    state.setName("Texas");
    address1.setState(state);
    address1.setIsoCountrySubdivision("US-TX");
    fg1.setAddress(address1);
    fg1.setOrder(order);
    fg1.setPrimary(true);
    fg1.setRetailShippingPrice(new Money(10D));
    fg1.setShippingPrice(new Money(10D));
    fg1.setType(FulfillmentType.PHYSICAL_SHIP);
    fg1.setOrder(order);
    FulfillmentGroupItem fgItem1 = new FulfillmentGroupItemImpl();
    fgItem1.setFulfillmentGroup(fg1);
    fgItem1.setOrderItem(orderItem1);
    fgItem1.setQuantity(2);
    // fgItem1.setRetailPrice(new Money(19.99D));
    fg1.getFulfillmentGroupItems().add(fgItem1);
    order.getFulfillmentGroups().add(fg1);
    FulfillmentGroup fg2 = new FulfillmentGroupImpl();
    fg2.setId(2L);
    Address address2 = new AddressImpl();
    address2.setAddressLine1("124 Test Road");
    address2.setCity("Dallas");
    Country country2 = new CountryImpl();
    country2.setAbbreviation("US");
    country2.setName("United States");
    ISOCountry isoCountry2 = new ISOCountryImpl();
    isoCountry2.setAlpha2("US");
    isoCountry2.setName("UNITED STATES");
    address2.setCountry(country2);
    address2.setIsoCountryAlpha2(isoCountry2);
    address2.setDefault(true);
    address2.setFirstName("John");
    address2.setLastName("Tester");
    address2.setPostalCode("75244");
    Phone primary2 = new PhoneImpl();
    primary2.setPhoneNumber("972-976-1234");
    address2.setPhonePrimary(primary2);
    State state2 = new StateImpl();
    state2.setAbbreviation("TX");
    state2.setCountry(country2);
    state2.setName("Texas");
    address2.setState(state2);
    address2.setIsoCountrySubdivision("US-TX");
    fg2.setAddress(address2);
    fg2.setOrder(order);
    fg2.setPrimary(true);
    fg2.setRetailShippingPrice(new Money(20D));
    fg2.setShippingPrice(new Money(20D));
    fg2.setType(FulfillmentType.PHYSICAL_SHIP);
    fg2.setOrder(order);
    FulfillmentGroupItem fgItem2 = new FulfillmentGroupItemImpl();
    fgItem2.setFulfillmentGroup(fg2);
    fgItem2.setOrderItem(orderItem2);
    fgItem2.setQuantity(3);
    // fgItem2.setRetailPrice(new Money(29.99D));
    fg2.getFulfillmentGroupItems().add(fgItem2);
    order.getFulfillmentGroups().add(fg2);
    order.setSubTotal(new Money((2 * 19.99D) + (3 * 29.99D)));
    orders.put(order.getId(), order);
    return order;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) BundleOrderItemImpl(org.broadleafcommerce.core.order.domain.BundleOrderItemImpl) Address(org.broadleafcommerce.profile.core.domain.Address) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderItemPriceDetailImpl(org.broadleafcommerce.core.order.domain.OrderItemPriceDetailImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) Money(org.broadleafcommerce.common.money.Money) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) Phone(org.broadleafcommerce.profile.core.domain.Phone) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) ProductBundleImpl(org.broadleafcommerce.core.catalog.domain.ProductBundleImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) PhoneImpl(org.broadleafcommerce.profile.core.domain.PhoneImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 39 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class OfferDataItemProvider method createBasicOrder.

public Order createBasicOrder() {
    Order order = new OrderImpl();
    order.setId(getOrderId());
    Category category1 = new CategoryImpl();
    category1.setName("test1");
    category1.setId(1L);
    Product product1 = new ProductImpl();
    Sku sku1 = new SkuImpl();
    sku1.setName("test1");
    sku1.setId(1L);
    sku1.setDiscountable(true);
    sku1.setRetailPrice(new Money(19.99D));
    product1.setDefaultSku(sku1);
    CategoryProductXref xref1 = new CategoryProductXrefImpl();
    xref1.setProduct(product1);
    xref1.setCategory(category1);
    category1.getAllProductXrefs().add(xref1);
    Category category2 = new CategoryImpl();
    category2.setName("test2");
    category2.setId(2L);
    Product product2 = new ProductImpl();
    Sku sku2 = new SkuImpl();
    sku2.setName("test2");
    sku2.setId(2L);
    sku2.setDiscountable(true);
    sku2.setRetailPrice(new Money(29.99D));
    product2.setDefaultSku(sku2);
    CategoryProductXref xref2 = new CategoryProductXrefImpl();
    xref2.setProduct(product2);
    xref2.setCategory(category2);
    category2.getAllProductXrefs().add(xref2);
    DiscreteOrderItem orderItem1 = new DiscreteOrderItemImpl();
    orderItem1.setCategory(category1);
    orderItem1.setName("test1");
    orderItem1.setOrder(order);
    orderItem1.setOrderItemType(OrderItemType.DISCRETE);
    orderItem1.setProduct(product1);
    orderItem1.setQuantity(2);
    orderItem1.setSku(sku1);
    orderItem1.setId(getOrderItemId());
    orderItem1.setOrder(order);
    OrderItemPriceDetail priceDetail1 = new OrderItemPriceDetailImpl();
    priceDetail1.setOrderItem(orderItem1);
    priceDetail1.setQuantity(2);
    orderItem1.getOrderItemPriceDetails().add(priceDetail1);
    order.getOrderItems().add(orderItem1);
    DiscreteOrderItem orderItem2 = new DiscreteOrderItemImpl();
    orderItem2.setCategory(category2);
    orderItem2.setName("test2");
    orderItem2.setOrder(order);
    orderItem2.setOrderItemType(OrderItemType.DISCRETE);
    orderItem2.setProduct(product2);
    orderItem2.setQuantity(3);
    orderItem2.setSku(sku2);
    orderItem2.setId(getOrderItemId());
    orderItem2.setOrder(order);
    OrderItemPriceDetail priceDetail2 = new OrderItemPriceDetailImpl();
    priceDetail2.setOrderItem(orderItem2);
    priceDetail2.setQuantity(3);
    orderItem2.getOrderItemPriceDetails().add(priceDetail2);
    order.getOrderItems().add(orderItem2);
    Customer customer = new CustomerImpl();
    customer.setEmailAddress("test@test.com");
    customer.setFirstName("John");
    customer.setLastName("Tester");
    customer.setReceiveEmail(true);
    customer.setRegistered(true);
    order.setCustomer(customer);
    order.setEmailAddress("test@test.com");
    FulfillmentGroup fg1 = new FulfillmentGroupImpl();
    fg1.setId(1L);
    Address address1 = new AddressImpl();
    address1.setAddressLine1("123 Test Road");
    address1.setCity("Dallas");
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    address1.setCountry(country);
    address1.setIsoCountryAlpha2(isoCountry);
    address1.setDefault(true);
    address1.setFirstName("John");
    address1.setLastName("Tester");
    address1.setPostalCode("75244");
    Phone primary = new PhoneImpl();
    primary.setPhoneNumber("972-976-1234");
    address1.setPhonePrimary(primary);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setCountry(country);
    state.setName("Texas");
    address1.setState(state);
    address1.setIsoCountrySubdivision("US-TX");
    fg1.setAddress(address1);
    fg1.setOrder(order);
    fg1.setPrimary(true);
    fg1.setRetailShippingPrice(new Money(10D));
    fg1.setShippingPrice(new Money(10D));
    fg1.setType(FulfillmentType.PHYSICAL_SHIP);
    fg1.setOrder(order);
    FulfillmentGroupItem fgItem1 = new FulfillmentGroupItemImpl();
    fgItem1.setFulfillmentGroup(fg1);
    fgItem1.setOrderItem(orderItem1);
    fgItem1.setQuantity(2);
    // fgItem1.setRetailPrice(new Money(19.99D));
    fg1.getFulfillmentGroupItems().add(fgItem1);
    order.getFulfillmentGroups().add(fg1);
    FulfillmentGroup fg2 = new FulfillmentGroupImpl();
    fg2.setId(2L);
    Address address2 = new AddressImpl();
    address2.setAddressLine1("124 Test Road");
    address2.setCity("Dallas");
    Country country2 = new CountryImpl();
    country2.setAbbreviation("US");
    country2.setName("United States");
    ISOCountry isoCountry2 = new ISOCountryImpl();
    isoCountry2.setAlpha2("US");
    isoCountry2.setName("UNITED STATES");
    address2.setCountry(country2);
    address2.setIsoCountryAlpha2(isoCountry2);
    address2.setDefault(true);
    address2.setFirstName("John");
    address2.setLastName("Tester");
    address2.setPostalCode("75244");
    Phone primary2 = new PhoneImpl();
    primary2.setPhoneNumber("972-976-1234");
    address2.setPhonePrimary(primary2);
    State state2 = new StateImpl();
    state2.setAbbreviation("TX");
    state2.setCountry(country2);
    state2.setName("Texas");
    address2.setState(state2);
    address2.setIsoCountrySubdivision("US-TX");
    fg2.setAddress(address2);
    fg2.setOrder(order);
    fg2.setPrimary(true);
    fg2.setRetailShippingPrice(new Money(20D));
    fg2.setShippingPrice(new Money(20D));
    fg2.setType(FulfillmentType.PHYSICAL_SHIP);
    fg2.setOrder(order);
    FulfillmentGroupItem fgItem2 = new FulfillmentGroupItemImpl();
    fgItem2.setFulfillmentGroup(fg2);
    fgItem2.setOrderItem(orderItem2);
    fgItem2.setQuantity(3);
    // fgItem2.setRetailPrice(new Money(29.99D));
    fg2.getFulfillmentGroupItems().add(fgItem2);
    order.getFulfillmentGroups().add(fg2);
    order.setSubTotal(new Money((2 * 19.99D) + (3 * 29.99D)));
    orders.put(order.getId(), order);
    return order;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) Address(org.broadleafcommerce.profile.core.domain.Address) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderItemPriceDetailImpl(org.broadleafcommerce.core.order.domain.OrderItemPriceDetailImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) Money(org.broadleafcommerce.common.money.Money) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) Phone(org.broadleafcommerce.profile.core.domain.Phone) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) PhoneImpl(org.broadleafcommerce.profile.core.domain.PhoneImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 40 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class CategorySiteMapGeneratorTest method testCategorySiteMapGenerator.

@Test
public void testCategorySiteMapGenerator() throws SiteMapException, IOException {
    Category c1 = new CategoryImpl();
    c1.setUrl("/");
    c1.setId(1l);
    Category c2 = new CategoryImpl();
    c2.setUrl("/hot-sauces");
    c2.setId(2l);
    CategoryMediaXref cmXref1 = new CategoryMediaXrefImpl();
    Media m1 = new MediaImpl();
    m1.setUrl("/img/hot-sauce-img1.png");
    cmXref1.setCategory(c2);
    cmXref1.setMedia(m1);
    c2.getCategoryMediaXref().put("image1", cmXref1);
    CategoryMediaXref cmXref2 = new CategoryMediaXrefImpl();
    Media m2 = new MediaImpl();
    m2.setUrl("/img/hot-sauce-img2.png");
    cmXref2.setCategory(c2);
    cmXref2.setMedia(m2);
    c2.getCategoryMediaXref().put("image2", cmXref2);
    Category c3 = new CategoryImpl();
    c3.setUrl("merchandise");
    c3.setId(3l);
    Category c4 = new CategoryImpl();
    c4.setUrl("/clearance");
    c4.setId(4l);
    Category c5 = new CategoryImpl();
    c5.setUrl("/mens");
    c5.setId(5l);
    Category c6 = new CategoryImpl();
    c6.setUrl("/womens");
    c6.setId(6l);
    List<Category> merchandiseSubcategories = new ArrayList<Category>();
    merchandiseSubcategories.add(c5);
    merchandiseSubcategories.add(c6);
    CategoryDao categoryDao = EasyMock.createMock(CategoryDao.class);
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c1, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c1.getId())).andReturn(c1).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c2, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c2.getId())).andReturn(c2).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c3, 5, 0)).andReturn(merchandiseSubcategories).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c3.getId())).andReturn(c3).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c4, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c4.getId())).andReturn(c4).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c5, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c5.getId())).andReturn(c5).atLeastOnce();
    EasyMock.expect(categoryDao.readActiveSubCategoriesByCategory(c6, 5, 0)).andReturn(new ArrayList<Category>()).atLeastOnce();
    EasyMock.expect(categoryDao.readCategoryById(c6.getId())).andReturn(c6).atLeastOnce();
    // Initialize the mocks
    EasyMock.replay(categoryDao);
    CategorySiteMapGenerator csmg = new CategorySiteMapGenerator(new MockEnvironment());
    csmg.setCategoryDao(categoryDao);
    csmg.setRowLimit(5);
    List<SiteMapGeneratorConfiguration> smgcList = new ArrayList<SiteMapGeneratorConfiguration>();
    CategorySiteMapGeneratorConfiguration c1CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c1CSMGC.setDisabled(false);
    c1CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c1CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c1CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c1CSMGC.setRootCategory(c1);
    c1CSMGC.setStartingDepth(0);
    c1CSMGC.setEndingDepth(1);
    smgcList.add(c1CSMGC);
    CategorySiteMapGeneratorConfiguration c2CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c2CSMGC.setDisabled(false);
    c2CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c2CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c2CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c2CSMGC.setRootCategory(c2);
    c2CSMGC.setStartingDepth(0);
    c2CSMGC.setEndingDepth(1);
    smgcList.add(c2CSMGC);
    CategorySiteMapGeneratorConfiguration c3CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c3CSMGC.setDisabled(false);
    c3CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c3CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c3CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c3CSMGC.setRootCategory(c3);
    c3CSMGC.setStartingDepth(0);
    c3CSMGC.setEndingDepth(1);
    smgcList.add(c3CSMGC);
    CategorySiteMapGeneratorConfiguration c4CSMGC = new CategorySiteMapGeneratorConfigurationImpl();
    c4CSMGC.setDisabled(false);
    c4CSMGC.setSiteMapGeneratorType(SiteMapGeneratorType.CATEGORY);
    c4CSMGC.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    c4CSMGC.setSiteMapPriority(SiteMapPriorityType.POINT5);
    c4CSMGC.setRootCategory(c4);
    c4CSMGC.setStartingDepth(0);
    c4CSMGC.setEndingDepth(1);
    smgcList.add(c4CSMGC);
    testGenerator(smgcList, csmg, 2);
    File file1 = fileService.getResource("/sitemap_index.xml");
    File file2 = fileService.getResource("/sitemap1.xml");
    File file3 = fileService.getResource("/sitemap2.xml");
    File file4 = fileService.getResource("/sitemap3.xml");
    compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap2.xml");
    compareFiles(file4, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap3.xml");
    testGenerator(smgcList, csmg, 50000);
    File file5 = fileService.getResource("/sitemap.xml");
    compareFiles(file5, "src/test/resources/org/broadleafcommerce/sitemap/category/sitemap.xml");
}
Also used : CategorySiteMapGeneratorConfigurationImpl(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfigurationImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) MediaImpl(org.broadleafcommerce.common.media.domain.MediaImpl) CategoryDao(org.broadleafcommerce.core.catalog.dao.CategoryDao) Media(org.broadleafcommerce.common.media.domain.Media) ArrayList(java.util.ArrayList) CategoryMediaXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) MockEnvironment(org.springframework.mock.env.MockEnvironment) CategoryMediaXref(org.broadleafcommerce.core.catalog.domain.CategoryMediaXref) SiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration) CategorySiteMapGeneratorConfiguration(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration) File(java.io.File) CategorySiteMapGeneratorConfiguration(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration) Test(org.junit.Test) SiteMapGeneratorTest(org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)

Aggregations

Category (org.broadleafcommerce.core.catalog.domain.Category)49 Product (org.broadleafcommerce.core.catalog.domain.Product)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)13 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)8 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)7 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)7 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)7 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 ArrayList (java.util.ArrayList)6 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)6 CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)6 Money (org.broadleafcommerce.common.money.Money)5 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Customer (org.broadleafcommerce.profile.core.domain.Customer)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)4 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 Calendar (java.util.Calendar)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3