AbstractHttpTransport implements IHttpTransport, IConfigModifier, IShutdownListener, IDependenciesListener { protected void generateModuleIdMap(IDependencies deps) throws IOException { final String methodName = "generateModuleIdMap"; boolean isTraceLogging = log.isLoggable(Level.FINER); if (isTraceLogging) { log.entering(sourceClass, methodName); } if (getModuleIdRegFunctionName() == null) { if (isTraceLogging) { log.finer("No module id list registration function - returning"); log.exiting(sourceClass, methodName); } return; } Map<String, String> names = new TreeMap<String, String>(); for (String name : deps.getDependencyNames()) { names.put(name, isTraceLogging ? deps.getURI(name).toString() : null); } for (String name : getSyntheticModuleNames()) { names.put(name, isTraceLogging ? "transport added" : null); } if (isTraceLogging) { StringBuffer sb = new StringBuffer("Module ID list:\r\n"); int i = 1; for (Map.Entry<String, String> entry : names.entrySet()) { sb.append(i++).append(": ").append(entry.getKey()).append(" - ").append(entry.getValue()).append("\r\n"); } log.finer(sb.toString()); } Map<String, Integer> idMap = new HashMap<String, Integer>(names.size()); List<String> idList = new ArrayList<String>(names.size()+1); idList.add(""); idList.addAll(names.keySet()); for (int i = 1; i < idList.size(); i++) { idMap.put(idList.get(i), i); } MessageDigest md = null; try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { if (log.isLoggable(Level.WARNING)) { log.log(Level.WARNING, e.getMessage(), e); } throw new IOException(e); } moduleIdListHash = md.digest(idList.toString().getBytes("UTF-8")); moduleIdMap = Collections.unmodifiableMap(idMap); moduleIdList = idList; if (log.isLoggable(Level.INFO)) { log.info("Module ID List hash = " + TypeUtil.byteArray2String(moduleIdListHash)); } if (isTraceLogging) { log.exiting(sourceClass, methodName); } } AbstractHttpTransport();   AbstractHttpTransport(CountDownLatch depsInitialized, List<String> dependentFeatures, long depsLastMod); @SuppressWarnings("deprecation") @Override void decorateRequest(HttpServletRequest request); @Override Map<String, Integer> getModuleIdMap(); @Override String getModuleIdRegFunctionName(); @Override void modifyConfig(IAggregator aggregator, Object configObj); @Override void initialize(IAggregator aggregator, IAggregatorExtension extension, IExtensionRegistrar reg); @Override void shutdown(IAggregator aggregator); @Override void contributeLoaderExtensionJavaScript(String contribution); @Override String getLayerContribution(HttpServletRequest request,
			LayerContributionType type, Object arg); abstract boolean isServerExpandable(HttpServletRequest request, String mid); @Override abstract List<ICacheKeyGenerator> getCacheKeyGenerators(); @Override void dependenciesLoaded(IDependencies deps, long sequence); static final String PATHS_PROPNAME; static final String REQUESTEDMODULES_REQPARAM; static final String REQUESTEDMODULEIDS_REQPARAM; static final String REQUESTEDMODULESCOUNT_REQPARAM; static final String EXCLUDEENC_REQPARAM; static final String EXCLUDEIDS_REQPARAM; static final String CONSOLE_WARNING_MSG_FMT; static final String SCRIPTS_REQPARAM; static final String DEPS_REQPARAM; static final String REQUIRED_REQPARAM; static final String PRELOADS_REQPARAM; static final String EXCLUDES_REQPARAM; static final String FEATUREMAP_REQPARAM; static final String FEATUREMAPHASH_REQPARAM; static final String FAILONVERSIONERR_REQPARAM; static final String[] INCLUDEREQUIREDEPS_REQPARAM; static final String[] INCLUDEUNDEFINEDFEATUREDEPS_REQPARAM; static final String[] ASSERTNONLS_REQPARAM; static final String[] OPTIMIZATIONLEVEL_REQPARAMS; static final String[] EXPANDREQUIRELISTS_REQPARAMS; static final String[] EXPORTMODULENAMES_REQPARAMS; static final String[] SHOWFILENAMES_REQPARAMS; static final String[] NOCACHE_REQPARAMS; static final String[] REQUESTEDLOCALES_REQPARAMS; static final String[] CACHEBUST_REQPARAMS; static final String[] SERVEREXPANDLAYERS_REQPARAMS; static final String[] DEPENDENCYEXPANSIONLOGGING_REQPARAMS; static final String[] GENERATESOURCEMAPS_REQPARAMS; static final String CONFIGVARNAME_REQPARAM; static final String LAYERCONTRIBUTIONSTATE_REQATTRNAME; static final String ENCODED_FEATURE_MAP_REQPARAM; static final String FEATURE_LIST_PRELUDE; static final String FEATURE_LIST_PROLOGUE; }
