Beispiel #1
0
  @Test
  public void refreshPoolsCleanupPoolThatLostVirtLimit() {
    List<Subscription> subscriptions = Util.newList();
    List<Pool> pools = Util.newList();
    Subscription s = TestUtil.createSubscription(getOwner(), TestUtil.createProduct());
    s.setId("01923");
    subscriptions.add(s);
    Pool p = TestUtil.createPool(s.getProduct());
    p.setSubscriptionId(s.getId());
    p.setAttribute(PoolManager.DELETE_FLAG, "true");
    pools.add(p);

    when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
    when(mockPoolCurator.listAvailableEntitlementPools(
            any(Consumer.class),
            any(Owner.class),
            anyString(),
            any(Date.class),
            anyBoolean(),
            anyBoolean()))
        .thenReturn(pools);

    List<PoolUpdate> updates = new LinkedList();
    updates.add(new PoolUpdate(p, false, true, false));
    when(poolRulesMock.updatePools(s, pools)).thenReturn(updates);

    this.manager.getRefresher().add(getOwner()).run();
    verify(this.mockPoolCurator, times(1)).delete(any(Pool.class));
  }
Beispiel #2
0
  @Test
  public void refreshPoolsCreatingPoolsForExistingSubscriptions() {
    List<Subscription> subscriptions = Util.newList();
    List<Pool> pools = Util.newList();
    Subscription s = TestUtil.createSubscription(getOwner(), TestUtil.createProduct());
    subscriptions.add(s);
    when(mockSubAdapter.getSubscriptions(any(Owner.class))).thenReturn(subscriptions);
    when(mockPoolCurator.listAvailableEntitlementPools(
            any(Consumer.class),
            any(Owner.class),
            anyString(),
            any(Date.class),
            anyBoolean(),
            anyBoolean()))
        .thenReturn(pools);

    List<Pool> newPools = new LinkedList<Pool>();
    Pool p = TestUtil.createPool(s.getProduct());
    p.setSubscriptionId(s.getId());
    newPools.add(p);
    when(poolRulesMock.createPools(s)).thenReturn(newPools);

    this.manager.getRefresher().add(getOwner()).run();
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
  }
Beispiel #3
0
  @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));
  }
Beispiel #4
0
  @Test
  public void testCreatePoolForSubscription() {
    final Subscription s = TestUtil.createSubscription(getOwner(), TestUtil.createProduct());

    List<Pool> newPools = new LinkedList<Pool>();
    Pool p = TestUtil.createPool(s.getProduct());
    p.setSubscriptionId(s.getId());
    newPools.add(p);
    when(poolRulesMock.createPools(s)).thenReturn(newPools);

    this.manager.createPoolsForSubscription(s);
    verify(this.mockPoolCurator, times(1)).create(any(Pool.class));
  }