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));
}
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));
}
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];
}
});
}
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());
}
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"));
}
Aggregations