FragmentFactory { FragmentView getView(FragmentRequest request, String viewName) { if (viewName == null) { viewName = request.getMappedFragmentId(); } String providerAndFragmentId = request.getMappedProviderName() + ":" + viewName; if (!isDevelopmentMode()) { if (viewCache.containsKey(providerAndFragmentId)) { return viewCache.get(providerAndFragmentId); } } if ("*".equals(request.getMappedProviderName())) { for (FragmentViewProvider p : viewProviders.values()) { FragmentView ret = p.getView(viewName); if (ret != null) { if (!isDevelopmentMode()) viewCache.put(providerAndFragmentId, ret); return ret; } } } else { FragmentViewProvider provider = viewProviders.get(request.getMappedProviderName()); if (provider == null) { throw new UiFrameworkException("No view provider: " + request.getMappedProviderName()); } return provider.getView(viewName); } return null; } FragmentFactory(); String process(FragmentContext context); Object getController(String providerName, String fragmentName); boolean isDevelopmentMode(); void setDevelopmentMode(boolean developmentMode); Map<String, FragmentControllerProvider> getControllerProviders(); void setControllerProviders(Map<String, FragmentControllerProvider> newControllerProviders); void setAdditionalControllerProviders(Map<String, FragmentControllerProvider> additional); void addControllerProvider(String key, FragmentControllerProvider provider); Map<String, FragmentViewProvider> getViewProviders(); void setViewProviders(Map<String, FragmentViewProvider> newViewProviders); void setAdditionalViewProviders(Map<String, FragmentViewProvider> additional); void addViewProvider(String key, FragmentViewProvider provider); Object invokeFragmentAction(String providerName, String fragmentName, String action, HttpServletRequest httpRequest, HttpServletResponse httpServletResponse); boolean fragmentExists(String providerName, String fragmentName); T convert(Object obs, Class<T> toType); Map<String, T> getSpringBeansOfType(Class<T> ofType); MessageSource getMessageSource(); ExtensionManager getExtensionManager(); ConversionService getConversionService(); FormatterService getFormatterService(); ServletContext getServletContext(); List<FragmentModelConfigurator> getModelConfigurators(); void setModelConfigurators(List<FragmentModelConfigurator> modelConfigurators); void setPossibleFragmentControllerArgumentProviders(List<PossibleFragmentControllerArgumentProvider> possibleFragmentControllerArgumentProviders); void setPossibleFragmentActionArgumentProviders(List<PossibleFragmentActionArgumentProvider> possibleFragmentActionArgumentProviders); void setSessionFactory(SessionFactory sessionFactory); List<FragmentRequestMapper> getRequestMappers(); void setRequestMappers(List<FragmentRequestMapper> requestMappers);  }
@Test public void getView_shouldGetAViewFromTheRequestedProvider() throws Exception { Assert.assertNotNull(factory.getView(new FragmentRequest("somemodule", "somefragment"), null)); Assert.assertNull(factory.getView(new FragmentRequest("somemodule", "otherfragment"), null)); Assert.assertNull(factory.getView(new FragmentRequest("othermodule", "somefragment"), null)); }
@Test public void getView_shouldGetAViewFromAnyProviderIfNoneIsSpecified() throws Exception { Assert.assertNotNull(factory.getView(new FragmentRequest("*", "somefragment"), null)); Assert.assertNotNull(factory.getView(new FragmentRequest("*", "otherfragment"), null)); Assert.assertNull(factory.getView(new FragmentRequest("*", "nothingwiththisname"), null)); }
@Test(expected=UiFrameworkException.class) public void getView_shouldFailIfAnInvalidProviderNameIsSpecified() throws Exception { factory.getView(new FragmentRequest("unknownmodule", "somefragment"), null); }