RuleFeaturesProvider { public boolean isFeatureRequest(RuleFeatures.Feature feature, String uri){ for (RuleFeatures features : getFeaturesList()) { if(features.getUrlPattern().matcher(uri).matches()){ if(features.hasFeature(feature)){ log.debug(String.format("Don't expand the uri: %s for the pattern %s since it's a %s request", uri, features.getUrlPattern().pattern(), feature.name())); return true; } return false; } } return false; } RuleFeaturesProvider(List<Rule> rules); List<RuleFeatures> getFeaturesList(); boolean isFeatureRequest(RuleFeatures.Feature feature, String uri);  }
@Test public void testStorageExpandFeatureRequests(TestContext context){ Rule rule1 = createRule("/root/element1/element2/(test1/.*/test2/.*/test3/.*)", true, false); Rule rule2 = createRule("/root/element11/element22/(.*)", true, false); Rule rule3 = createRule("/root/element111/element222/", true, false); RuleFeaturesProvider provider = new RuleFeaturesProvider(Arrays.asList(rule1, rule2, rule3)); context.assertTrue(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element1/element2/test1/1234/test2/23423/test3/asdf/asdf")); context.assertFalse(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element1/element2/test999/1234/test2/23423/test3/asdf/asdf")); context.assertTrue(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element11/element22/test1/1234/")); context.assertFalse(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element11/element22")); context.assertTrue(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element111/element222/")); context.assertFalse(provider.isFeatureRequest(STORAGE_EXPAND, "/root/element111/element222/asdf")); }
@Test public void testStorageExpandRequestsFromSpecificToLessSpecific(TestContext context){ Rule rule1 = createRule("/root/elements/123/(.*)", false, false); Rule rule2 = createRule("/root/elements/([0-9].*)", true, false); RuleFeaturesProvider provider = new RuleFeaturesProvider(Arrays.asList(rule1, rule2)); context.assertFalse(provider.isFeatureRequest(STORAGE_EXPAND, "/root/elements/123/some/more/elements")); context.assertTrue(provider.isFeatureRequest(STORAGE_EXPAND, "/root/elements/999/some/more/elements")); }
@Test public void testExpandOnBackendFeatureRequests(TestContext context){ Rule rule1 = createRule("/root/element1/element2/(test1/.*/test2/.*/test3/.*)", false, true); Rule rule2 = createRule("/root/element11/element22/(.*)", false, true); Rule rule3 = createRule("/root/element111/element222/", false, true); RuleFeaturesProvider provider = new RuleFeaturesProvider(Arrays.asList(rule1, rule2, rule3)); context.assertTrue(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element1/element2/test1/1234/test2/23423/test3/asdf/asdf")); context.assertFalse(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element1/element2/test999/1234/test2/23423/test3/asdf/asdf")); context.assertTrue(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element11/element22/test1/1234/")); context.assertFalse(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element11/element22")); context.assertTrue(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element111/element222/")); context.assertFalse(provider.isFeatureRequest(EXPAND_ON_BACKEND, "/root/element111/element222/asdf")); }