Search in sources :

Example 1 with MediaImpl

use of org.broadleafcommerce.common.media.domain.MediaImpl in project BroadleafCommerce by BroadleafCommerce.

the class CatalogTest method testCatalog.

@Test(groups = { "testCatalog" })
@Transactional
public void testCatalog() throws Exception {
    Category category = new CategoryImpl();
    category.setName("Soaps");
    category = catalogService.saveCategory(category);
    Category category2 = new CategoryImpl();
    category2.setName("Towels");
    category2 = catalogService.saveCategory(category2);
    Category category3 = new CategoryImpl();
    category3.setName("SuperCategory");
    category3 = catalogService.saveCategory(category3);
    CategoryXref temp = new CategoryXrefImpl();
    temp.setCategory(category);
    temp.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp);
    category3 = catalogService.saveCategory(category3);
    // Test category hierarchy
    Long cat3Id = category3.getId();
    category3 = null;
    category3 = catalogService.findCategoryById(cat3Id);
    category3.getAllParentCategoryXrefs().clear();
    CategoryXref temp2 = new CategoryXrefImpl();
    temp2.setCategory(category);
    temp2.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp2);
    CategoryXref temp3 = new CategoryXrefImpl();
    temp3.setCategory(category2);
    temp3.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp3);
    category3 = catalogService.saveCategory(category3);
    assert category3.getAllParentCategoryXrefs().size() == 2;
    Product newProduct = new ProductImpl();
    Sku newDefaultSku = new SkuImpl();
    newDefaultSku = catalogService.saveSku(newDefaultSku);
    newProduct.setDefaultSku(newDefaultSku);
    newProduct.setName("Lavender Soap");
    Calendar activeStartCal = Calendar.getInstance();
    activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
    newProduct.setActiveStartDate(activeStartCal.getTime());
    // newProduct.setAllParentCategories(allParentCategories);
    newProduct.setDefaultCategory(category);
    newProduct.getAllParentCategoryXrefs().clear();
    newProduct = catalogService.saveProduct(newProduct);
    CategoryProductXref categoryXref = new CategoryProductXrefImpl();
    categoryXref.setProduct(newProduct);
    categoryXref.setCategory(category);
    newProduct.getAllParentCategoryXrefs().add(categoryXref);
    CategoryProductXref categoryXref2 = new CategoryProductXrefImpl();
    categoryXref2.setProduct(newProduct);
    categoryXref2.setCategory(category2);
    newProduct.getAllParentCategoryXrefs().add(categoryXref2);
    newProduct = catalogService.saveProduct(newProduct);
    Long newProductId = newProduct.getId();
    Product testProduct = catalogService.findProductById(newProductId);
    assert testProduct.getId().equals(testProduct.getId());
    Category testCategory = catalogService.findCategoryByName("Soaps");
    assert testCategory.getId().equals(category.getId());
    testCategory = catalogService.findCategoryById(category.getId());
    assert testCategory.getId().equals(category.getId());
    Media media = new MediaImpl();
    media.setAltText("test");
    media.setTitle("large");
    media.setUrl("http://myUrl");
    category.getCategoryMediaXref().put("large", new CategoryMediaXrefImpl(category, media, "large"));
    catalogService.saveCategory(testCategory);
    testCategory = catalogService.findCategoryById(category.getId());
    assert (testCategory.getCategoryMediaXref().get("large") != null);
    List<Category> categories = catalogService.findAllCategories();
    assert categories != null && categories.size() == 3;
    List<Product> products = catalogService.findAllProducts();
    boolean foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    products = catalogService.findProductsByName(newProduct.getName());
    foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    Sku newSku = new SkuImpl();
    newSku.setName("Under Armor T-Shirt -- Red");
    newSku.setRetailPrice(new Money(14.99));
    newSku.setActiveStartDate(activeStartCal.getTime());
    newSku = catalogService.saveSku(newSku);
    List<Sku> allSkus = new ArrayList<>();
    allSkus.add(newSku);
    newProduct.setAdditionalSkus(allSkus);
    newProduct = catalogService.saveProduct(newProduct);
    Long skuId = newProduct.getSkus().get(0).getId();
    Sku testSku = catalogService.findSkuById(skuId);
    assert testSku.getId().equals(skuId);
    List<Sku> testSkus = catalogService.findAllSkus();
    boolean foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
    List<Long> skuIds = new ArrayList<>();
    skuIds.add(skuId);
    testSkus = catalogService.findSkusByIds(skuIds);
    foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) MediaImpl(org.broadleafcommerce.common.media.domain.MediaImpl) Calendar(java.util.Calendar) Media(org.broadleafcommerce.common.media.domain.Media) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) CategoryMediaXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MediaImpl

use of org.broadleafcommerce.common.media.domain.MediaImpl 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

ArrayList (java.util.ArrayList)2 Media (org.broadleafcommerce.common.media.domain.Media)2 MediaImpl (org.broadleafcommerce.common.media.domain.MediaImpl)2 Category (org.broadleafcommerce.core.catalog.domain.Category)2 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)2 CategoryMediaXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl)2 File (java.io.File)1 Calendar (java.util.Calendar)1 Money (org.broadleafcommerce.common.money.Money)1 SiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.SiteMapGeneratorConfiguration)1 SiteMapGeneratorTest (org.broadleafcommerce.common.sitemap.service.SiteMapGeneratorTest)1 CategoryDao (org.broadleafcommerce.core.catalog.dao.CategoryDao)1 CategoryMediaXref (org.broadleafcommerce.core.catalog.domain.CategoryMediaXref)1 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)1 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)1 CategorySiteMapGeneratorConfiguration (org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration)1 CategorySiteMapGeneratorConfigurationImpl (org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfigurationImpl)1 CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)1 CategoryXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1