Example usage for com.liferay.portal.kernel.service LayoutFriendlyURLLocalServiceUtil fetchLayoutFriendlyURL

List of usage examples for com.liferay.portal.kernel.service LayoutFriendlyURLLocalServiceUtil fetchLayoutFriendlyURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service LayoutFriendlyURLLocalServiceUtil fetchLayoutFriendlyURL.

Prototype

public static com.liferay.portal.kernel.model.LayoutFriendlyURL fetchLayoutFriendlyURL(long plid,
            String languageId, boolean useDefault) 

Source Link

Usage

From source file:com.liferay.layout.service.test.LayoutFriendlyURLServiceTest.java

License:Open Source License

@Test
public void testLocalizedSiteFetchLayoutFriendlyURL() throws Exception {
    List<Locale> availableLocales = Arrays.asList(LocaleUtil.US, LocaleUtil.SPAIN);

    Locale defaultLocale = LocaleUtil.SPAIN;

    _group = GroupTestUtil.updateDisplaySettings(_group.getGroupId(), availableLocales, defaultLocale);

    Map<Locale, String> nameMap = new HashMap<>();

    String name = RandomTestUtil.randomString();

    nameMap.put(LocaleUtil.SPAIN, name);
    nameMap.put(LocaleUtil.US, name);// w  w  w  . j  a va  2  s  .c o m

    Map<Locale, String> friendlyURLMap = new HashMap<>();

    friendlyURLMap.put(LocaleUtil.SPAIN, "/spanishurl");
    friendlyURLMap.put(LocaleUtil.US, "/englishurl");

    Layout layout = LayoutTestUtil.addLayout(_group.getGroupId(), false, nameMap, friendlyURLMap);

    Locale locale = LocaleThreadLocal.getSiteDefaultLocale();

    try {
        LocaleThreadLocal.setSiteDefaultLocale(defaultLocale);

        LayoutFriendlyURL layoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil
                .fetchLayoutFriendlyURL(layout.getPlid(), LocaleUtil.toLanguageId(LocaleUtil.GERMANY), true);

        Assert.assertEquals("/spanishurl", layoutFriendlyURL.getFriendlyURL());
        Assert.assertEquals(LocaleUtil.toLanguageId(defaultLocale), layoutFriendlyURL.getLanguageId());
    } finally {
        LocaleThreadLocal.setSiteDefaultLocale(locale);
    }
}