AbstractHttpTransport implements IHttpTransport, IConfigModifier, IShutdownListener, IDependenciesListener { protected Features getFeaturesFromRequest(HttpServletRequest request) throws IOException { return getFeaturesFromRequest(request, false); } 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 testGetFeaturesFromRequest() throws Exception { Map<String, Object> requestAttributes = new HashMap<String, Object>(); Map<String, String[]> requestParameters = new HashMap<String, String[]>(); Ref<IConfig> configRef = new Ref<IConfig>(null); File tmpdir = new File(System.getProperty("java.io.tmpdir")); IAggregator mockAggregator = TestUtils.createMockAggregator(configRef, tmpdir); EasyMock.replay(mockAggregator); configRef.set(new ConfigImpl(mockAggregator, tmpdir.toURI(), "{has:{def1:1,def2:0}}")); AbstractHttpTransport transport = new TestHttpTransport(mockAggregator); Cookie[] cookies = new Cookie[1]; HttpServletRequest request = TestUtils.createMockRequest(null, requestAttributes, requestParameters, cookies, null); EasyMock.replay(request); assertNull(transport.getHasConditionsFromRequest(request)); String hasConditions = "foo;!bar"; requestParameters.put("has", new String[]{hasConditions}); Features features = transport.getFeaturesFromRequest(request); assertEquals(4, features.featureNames().size()); Assert.assertTrue(features.featureNames().contains("foo") && features.featureNames().contains("bar") && features.featureNames().contains("def1") && features.featureNames().contains("def2")); Assert.assertTrue(features.isFeature("foo")); Assert.assertFalse(features.isFeature("bar")); Assert.assertTrue(features.isFeature("def1")); Assert.assertFalse(features.isFeature("def2")); requestParameters.clear(); requestParameters.put("hashash", new String[]{"xxxx"}); cookies[0] = new Cookie("has", hasConditions); features = transport.getFeaturesFromRequest(request); assertEquals(4, features.featureNames().size()); Assert.assertTrue(features.featureNames().contains("foo") && features.featureNames().contains("bar") && features.featureNames().contains("def1") && features.featureNames().contains("def2")); Assert.assertTrue(features.isFeature("foo")); Assert.assertFalse(features.isFeature("bar")); Assert.assertTrue(features.isFeature("def1")); Assert.assertFalse(features.isFeature("def2")); requestParameters.put("hashash", new String[]{"xxxx"}); cookies[0] = new Cookie("has", null); features = transport.getFeaturesFromRequest(request); assertEquals(2, features.featureNames().size()); cookies[0] = new Cookie("foo", "bar"); features = transport.getFeaturesFromRequest(request); assertEquals(2, features.featureNames().size()); }
@Test public void testGetFeaturesFromRequest_IConfig_defaultFeatures_parameter() throws Exception { Map<String, Object> requestAttributes = new HashMap<String, Object>(); Map<String, String[]> requestParameters = new HashMap<String, String[]>(); Ref<IConfig> configRef = new Ref<IConfig>(null); IConfig mockConfig = EasyMock.createNiceMock(IConfig.class); configRef.set(mockConfig); File tmpdir = new File(System.getProperty("java.io.tmpdir")); IAggregator mockAggregator = TestUtils.createMockAggregator(configRef, tmpdir); AbstractHttpTransport transport = new TestHttpTransport(mockAggregator); EasyMock.replay(mockAggregator); final Features defaultFeatures = new Features(); HttpServletRequest mockRequest = TestUtils.createMockRequest(null, requestAttributes, requestParameters, null, null); EasyMock.expect(mockRequest.getRequestURL()).andReturn(new StringBuffer("http: EasyMock.expect(mockRequest.getQueryString()).andReturn("abc=1").anyTimes(); EasyMock.expect(mockConfig.getDefaultFeatures("http: EasyMock.replay(mockConfig, mockRequest); transport.getFeaturesFromRequest(mockRequest); EasyMock.verify(mockRequest, mockConfig); EasyMock.reset(mockRequest, mockConfig); mockRequest = TestUtils.createMockRequest(null, requestAttributes, requestParameters, null, null); EasyMock.expect(mockRequest.getRequestURL()).andReturn(new StringBuffer("http: EasyMock.expect(mockConfig.getDefaultFeatures("http: EasyMock.replay(mockRequest, mockConfig); transport.getFeaturesFromRequest(mockRequest); EasyMock.verify(mockRequest, mockConfig); }