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);