@Test public void testGenerateModuleIdMap() throws Exception { final String[] moduleIdRegFunctionName = new String[]{"reg"}; final Collection<String> syntheticModuleNames = new ArrayList<String>(); final Set<String> dependencyNames = new HashSet<String>(); TestHttpTransport transport = new TestHttpTransport(TestUtils.createMockAggregator()) { @Override public String getModuleIdRegFunctionName() { return moduleIdRegFunctionName[0]; } @Override public Collection<String> getSyntheticModuleNames() { return syntheticModuleNames; } }; IDependencies mockDependencies = EasyMock.createMock(IDependencies.class); EasyMock.expect(mockDependencies.getDependencyNames()).andAnswer(new IAnswer<Iterable<String>>() { @Override public Iterable<String> answer() throws Throwable { return dependencyNames; } }).anyTimes(); IAggregator mockAggregator = EasyMock.createMock(IAggregator.class); EasyMock.expect(mockAggregator.getDependencies()).andReturn(mockDependencies).anyTimes(); Whitebox.setInternalState(transport, "aggregator", mockAggregator); EasyMock.replay(mockAggregator, mockDependencies); transport.generateModuleIdMap(mockDependencies); Assert.assertEquals(0, transport.getModuleIdMap().size()); Assert.assertEquals(Arrays.asList(new String[]{""}), transport.getModuleIdList()); dependencyNames.add("foo"); dependencyNames.add("bar"); transport.generateModuleIdMap(mockDependencies); List<String> idList = transport.getModuleIdList(); Assert.assertEquals(Arrays.asList(new String[]{"", "bar", "foo"}), idList); for (int i = 1; i < idList.size(); i++) { Assert.assertEquals(i, transport.getModuleIdMap().get(idList.get(i)).intValue()); } Assert.assertEquals(idList.size()-1, transport.getModuleIdMap().size()); syntheticModuleNames.add("combo/text"); syntheticModuleNames.add("combo/other"); transport.generateModuleIdMap(mockDependencies); idList = transport.getModuleIdList(); Assert.assertEquals(Arrays.asList(new String[]{"", "bar", "combo/other", "combo/text", "foo"}), idList); for (int i = 1; i < idList.size(); i++) { Assert.assertEquals(i, transport.getModuleIdMap().get(idList.get(i)).intValue()); } Assert.assertEquals(idList.size()-1, transport.getModuleIdMap().size()); dependencyNames.add("module"); transport.generateModuleIdMap(mockDependencies); System.out.println(transport.getModuleIdList()); idList = transport.getModuleIdList(); Assert.assertEquals(Arrays.asList(new String[]{"", "bar", "combo/other", "combo/text", "foo", "module"}), idList); for (int i = 1; i < idList.size(); i++) { Assert.assertEquals(i, transport.getModuleIdMap().get(idList.get(i)).intValue()); } Assert.assertEquals(idList.size()-1, transport.getModuleIdMap().size()); moduleIdRegFunctionName[0] = null; Whitebox.setInternalState(transport, "moduleIdMap", (Map<String, Integer>)null); Whitebox.setInternalState(transport, "moduleIdList", (List<String>)null); transport.generateModuleIdMap(mockDependencies); Assert.assertNull(transport.getModuleIdMap()); Assert.assertNull(transport.getModuleIdList()); }