Search in sources :

Example 1 with DateSourceForTesting

use of org.candlepin.test.DateSourceForTesting 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)

Aggregations

BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)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 EntitlementRules (org.candlepin.policy.js.entitlement.EntitlementRules)1 DateSourceForTesting (org.candlepin.test.DateSourceForTesting)1 Before (org.junit.Before)1