LayerBuilder { protected String getSourcesMappingEpilogue() { String root = ""; String contextPath = request.getRequestURI(); if (contextPath != null) { if (contextPath.endsWith(ILayer.SOURCEMAP_RESOURCE_PATH)) { contextPath = contextPath.substring(0, contextPath.length()-(ILayer.SOURCEMAP_RESOURCE_PATHCOMP.length()+1)); } int idx = contextPath.lastIndexOf("/"); root = contextPath.substring(idx!=-1 ? idx+1 : 0); if (root.length() > 0 && !root.endsWith("/")) { root += "/"; } } StringBuffer sb = new StringBuffer(); sb.append(" .append(root) .append(ILayer.SOURCEMAP_RESOURCE_PATHCOMP); String queryString = request.getQueryString(); if (queryString != null) { sb.append("?").append(queryString); } return sb.toString(); } LayerBuilder(HttpServletRequest request, List<ICacheKeyGenerator> keyGens,
			ModuleList moduleList);   }
@Test public void testAppendSourcesMappingURL() throws Exception { IAggregator mockAggregator = TestUtils.createMockAggregator(); HttpServletRequest mockRequest = TestUtils.createMockRequest(mockAggregator); final MutableObject<String> requestUri = new MutableObject<String>(); final MutableObject<String> queryString = new MutableObject<String>(); EasyMock.expect(mockRequest.getRequestURI()).andAnswer(new IAnswer<String>() { @Override public String answer() throws Throwable { return requestUri.getValue(); } }).anyTimes(); EasyMock.expect(mockRequest.getQueryString()).andAnswer(new IAnswer<String>() { @Override public String answer() throws Throwable { return queryString.getValue(); } }).anyTimes(); EasyMock.replay(mockRequest); EasyMock.replay(mockAggregator); List<ICacheKeyGenerator> keyGens = new ArrayList<ICacheKeyGenerator>(); ModuleList modules = new ModuleList(); LayerBuilder builder = new LayerBuilder(mockRequest, keyGens, modules); mockRequest.setAttribute(IHttpTransport.GENERATESOURCEMAPS_REQATTRNAME, true); String result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" requestUri.setValue("/"); result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" requestUri.setValue("/foo"); result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" requestUri.setValue("/foo/"); queryString.setValue("debug=true&sourcemaps=1"); result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" requestUri.setValue("/foo/bar"); result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" requestUri.setValue("/foo/bar/"); result = builder.getSourcesMappingEpilogue(); Assert.assertEquals(" }