FrontendTokenDefinitionRegistryImpl implements FrontendTokenDefinitionRegistry { protected String getThemeId(Bundle bundle) { URL url = bundle.getEntry("WEB-INF/liferay-look-and-feel.xml"); if (url == null) { return null; } try (InputStream inputStream = url.openStream()) { String xml = StringUtil.read(inputStream); xml = xml.replaceAll(StringPool.NEW_LINE, StringPool.SPACE); Matcher matcher = _themeIdPattern.matcher(xml); if (!matcher.matches()) { return null; } String themeId = matcher.group(1); String servletContextName = getServletContextName(bundle); if (servletContextName != null) { themeId = themeId + PortletConstants.WAR_SEPARATOR + servletContextName; } return portal.getJsSafePortletId(themeId); } catch (IOException ioException) { throw new RuntimeException( "Unable to read WEB-INF/liferay-look-and-feel.xml", ioException); } }  @Override FrontendTokenDefinition getFrontendTokenDefinition(String themeId); @Override Collection<FrontendTokenDefinition> getFrontendTokenDefinitions();  }
@Test public void testGetThemeIdWithNontheme() { FrontendTokenDefinitionRegistryImpl frontendTokenDefinitionRegistryImpl = new FrontendTokenDefinitionRegistryImpl(); Bundle bundle = Mockito.mock(Bundle.class); Assert.assertNull( frontendTokenDefinitionRegistryImpl.getThemeId(bundle)); }
@Test public void testGetThemeIdWithoutServletContext() { FrontendTokenDefinitionRegistryImpl frontendTokenDefinitionRegistryImpl = new FrontendTokenDefinitionRegistryImpl(); Bundle bundle = Mockito.mock(Bundle.class); Mockito.when( bundle.getEntry("WEB-INF/liferay-look-and-feel.xml") ).thenReturn( _liferayLookAndFeelXMLURL ); Mockito.when( bundle.getHeaders(Mockito.anyString()) ).thenReturn( new HashMapDictionary<>() ); frontendTokenDefinitionRegistryImpl.portal = new PortalImpl(); Assert.assertEquals( "classic", frontendTokenDefinitionRegistryImpl.getThemeId(bundle)); }
@Test public void testGetThemeIdWithServletContext() { FrontendTokenDefinitionRegistryImpl frontendTokenDefinitionRegistryImpl = new FrontendTokenDefinitionRegistryImpl(); Bundle bundle = Mockito.mock(Bundle.class); Mockito.when( bundle.getEntry("WEB-INF/liferay-look-and-feel.xml") ).thenReturn( _liferayLookAndFeelXMLURL ); Dictionary<String, String> headers = new HashMapDictionary<>(); headers.put("Web-ContextPath", "/classic-theme"); Mockito.when( bundle.getHeaders(Mockito.anyString()) ).thenReturn( headers ); frontendTokenDefinitionRegistryImpl.portal = new PortalImpl(); Assert.assertEquals( "classic_WAR_classictheme", frontendTokenDefinitionRegistryImpl.getThemeId(bundle)); }