@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()); }
@Test public void testStackOnlyStacksWithSameStackingId() { consumer.setFact(IS_VIRT, "false"); consumer.setFact(SOCKET_FACT, "8"); pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2"); pool.setQuantity(10L); Product product1 = TestUtil.createProduct(); Pool pool1 = TestUtil.createPool(owner, product1); Entitlement e = TestUtil.createEntitlement(owner, consumer, pool1, new EntitlementCertificate()); Set<Entitlement> entSet = new HashSet<Entitlement>(); entSet.add(e); pool1.setEntitlements(entSet); pool1.getProduct().setAttribute("multi-entitlement", "yes"); pool1.getProduct().setAttribute("stacking_id", "2"); pool1.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2"); pool1.setQuantity(10L); // Consume 2 subscriptions with another stacking ID Entitlement toAdd = pool1.getEntitlements().iterator().next(); toAdd.setQuantity(2); consumer.addEntitlement(toAdd); // Ensure the 2 attached entitlements do not cause the suggested quantity to change SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date()); assertEquals(new Long(4), suggested.getSuggested()); }
@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()); }
@Test public void testRefreshPoolsRemovesExpiredSubscriptionsAlongWithItsPoolsAndEnts() { PreUnbindHelper preHelper = mock(PreUnbindHelper.class); Date expiredStart = TestUtil.createDate(2004, 5, 5); Date expiredDate = TestUtil.createDate(2005, 5, 5); List<Subscription> subscriptions = Util.newList(); Subscription sub = TestUtil.createSubscription(getOwner(), TestUtil.createProduct()); sub.setStartDate(expiredStart); sub.setEndDate(expiredDate); sub.setId("123"); subscriptions.add(sub); when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions); List<Pool> pools = Util.newList(); Pool p = TestUtil.createPool(sub.getOwner(), sub.getProduct()); p.setSubscriptionId(sub.getId()); p.setStartDate(expiredStart); p.setEndDate(expiredDate); p.setConsumed(1L); pools.add(p); when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(p); when(mockPoolCurator.listAvailableEntitlementPools( any(Consumer.class), any(Owner.class), anyString(), any(Date.class), anyBoolean(), anyBoolean())) .thenReturn(pools); List<Entitlement> poolEntitlements = Util.newList(); Entitlement ent = TestUtil.createEntitlement(); ent.setPool(p); ent.setQuantity(1); poolEntitlements.add(ent); when(mockPoolCurator.entitlementsIn(eq(p))).thenReturn(poolEntitlements); ValidationResult result = new ValidationResult(); when(preHelper.getResult()).thenReturn(result); this.manager.getRefresher().add(sub.getOwner()).run(); verify(mockSubAdapter).deleteSubscription(eq(sub)); verify(mockPoolCurator).delete(eq(p)); // Verify the entitlement was removed. verify(entCertAdapterMock).revokeEntitlementCertificates(eq(ent)); verify(entitlementCurator).delete(eq(ent)); }
@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()); }
@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()); }
private Pool entitlementPoolWithMembersAndExpiration( Owner theOwner, Product product, final int currentMembers, final int maxMembers, Date expiry) { Pool p = createPoolAndSub(theOwner, product, Long.valueOf(maxMembers), new Date(), expiry); for (int i = 0; i < currentMembers; i++) { Consumer c = createConsumer(theOwner); Entitlement e = createEntitlement(theOwner, c, p, null); e.setQuantity(1); entitlementCurator.create(e); p.getEntitlements().add(e); poolCurator.merge(p); } poolCurator.refresh(p); return p; }
@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()); }
@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()); }
@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()); }