Search in sources :

Example 1 with CustomUrlSiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class CustomUrlSiteMapGeneratorTest method testCustomUrlSiteMapGenerator.

@Test
public void testCustomUrlSiteMapGenerator() throws SiteMapException, IOException {
    CustomUrlSiteMapGeneratorConfiguration smgc = getConfiguration();
    testGenerator(smgc, new CustomUrlSiteMapGenerator());
    File file1 = fileService.getResource("/sitemap_index.xml");
    File file2 = fileService.getResource("/sitemap1.xml");
    File file3 = fileService.getResource("/sitemap2.xml");
    compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap2.xml");
}
Also used : CustomUrlSiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration) CustomUrlSiteMapGenerator(org.broadleafcommerce.common.sitemap.service.CustomUrlSiteMapGenerator) File(java.io.File) Test(org.junit.Test)

Example 2 with CustomUrlSiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class CustomUrlSiteMapGenerator method addSiteMapEntries.

@Override
public void addSiteMapEntries(SiteMapGeneratorConfiguration smgc, SiteMapBuilder siteMapBuilder) {
    for (SiteMapUrlEntry urlEntry : ((CustomUrlSiteMapGeneratorConfiguration) smgc).getCustomURLEntries()) {
        if (StringUtils.isEmpty(urlEntry.getLocation())) {
            continue;
        }
        SiteMapURLWrapper siteMapUrl = new SiteMapURLWrapper();
        // location
        siteMapUrl.setLoc(generateUri(siteMapBuilder, urlEntry));
        // change frequency
        if (urlEntry.getSiteMapChangeFreq() != null) {
            siteMapUrl.setChangeFreqType(urlEntry.getSiteMapChangeFreq());
        } else {
            siteMapUrl.setChangeFreqType(smgc.getSiteMapChangeFreq());
        }
        // priority
        if (urlEntry.getSiteMapPriority() != null) {
            siteMapUrl.setPriorityType(urlEntry.getSiteMapPriority());
        } else {
            siteMapUrl.setPriorityType(smgc.getSiteMapPriority());
        }
        // lastModDate
        siteMapUrl.setLastModDate(generateDate(urlEntry));
        siteMapBuilder.addUrl(siteMapUrl);
    }
}
Also used : CustomUrlSiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration) SiteMapUrlEntry(org.broadleafcommerce.common.sitemap.domain.SiteMapUrlEntry) SiteMapURLWrapper(org.broadleafcommerce.common.sitemap.wrapper.SiteMapURLWrapper)

Example 3 with CustomUrlSiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class CustomUrlSiteMapGeneratorTest method testSiteMapsWithSiteContext.

@Test
public void testSiteMapsWithSiteContext() throws SiteMapException, IOException {
    BroadleafRequestContext brc = new BroadleafRequestContext();
    BroadleafRequestContext.setBroadleafRequestContext(brc);
    Site site = new SiteImpl();
    site.setId(256L);
    brc.setSite(site);
    CustomUrlSiteMapGeneratorConfiguration smgc = getConfiguration();
    testGenerator(smgc, new CustomUrlSiteMapGenerator());
    File file1 = fileService.getResource("/sitemap_index.xml");
    File file2 = fileService.getResource("/sitemap1.xml");
    File file3 = fileService.getResource("/sitemap2.xml");
    assertThat(file1.getAbsolutePath(), containsString("site-256"));
    assertThat(file2.getAbsolutePath(), containsString("site-256"));
    assertThat(file3.getAbsolutePath(), containsString("site-256"));
    compareFiles(file1, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap_index.xml");
    compareFiles(file2, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap1.xml");
    compareFiles(file3, "src/test/resources/org/broadleafcommerce/sitemap/custom/sitemap2.xml");
    // Remove the request context from thread local so it doesn't get in the way of subsequent tests
    BroadleafRequestContext.setBroadleafRequestContext(null);
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) SiteImpl(org.broadleafcommerce.common.site.domain.SiteImpl) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CustomUrlSiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration) CustomUrlSiteMapGenerator(org.broadleafcommerce.common.sitemap.service.CustomUrlSiteMapGenerator) File(java.io.File) Test(org.junit.Test)

Example 4 with CustomUrlSiteMapGeneratorConfiguration

use of org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration in project BroadleafCommerce by BroadleafCommerce.

the class CustomUrlSiteMapGeneratorTest method getConfiguration.

public CustomUrlSiteMapGeneratorConfiguration getConfiguration() {
    SiteMapUrlEntry urlEntry1 = new SiteMapUrlEntryImpl();
    urlEntry1.setLastMod(new Date());
    urlEntry1.setLocation("http://www.heatclinic.com/1");
    urlEntry1.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    urlEntry1.setSiteMapPriority(SiteMapPriorityType.POINT5);
    SiteMapUrlEntry urlEntry2 = new SiteMapUrlEntryImpl();
    urlEntry2.setLastMod(new Date());
    urlEntry2.setLocation("2");
    urlEntry2.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    urlEntry2.setSiteMapPriority(SiteMapPriorityType.POINT5);
    SiteMapUrlEntry urlEntry3 = new SiteMapUrlEntryImpl();
    urlEntry3.setLastMod(new Date());
    urlEntry3.setLocation("/3");
    urlEntry3.setSiteMapChangeFreq(SiteMapChangeFreqType.HOURLY);
    urlEntry3.setSiteMapPriority(SiteMapPriorityType.POINT5);
    List<SiteMapUrlEntry> urlEntries = new ArrayList<>();
    urlEntries.add(urlEntry1);
    urlEntries.add(urlEntry2);
    urlEntries.add(urlEntry3);
    CustomUrlSiteMapGeneratorConfiguration smgc = new CustomUrlSiteMapGeneratorConfigurationImpl();
    smgc.setDisabled(false);
    smgc.setSiteMapGeneratorType(SiteMapGeneratorType.CUSTOM);
    smgc.setCustomURLEntries(urlEntries);
    return smgc;
}
Also used : CustomUrlSiteMapGeneratorConfigurationImpl(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfigurationImpl) SiteMapUrlEntryImpl(org.broadleafcommerce.common.sitemap.domain.SiteMapUrlEntryImpl) CustomUrlSiteMapGeneratorConfiguration(org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration) ArrayList(java.util.ArrayList) SiteMapUrlEntry(org.broadleafcommerce.common.sitemap.domain.SiteMapUrlEntry) Date(java.util.Date)

Aggregations

CustomUrlSiteMapGeneratorConfiguration (org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfiguration)4 File (java.io.File)2 SiteMapUrlEntry (org.broadleafcommerce.common.sitemap.domain.SiteMapUrlEntry)2 CustomUrlSiteMapGenerator (org.broadleafcommerce.common.sitemap.service.CustomUrlSiteMapGenerator)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Site (org.broadleafcommerce.common.site.domain.Site)1 SiteImpl (org.broadleafcommerce.common.site.domain.SiteImpl)1 CustomUrlSiteMapGeneratorConfigurationImpl (org.broadleafcommerce.common.sitemap.domain.CustomUrlSiteMapGeneratorConfigurationImpl)1 SiteMapUrlEntryImpl (org.broadleafcommerce.common.sitemap.domain.SiteMapUrlEntryImpl)1 SiteMapURLWrapper (org.broadleafcommerce.common.sitemap.wrapper.SiteMapURLWrapper)1 BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)1