コード例 #1
0
ファイル: PoolManagerTest.java プロジェクト: slagle/candlepin
  @Before
  public void init() throws Exception {
    product = TestUtil.createProduct();
    o = new Owner("key", "displayname");
    pool = TestUtil.createPool(o, product);

    when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    this.productCache = new ProductCache(mockConfig, mockProductAdapter);

    this.principal = TestUtil.createOwnerPrincipal();
    this.manager =
        spy(
            new CandlepinPoolManager(
                mockPoolCurator,
                mockSubAdapter,
                productCache,
                entCertAdapterMock,
                mockEventSink,
                eventFactory,
                mockConfig,
                enforcerMock,
                poolRulesMock,
                entitlementCurator,
                consumerCuratorMock,
                certCuratorMock,
                complianceRules,
                envCurator,
                autobindRules));

    when(entCertAdapterMock.generateEntitlementCert(
            any(Entitlement.class), any(Subscription.class), any(Product.class)))
        .thenReturn(new EntitlementCertificate());

    dummyComplianceStatus = new ComplianceStatus(new Date());
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class)))
        .thenReturn(dummyComplianceStatus);
  }
コード例 #2
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);
  }