CompleteAutoloadTilesContainerFactory extends BasicTilesContainerFactory { @Override protected List<ApplicationResource> getSources(ApplicationContext applicationContext) { Collection<ApplicationResource> webINFSet = applicationContext.getResources("/WEB-INFtiles*.xml"); Collection<ApplicationResource> metaINFSet = applicationContext .getResources("classpath*:META-INFtiles*.xml"); List<ApplicationResource> filteredResources = new ArrayList<ApplicationResource>(); if (webINFSet != null) { for (ApplicationResource resource : webINFSet) { if (Locale.ROOT.equals(resource.getLocale())) { filteredResources.add(resource); } } } if (metaINFSet != null) { for (ApplicationResource resource : metaINFSet) { if (Locale.ROOT.equals(resource.getLocale())) { filteredResources.add(resource); } } } return filteredResources; }  @Override TilesContainer createDecoratedContainer(TilesContainer originalContainer,
            ApplicationContext applicationContext);  }
@Test public void testGetSources() throws IOException { ApplicationContext applicationContext = createMock(ApplicationContext.class); ApplicationResource resource1 = createMock(ApplicationResource.class); expect(resource1.getLocale()).andReturn(Locale.ROOT); ApplicationResource resource2 = createMock(ApplicationResource.class); expect(resource2.getLocale()).andReturn(Locale.ITALY); ApplicationResource resource3 = createMock(ApplicationResource.class); expect(resource3.getLocale()).andReturn(Locale.ROOT); Collection<ApplicationResource> resourceSet1 = new HashSet<ApplicationResource>(); resourceSet1.add(resource1); resourceSet1.add(resource2); Collection<ApplicationResource> resourceSet2 = new HashSet<ApplicationResource>(); resourceSet2.add(resource3); expect(applicationContext.getResources("/WEB-INFtiles*.xml")).andReturn(resourceSet1); expect(applicationContext.getResources("classpath*:META-INFtiles*.xml")).andReturn(resourceSet2); replay(applicationContext, resource1, resource2, resource3); List<ApplicationResource> urls = factory.getSources(applicationContext); assertEquals(2, urls.size()); assertTrue(urls.contains(resource1)); assertTrue(urls.contains(resource3)); verify(applicationContext, resource1, resource2, resource3); }
@Test public void testTILES484first() throws IOException { ApplicationContext applicationContext = createMock(ApplicationContext.class); ApplicationResource resource = createMock(ApplicationResource.class); expect(resource.getLocale()).andReturn(Locale.ROOT); Collection<ApplicationResource> resourceSet = new HashSet<ApplicationResource>(); resourceSet.add(resource); expect(applicationContext.getResources("/WEB-INFtiles*.xml")).andReturn(null); expect(applicationContext.getResources("classpath*:META-INFtiles*.xml")).andReturn(resourceSet); replay(applicationContext, resource); List<ApplicationResource> resources = factory.getSources(applicationContext); assertEquals(1, resources.size()); assertTrue(resources.contains(resource)); verify(applicationContext, resource); }
@Test public void testTILES484second() throws IOException { ApplicationContext applicationContext = createMock(ApplicationContext.class); ApplicationResource resource1 = createMock(ApplicationResource.class); expect(resource1.getLocale()).andReturn(Locale.ROOT); ApplicationResource resource2 = createMock(ApplicationResource.class); expect(resource2.getLocale()).andReturn(Locale.ITALY); Collection<ApplicationResource> resourceSet = new HashSet<ApplicationResource>(); resourceSet.add(resource1); resourceSet.add(resource2); expect(applicationContext.getResources("/WEB-INFtiles*.xml")).andReturn(resourceSet); expect(applicationContext.getResources("classpath*:META-INFtiles*.xml")).andReturn(null); replay(applicationContext, resource1, resource2); List<ApplicationResource> resources = factory.getSources(applicationContext); assertEquals(1, resources.size()); assertTrue(resources.contains(resource1)); verify(applicationContext, resource1, resource2); }