ModuleImpl extends ModuleIdentifier implements IModule { public ModuleImpl(String mid, URI uri) { super(mid); this.uri = uri; } ModuleImpl(String mid, URI uri); protected  ModuleImpl(ModuleImpl module); @Override URI getURI(); @Override IResource getResource(IAggregator aggregator); Future<ModuleBuildReader> getBuild(final HttpServletRequest request); void processExtraModules(ModuleBuildReader reader, HttpServletRequest request, CacheEntry cacheEntry); @Override String toString(); @Override void clearCached(ICacheManager mgr); static IModuleCache newModuleCache(IAggregator aggregator);  }
@Test public void testModuleImpl() throws Exception { testDepMap.put("p2/a", (String[])ArrayUtils.add(testDepMap.get("p2/a"), "p1/aliased/d")); String configJson = "{paths:{p1:'p1',p2:'p2'}, aliases:[[/\\/aliased\\ configRef.set(new ConfigImpl(mockAggregator, tmpdir.toURI(), configJson)); Features features = new Features(); features.put("foo", true); features.put("bar", true); requestAttributes.put(IHttpTransport.FEATUREMAP_REQATTRNAME, features); ConcurrentListBuilder<String[]> expDeps = new ConcurrentListBuilder<String[]>(); requestAttributes.put(JavaScriptModuleBuilder.MODULE_EXPANDED_DEPS, expDeps); ModuleImpl module = (ModuleImpl)mockAggregator.newModule("p1/p1", mockAggregator.getConfig().locateModuleResource("p1/p1", true)); Reader reader = module.getBuild(mockRequest).get(); System.out.println(module.toString()); Assert.assertEquals("[expn, js:(has:[conditionFalse, conditionTrue, foo])]", module.getCacheKeyGenerators().toString()); Assert.assertTrue(module.getKeys().size() == 1 && module.getKeys().containsAll(Arrays.asList(new String[]{"expn:0;js:S:1:0:1;has{foo}"}))); StringWriter writer = new StringWriter(); CopyUtil.copy(reader, writer); String compiled = writer.toString(); System.out.println(compiled); Assert.assertEquals(1, expDeps.size()); Assert.assertTrue(ArrayUtils.indexOf(expDeps.toList().get(0), "p1/foo/d") != -1); expDeps = new ConcurrentListBuilder<String[]>(); requestAttributes.put(JavaScriptModuleBuilder.MODULE_EXPANDED_DEPS, expDeps); features.put("foo", false); reader = module.getBuild(mockRequest).get(); System.out.println(module.toString()); Assert.assertEquals("[expn, js:(has:[bar, conditionFalse, conditionTrue, foo])]", module.getCacheKeyGenerators().toString()); Assert.assertTrue(module.getKeys().size() == 2 && module.getKeys().containsAll(Arrays.asList( new String[]{"expn:0;js:S:1:0:1;has{foo}", "expn:0;js:S:1:0:1;has{bar,!foo}"}))); writer = new StringWriter(); CopyUtil.copy(reader, writer); compiled = writer.toString(); Assert.assertEquals(1, expDeps.size()); Assert.assertTrue(ArrayUtils.indexOf(expDeps.toList().get(0), "p1/bar/d") != -1); expDeps = new ConcurrentListBuilder<String[]>(); requestAttributes.put(JavaScriptModuleBuilder.MODULE_EXPANDED_DEPS, expDeps); features.put("bar", false); reader = module.getBuild(mockRequest).get(); System.out.println(module.toString()); List<ICacheKeyGenerator> cacheKeyGenerators = module.getCacheKeyGenerators(); Assert.assertEquals("[expn, js:(has:[bar, conditionFalse, conditionTrue, foo, non])]", module.getCacheKeyGenerators().toString()); Assert.assertTrue(module.getKeys().size() == 3 && module.getKeys().containsAll(Arrays.asList( new String[]{ "expn:0;js:S:1:0:1;has{foo}", "expn:0;js:S:1:0:1;has{bar,!foo}", "expn:0;js:S:1:0:1;has{!bar,!foo}" } ))); writer = new StringWriter(); CopyUtil.copy(reader, writer); compiled = writer.toString(); System.out.println(compiled); Assert.assertEquals(1, expDeps.size()); Assert.assertTrue(ArrayUtils.indexOf(expDeps.toList().get(0), "p1/non/d") != -1); expDeps = new ConcurrentListBuilder<String[]>(); requestAttributes.put(JavaScriptModuleBuilder.MODULE_EXPANDED_DEPS, expDeps); features.remove("bar"); features.put("foo", true); reader = module.getBuild(mockRequest).get(); System.out.println(module.toString()); Assert.assertTrue(cacheKeyGenerators == module.getCacheKeyGenerators()); Assert.assertTrue(module.getKeys().size() == 3 && module.getKeys().containsAll(Arrays.asList( new String[]{ "expn:0;js:S:1:0:1;has{foo}", "expn:0;js:S:1:0:1;has{bar,!foo}", "expn:0;js:S:1:0:1;has{!bar,!foo}" } ))); writer = new StringWriter(); CopyUtil.copy(reader, writer); compiled = writer.toString(); System.out.println(compiled); Assert.assertEquals(1, expDeps.size()); Assert.assertTrue(ArrayUtils.indexOf(expDeps.toList().get(0), "p1/foo/d") != -1); expDeps = new ConcurrentListBuilder<String[]>(); requestAttributes.put(JavaScriptModuleBuilder.MODULE_EXPANDED_DEPS, expDeps); features.put("bar", true); reader = module.getBuild(mockRequest).get(); System.out.println(module.toString()); Assert.assertTrue(cacheKeyGenerators == module.getCacheKeyGenerators()); Assert.assertTrue(module.getKeys().size() == 4 && module.getKeys().containsAll(Arrays.asList( new String[]{ "expn:0;js:S:1:0:1;has{foo}", "expn:0;js:S:1:0:1;has{bar,foo}", "expn:0;js:S:1:0:1;has{bar,!foo}", "expn:0;js:S:1:0:1;has{!bar,!foo}" } ))); writer = new StringWriter(); CopyUtil.copy(reader, writer); compiled = writer.toString(); Assert.assertEquals(1, expDeps.size()); Assert.assertTrue(ArrayUtils.indexOf(expDeps.toList().get(0), "p1/foo/d") != -1); }