示例#1
0
  @Test
  public void testPhysicalIgnoresFutureConsumed() {
    // Setup a future pool for the same product:
    Pool futurePool = TestUtil.createPool(owner, product);
    futurePool.setStartDate(TestUtil.createDate(2050, 1, 1));
    futurePool.setEndDate(TestUtil.createDate(2060, 1, 1));

    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    futurePool.getProduct().setAttribute("multi-entitlement", "yes");
    futurePool.getProduct().setAttribute("stacking_id", "1");
    futurePool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green in future but we have nothing now:
    Entitlement e = createValidEntitlement(futurePool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(4), suggested.getSuggested());
  }
示例#2
0
  @Test
  public void testFutureSuggested() {
    consumer.setFact(SOCKET_FACT, "4");

    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));

    Pool currentPool = TestUtil.createPool(owner, product);
    currentPool.setStartDate(TestUtil.createDate(2000, 1, 1));
    currentPool.setEndDate(TestUtil.createDate(5000, 1, 1));
    currentPool.getProduct().setAttribute("multi-entitlement", "yes");
    currentPool.getProduct().setAttribute("stacking_id", "1");

    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    currentPool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement currentEntitlement = TestUtil.createEntitlement(owner, consumer, currentPool, null);
    currentEntitlement.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(currentEntitlement);
    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(currentPool, consumer, TestUtil.createDate(2010, 6, 1));
    assertEquals(new Long(0), suggested.getSuggested());

    // Make sure current coverage does not affect the future
    suggested = quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(9000, 6, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
示例#3
0
  @Test
  public void testPhysicalAccountsForCurrentlyConsumed() {
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
示例#4
0
  @Test
  public void testCalculatedValueIsZeroWhenNegativeIsCalculated() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(1000);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(0), suggested.getSuggested());
  }
示例#5
0
  @Test
  public void testTotalConsumedDoesNotIncludeFutureEntitlements() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null);
    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(2010, 1, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
示例#6
0
  @Test
  public void testTotalConsumedIsZeroWhenNoMatches() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Product product2 = TestUtil.createProduct();
    Pool pool2 = TestUtil.createPool(owner, product2);

    Entitlement e = createValidEntitlement(pool2);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
示例#7
0
  @Test
  public void testPhysicalIgnoresPastConsumed() {
    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green now, but we will ask for suggested quantity on a date in the future:
    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    // Ask for quantity in the future, past the end of the current pool:
    Calendar c = Calendar.getInstance();
    c.setTime(pool.getEndDate());
    Date futureDate = TestUtil.createDate(c.get(Calendar.YEAR) + 1, 1, 1);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, futureDate);
    assertEquals(new Long(4), suggested.getSuggested());
  }