Search in sources :

Example 6 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerationByEntitlementId.

@Test
public void testNonLazyRegenerationByEntitlementId() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Consumer consumer = TestUtil.createConsumer(owner);
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    Entitlement entitlement = TestUtil.createEntitlement(owner, consumer, pool, null);
    entitlement.setId("test-ent-id");
    Collection<String> entitlements = Arrays.asList(entitlement.getId());
    pool.setEntitlements(new HashSet(Arrays.asList(entitlement)));
    HashMap<String, EntitlementCertificate> ecMap = new HashMap<>();
    ecMap.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntitlementCurator.find(eq(entitlement.getId()))).thenReturn(entitlement);
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), any(Map.class), any(Map.class), any(Map.class), eq(true))).thenReturn(ecMap);
    this.ecGenerator.regenerateCertificatesByEntitlementIds(entitlements, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter, times(1)).generateEntitlementCerts(any(Consumer.class), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Consumer(org.candlepin.model.Consumer) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class EntitlementCertificateGeneratorTest method testNonLazyRegenerate.

@Test
public void testNonLazyRegenerate() throws Exception {
    Owner owner = TestUtil.createOwner("test-owner", "Test Owner");
    Product product = TestUtil.createProduct();
    Pool pool = TestUtil.createPool(owner, product);
    pool.setSourceSubscription(new SourceSubscription("source-sub-id", "master"));
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(this.mockEntCertAdapter.generateEntitlementCerts(any(Consumer.class), anyMapOf(String.class, PoolQuantity.class), anyMapOf(String.class, Entitlement.class), anyMapOf(String.class, Product.class), eq(true))).thenReturn(entCerts);
    Consumer consumer = TestUtil.createConsumer(owner);
    Entitlement entitlement = new Entitlement(pool, consumer, owner, 1);
    entitlement.setDirty(true);
    this.ecGenerator.regenerateCertificatesOf(entitlement, false);
    assertFalse(entitlement.isDirty());
    verify(this.mockEntCertAdapter).generateEntitlementCerts(eq(consumer), this.poolQuantityMapCaptor.capture(), this.entMapCaptor.capture(), this.productMapCaptor.capture(), eq(true));
    assertEquals(entitlement, this.entMapCaptor.getValue().get(pool.getId()));
    assertEquals(product, this.productMapCaptor.getValue().get(pool.getId()));
    verify(this.mockEventSink, times(1)).queueEvent(any(Event.class));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Owner(org.candlepin.model.Owner) SourceSubscription(org.candlepin.model.SourceSubscription) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Event(org.candlepin.audit.Event) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 8 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class PoolManagerTest method init.

@Before
public void init() throws Exception {
    MockitoAnnotations.initMocks(this);
    i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
    owner = TestUtil.createOwner("key", "displayname");
    product = TestUtil.createProduct();
    pool = TestUtil.createPool(owner, product);
    when(mockOwnerCurator.lookupByKey(eq(owner.getKey()))).thenReturn(owner);
    when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
    when(eventFactory.getEventBuilder(any(Target.class), any(Type.class))).thenReturn(eventBuilder);
    when(eventBuilder.setEventData(any(Eventful.class))).thenReturn(eventBuilder);
    this.principal = TestUtil.createOwnerPrincipal(owner);
    this.manager = spy(new CandlepinPoolManager(mockPoolCurator, mockEventSink, eventFactory, mockConfig, enforcerMock, poolRulesMock, entitlementCurator, consumerCuratorMock, consumerTypeCuratorMock, certCuratorMock, mockECGenerator, complianceRules, autobindRules, activationKeyRules, mockProductCurator, mockProductManager, mockContentManager, mockOwnerContentCurator, mockOwnerCurator, mockOwnerProductCurator, mockOwnerManager, pinsetterKernel, i18n, mockBindChainFactory));
    setupBindChain();
    Map<String, EntitlementCertificate> entCerts = new HashMap<>();
    entCerts.put(pool.getId(), new EntitlementCertificate());
    when(mockECGenerator.generateEntitlementCertificates(any(Consumer.class), any(Map.class), any(Map.class), any(Map.class), eq(false))).thenReturn(entCerts);
    dummyComplianceStatus = new ComplianceStatus(new Date());
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class))).thenReturn(dummyComplianceStatus);
    when(consumerCuratorMock.lockAndLoad(any(Consumer.class))).thenAnswer(new Answer<Consumer>() {

        @Override
        public Consumer answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Consumer) args[0];
        }
    });
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) HashMap(java.util.HashMap) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) Matchers.anyString(org.mockito.Matchers.anyString) Eventful(org.candlepin.model.Eventful) Date(java.util.Date) Target(org.candlepin.audit.Event.Target) Type(org.candlepin.audit.Event.Type) CallerType(org.candlepin.policy.js.entitlement.Enforcer.CallerType) ConsumerType(org.candlepin.model.ConsumerType) PoolType(org.candlepin.model.Pool.PoolType) Consumer(org.candlepin.model.Consumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Before(org.junit.Before)

Example 9 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class QuantityRulesTest method testStackOnlyStacksWithSameStackingId.

@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<>();
    entSet.add(e);
    pool1.setEntitlements(entSet);
    pool1.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
    pool1.getProduct().setAttribute(Product.Attributes.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());
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with EntitlementCertificate

use of org.candlepin.model.EntitlementCertificate in project candlepin by candlepin.

the class RulesObjectMapperTest method filterEntitlementCert.

@Test
public void filterEntitlementCert() {
    List<Entitlement> allEnts = new LinkedList<>();
    Entitlement e = new Entitlement();
    Set<EntitlementCertificate> entCerts = new HashSet<>();
    EntitlementCertificate cert = new EntitlementCertificate();
    cert.setCert("FILTERME");
    cert.setKey("FILTERME");
    entCerts.add(cert);
    e.setCertificates(entCerts);
    allEnts.add(e);
    context.put("entitlements", allEnts);
    String output = objMapper.toJsonString(context);
    assertFalse(output.contains("FILTERME"));
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EntitlementCertificate (org.candlepin.model.EntitlementCertificate)29 Entitlement (org.candlepin.model.Entitlement)15 Consumer (org.candlepin.model.Consumer)14 CertificateSerial (org.candlepin.model.CertificateSerial)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 Owner (org.candlepin.model.Owner)8 Pool (org.candlepin.model.Pool)8 Product (org.candlepin.model.Product)7 Map (java.util.Map)5 Event (org.candlepin.audit.Event)4 Certificate (org.candlepin.model.Certificate)3 PoolQuantity (org.candlepin.model.PoolQuantity)3 KeyPair (java.security.KeyPair)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)2