@Before
  public void setupTest() {
    this.i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    this.hypervisorType = new ConsumerType(ConsumerTypeEnum.HYPERVISOR);
    this.consumerResource =
        new ConsumerResource(
            this.consumerCurator,
            this.consumerTypeCurator,
            null,
            this.subscriptionService,
            null,
            this.idCertService,
            null,
            this.i18n,
            this.sink,
            this.eventFactory,
            null,
            null,
            this.userService,
            null,
            null,
            null,
            null,
            this.ownerCurator,
            this.activationKeyCurator,
            null,
            this.complianceRules,
            this.deletedConsumerCurator,
            null,
            new CandlepinCommonTestConfig());
    hypervisorResource =
        new HypervisorResource(
            consumerResource, poolManager, consumerCurator, this.deletedConsumerCurator, i18n);

    // Ensure that we get the consumer that was passed in back from the create call.
    when(consumerCurator.create(any(Consumer.class)))
        .thenAnswer(
            new Answer<Object>() {
              @Override
              public Object answer(InvocationOnMock invocation) throws Throwable {
                return invocation.getArguments()[0];
              }
            });
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class)))
        .thenReturn(new ComplianceStatus(new Date()));
  }
Esempio n. 2
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);
  }