예제 #1
0
  @Test
  public void futureHealing() throws Exception {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<ConsumerInstalledProduct>();
    products.add(cip);

    when(c.getOwner()).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind("fakeConsumer", null, null, null, null, null, false, dtStr, null, null, null);
    AutobindData data = AutobindData.create(c).on(dt);
    verify(e).bindByProducts(eq(data));
  }
예제 #2
0
  @Test
  public void testProductNoPool() throws Exception {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    String[] prodIds = {"notthere"};

    when(c.getOwner()).thenReturn(o);
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);
    when(e.bindByProducts(any(AutobindData.class))).thenReturn(null);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    Response r =
        cr.bind("fakeConsumer", null, prodIds, null, null, null, false, null, null, null, null);
    assertEquals(null, r.getEntity());
  }
예제 #3
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));
  }
예제 #4
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));
  }
예제 #5
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));
  }
  @Override
  public void execute(JobExecutionContext context) throws JobExecutionException {
    String productId = context.getMergedJobDataMap().getString(JobStatus.TARGET_ID);
    Boolean lazy = context.getMergedJobDataMap().getBoolean(LAZY_REGEN);

    List<String> l = new ArrayList<String>();
    l.add(productId);

    Set<Owner> owners = subAdapter.lookupOwnersByProduct(l);

    for (Owner owner : owners) {
      poolManager.refreshPools(owner, lazy);
    }
    context.setResult("Pools refreshed for product " + productId);
  }
예제 #7
0
  @Test
  public void testNonLazyRegenerate() throws Exception {
    Subscription s = TestUtil.createSubscription(getOwner(), product);
    s.setId("testSubId");
    pool.setSubscriptionId(s.getId());
    Entitlement e =
        new Entitlement(
            pool, TestUtil.createConsumer(o), pool.getStartDate(), pool.getEndDate(), 1);
    e.setDirty(true);

    when(mockSubAdapter.getSubscription(pool.getSubscriptionId())).thenReturn(s);

    manager.regenerateCertificatesOf(e, false, false);
    assertFalse(e.getDirty());

    verify(entCertAdapterMock).revokeEntitlementCertificates(e);
    verify(entCertAdapterMock).generateEntitlementCert(eq(e), eq(s), eq(product));
    verify(mockEventSink, times(1)).sendEvent(any(Event.class));
  }
예제 #8
0
 @Test
 public void testRefreshPoolsForDeactivatingPools() {
   List<Subscription> subscriptions = Util.newList();
   List<Pool> pools = Util.newList();
   Pool p = TestUtil.createPool(TestUtil.createProduct());
   p.setSubscriptionId("112");
   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);
   this.manager.getRefresher().add(getOwner()).run();
   verify(this.manager).deletePool(same(p));
 }
예제 #9
0
  @SuppressWarnings("unchecked")
  @Test
  public void testBindByPools() throws Exception {
    PoolIdAndQuantity[] pools = new PoolIdAndQuantity[2];
    pools[0] = new PoolIdAndQuantity("first", 1);
    pools[1] = new PoolIdAndQuantity("second", 2);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    PoolManager pm = mock(PoolManager.class);
    Owner owner = TestUtil.createOwner();
    Consumer consumer = TestUtil.createConsumer(owner);

    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(consumer);
    when(sa.hasUnacceptedSubscriptionTerms(any(Owner.class))).thenReturn(false);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            pm,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Response rsp =
        cr.bind(
            "fakeConsumer",
            null,
            null,
            null,
            null,
            null,
            true,
            null,
            null,
            pools,
            new TrustedUserPrincipal("TaylorSwift"));

    JobDetail detail = (JobDetail) rsp.getEntity();
    PoolIdAndQuantity[] pQs =
        (PoolIdAndQuantity[]) detail.getJobDataMap().get("pool_and_quantities");
    boolean firstFound = false;
    boolean secondFound = false;
    for (PoolIdAndQuantity pq : pQs) {
      if (pq.getPoolId().contentEquals("first")) {
        firstFound = true;
        assertEquals(1, pq.getQuantity().intValue());
      }
      if (pq.getPoolId().contentEquals("second")) {
        secondFound = true;
        assertEquals(2, pq.getQuantity().intValue());
      }
    }
    assertTrue(firstFound);
    assertTrue(secondFound);
  }
예제 #10
0
  @Test(expected = RuntimeException.class)
  public void testExceptionFromCertGen() throws Exception {
    Consumer consumer = createConsumer();

    Entitlement e = Mockito.mock(Entitlement.class);
    Pool p = Mockito.mock(Pool.class);
    Subscription s = Mockito.mock(Subscription.class);
    when(e.getPool()).thenReturn(p);
    when(p.getSubscriptionId()).thenReturn("4444");

    when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
    when(mockedEntitlementCurator.find(eq("9999"))).thenReturn(e);
    when(mockedSubscriptionServiceAdapter.getSubscription(eq("4444"))).thenReturn(s);

    when(mockedEntitlementCertServiceAdapter.generateEntitlementCert(
            any(Entitlement.class), any(Product.class)))
        .thenThrow(new IOException());

    CandlepinPoolManager poolManager =
        new CandlepinPoolManager(
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            mockedEntitlementCurator,
            mockedConsumerCurator,
            null,
            null,
            null,
            null,
            mockedActivationKeyRules,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null);

    ConsumerResource consumerResource =
        new ConsumerResource(
            mockedConsumerCurator,
            null,
            null,
            null,
            mockedEntitlementCurator,
            null,
            mockedEntitlementCertServiceAdapter,
            null,
            null,
            null,
            null,
            null,
            null,
            poolManager,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.regenerateEntitlementCertificates(consumer.getUuid(), "9999", false);
  }