示例#1
0
  @Before
  public void createEnforcer() throws Exception {
    MockitoAnnotations.initMocks(this);

    when(config.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    productCache = new ProductCache(config, productAdapter);

    owner = createOwner();
    ownerCurator.create(owner);

    consumer = TestUtil.createConsumer(owner);
    consumerTypeCurator.create(consumer.getType());
    consumerCurator.create(consumer);

    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));

    JsRunner jsRules = new JsRunnerProvider(rulesCurator).get();

    enforcer =
        new EntitlementRules(
            new DateSourceForTesting(2010, 1, 1),
            jsRules,
            productCache,
            i18n,
            config,
            consumerCurator,
            poolCurator);
  }
示例#2
0
 private Date expiryDate(int year, int month, int day) {
   return TestDateUtil.date(year, month, day);
 }