use of org.candlepin.policy.js.entitlement.EntitlementRules in project candlepin by candlepin.
the class EnforcerTest method createEnforcer.
@Before
public void createEnforcer() throws Exception {
MockitoAnnotations.initMocks(this);
when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
owner = createOwner();
ownerCurator.create(owner);
consumer = this.createConsumer(owner);
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/rules/test-rules.js")));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line + "\n");
}
reader.close();
Rules rules = mock(Rules.class);
when(rules.getRules()).thenReturn(builder.toString());
when(rulesCurator.getRules()).thenReturn(rules);
when(rulesCurator.getUpdated()).thenReturn(TestDateUtil.date(2010, 1, 1));
when(cacheProvider.get()).thenReturn(cache);
JsRunner jsRules = new JsRunnerProvider(rulesCurator, cacheProvider).get();
translator = new StandardTranslator(consumerTypeCurator, mockEnvironmentCurator, mockOwnerCurator);
enforcer = new EntitlementRules(new DateSourceForTesting(2010, 1, 1), jsRules, i18n, config, consumerCurator, consumerTypeCurator, mockProductCurator, new RulesObjectMapper(new ProductCachedSerializationModule(mockProductCurator)), mockOwnerCurator, mockOwnerProductCurator, mockProductShareCurator, mockProductManager, mockEventSink, mockEventFactory, translator);
}
use of org.candlepin.policy.js.entitlement.EntitlementRules in project candlepin by candlepin.
the class EnforcerTest method shouldParseValidMapping.
@Test
public void shouldParseValidMapping() {
Rule func1rule = new EntitlementRules.Rule("func1", 1, new HashSet<String>() {
{
add("attr1");
add("attr2");
add("attr3");
}
});
assertEquals(func1rule, ((EntitlementRules) enforcer).parseRule("func1:1:attr1:attr2:attr3"));
assertEquals(new EntitlementRules.Rule("func3", 3, new HashSet<String>() {
{
add("attr4");
}
}), ((EntitlementRules) enforcer).parseRule("func3:3:attr4"));
}
Aggregations