Search in sources :

Example 1 with EntitlementRules

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);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) DateSourceForTesting(org.candlepin.test.DateSourceForTesting) InputStreamReader(java.io.InputStreamReader) EntitlementRules(org.candlepin.policy.js.entitlement.EntitlementRules) BufferedReader(java.io.BufferedReader) JsRunnerProvider(org.candlepin.policy.js.JsRunnerProvider) RulesObjectMapper(org.candlepin.policy.js.RulesObjectMapper) JsRunner(org.candlepin.policy.js.JsRunner) Rules(org.candlepin.model.Rules) EntitlementRules(org.candlepin.policy.js.entitlement.EntitlementRules) StandardTranslator(org.candlepin.dto.StandardTranslator) Before(org.junit.Before)

Example 2 with EntitlementRules

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"));
}
Also used : Rule(org.candlepin.policy.js.entitlement.EntitlementRules.Rule) EntitlementRules(org.candlepin.policy.js.entitlement.EntitlementRules) Rule(org.candlepin.policy.js.entitlement.EntitlementRules.Rule) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EntitlementRules (org.candlepin.policy.js.entitlement.EntitlementRules)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 StandardTranslator (org.candlepin.dto.StandardTranslator)1 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)1 Rules (org.candlepin.model.Rules)1 JsRunner (org.candlepin.policy.js.JsRunner)1 JsRunnerProvider (org.candlepin.policy.js.JsRunnerProvider)1 RulesObjectMapper (org.candlepin.policy.js.RulesObjectMapper)1 Rule (org.candlepin.policy.js.entitlement.EntitlementRules.Rule)1 DateSourceForTesting (org.candlepin.test.DateSourceForTesting)1 Before (org.junit.Before)1 Test (org.junit.Test)1