StyleRepositoryServiceImpl implements StyleRepositoryService { @Override public Style getStyle(String styleName) { if (StringUtils.isBlank(styleName)) { throw new RiceIllegalArgumentException("styleName was null or blank"); } StyleBo style = getStyleByName(styleName); if (style == null) { String propertyName = STYLE_CONFIG_PREFIX + "." + styleName; String location = ConfigContext.getCurrentContextConfig().getProperty(propertyName); if (location != null) { final InputStream xml; try { xml = RiceUtilities.getResourceAsStream(location); } catch (MalformedURLException e) { throw new RiceRuntimeException(getUnableToLoadMessage(propertyName, location), e); } catch (IOException e) { throw new RiceRuntimeException(getUnableToLoadMessage(propertyName, location), e); } if (xml == null) { throw new RiceRuntimeException(getUnableToLoadMessage(propertyName, location) + ", no such file"); } LOG.info("Automatically loading style '" + styleName + "' from '" + location + "' as configured by " + propertyName); List<Style> styles = styleXmlParser.parseStyles(xml); for (Style autoLoadedStyle : styles) { if (autoLoadedStyle.getName().equals(styleName)) { return autoLoadedStyle; } } throw new RiceRuntimeException("Failed to locate auto-loaded style '" + styleName + "' after successful parsing of file from '" + location + "' as configured by " + propertyName); } } return StyleBo.to(style); }  void setStyleXmlParser(StyleXmlParser styleXmlParser); @Override Style getStyle(String styleName); @Override void saveStyle(Style data); @Override List<String> getAllStyleNames(); DataObjectService getDataObjectService(); @Required void setDataObjectService(DataObjectService dataObjectService); @Required void setStyleDao(StyleDao styleDao);  }
@Test(expected = IllegalArgumentException.class) public void testGetStyle_nullStyleName() throws Exception{ getStyleRepositoryService().getStyle(null); }
@Test(expected = IllegalArgumentException.class) public void testGetStyle_emptyStyleName() throws Exception{ getStyleRepositoryService().getStyle(""); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<StyleBo>(StyleBo.class)), any( QueryByCriteria.class)); }
@Test(expected = IllegalArgumentException.class) public void testGetStyle_blankStyleName() throws Exception{ getStyleRepositoryService().getStyle(" "); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<StyleBo>(StyleBo.class)), any( QueryByCriteria.class)); }
@Test public void testGetStyle_valid() throws Exception{ setDataObjectServiceFetchStyle(style); Style styleFetched = getStyleRepositoryService().getStyle(NAME); assertTrue("Style fetched correctly",styleFetched != null && StringUtils.equals(styleFetched.getName(),style.getName())); verify(dataObjectService,times(1)).findMatching(Matchers.argThat( new ClassOrSubclassMatcher<StyleBo>(StyleBo.class)), any( QueryByCriteria.class)); }