contentNode, session).isEmpty());
}
@Test
public void testBulkDiffAssigningUrlMappings() throws Exception {
JCRSessionWrapper session = JCRSessionFactory.getInstance()
.getCurrentUserSession(null, Locale.ENGLISH);
JCRNodeWrapper pageNode = session.getNode(SITECONTENT_ROOT_NODE
+ "/testPage");
VanityUrl englishVanityUrl = new VanityUrl("/testpage", TESTSITE_NAME,
"en");
englishVanityUrl.setActive(true);
VanityUrl englishVanityUrl2 = new VanityUrl("/testpage2",
TESTSITE_NAME, "en");
englishVanityUrl2.setActive(false);
VanityUrl englishVanityUrl3 = new VanityUrl("/testpage/page3",
TESTSITE_NAME, "en");
englishVanityUrl3.setActive(true);
VanityUrl frenchVanityUrl = new VanityUrl("/testpage/french",
TESTSITE_NAME, "fr");
frenchVanityUrl.setActive(true);
VanityUrl frenchVanityUrl2 = new VanityUrl("/testpage/french2",
TESTSITE_NAME, "fr");
frenchVanityUrl2.setDefaultMapping(true);
frenchVanityUrl2.setActive(true);
List<VanityUrl> vanityUrls = new ArrayList<VanityUrl>();
vanityUrls.add(englishVanityUrl);
vanityUrls.add(englishVanityUrl2);
vanityUrls.add(englishVanityUrl3);
vanityUrls.add(frenchVanityUrl);
vanityUrls.add(frenchVanityUrl2);
Set<String> languages = new HashSet<String>();
languages.add("en");
languages.add("fr");
getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
languages);
assertFalse("URL mapping should exist", getVanityUrlService()
.findExistingVanityUrls(englishVanityUrl.getUrl(),
englishVanityUrl.getSite(), Constants.EDIT_WORKSPACE)
.isEmpty());
assertFalse("URL mapping should exist", getVanityUrlService()
.findExistingVanityUrls(englishVanityUrl2.getUrl(),
englishVanityUrl2.getSite(), Constants.EDIT_WORKSPACE)
.isEmpty());
assertFalse("URL mapping should exist", getVanityUrlService()
.findExistingVanityUrls(englishVanityUrl3.getUrl(),
englishVanityUrl3.getSite(), Constants.EDIT_WORKSPACE)
.isEmpty());
assertFalse("URL mapping should exist", getVanityUrlService()
.findExistingVanityUrls(frenchVanityUrl.getUrl(),
frenchVanityUrl.getSite(), Constants.EDIT_WORKSPACE)
.isEmpty());
assertFalse("URL mapping should exist", getVanityUrlService()
.findExistingVanityUrls(frenchVanityUrl2.getUrl(),
frenchVanityUrl2.getSite(), Constants.EDIT_WORKSPACE)
.isEmpty());
englishVanityUrl.setDefaultMapping(true);
englishVanityUrl2.setDefaultMapping(true);
try {
getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
languages);
assertTrue("Exception should have been thrown", false);
} catch (ConstraintViolationException ex) {
// expected as two default mappings on same language - nothing should be saved
}
VanityUrl frenchVanityUrl3 = new VanityUrl("/testpage", TESTSITE_NAME,
"fr");
frenchVanityUrl3.setDefaultMapping(true);
frenchVanityUrl3.setActive(true);
try {
getVanityUrlService().saveVanityUrlMappings(pageNode, vanityUrls,
languages);
assertTrue("Exception should have been thrown", false);
} catch (ConstraintViolationException ex) {
// expected as same mapping is used in English - nothing should be saved
}
List<VanityUrl> vanityUrls_en = getVanityUrlService()
.getVanityUrlsForCurrentLocale(pageNode, session);
String[] expectedUrls_en = new String[] { "/testpage", "/testpage2",
"/testpage/page3" };
assertTrue("Number of Urls is not expected " + expectedUrls_en.length
+ " vs. " + vanityUrls_en.size(),
expectedUrls_en.length == vanityUrls_en.size());
for (VanityUrl vanityUrl_en : vanityUrls_en) {
boolean found = false;
for (String expectedUrl_en : expectedUrls_en) {
if (vanityUrl_en.getUrl().equals(expectedUrl_en)) {
found = true;
break;
}
}
assertTrue("Expected vanity url not found: " + vanityUrl_en, found);
}
JCRSessionWrapper frenchSession = JCRSessionFactory.getInstance()
.getCurrentUserSession(null, Locale.FRENCH);
List<VanityUrl> vanityUrls_fr = getVanityUrlService()
.getVanityUrlsForCurrentLocale(pageNode, frenchSession);