Example #1
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));
  }
  @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);
  }