Search in sources :

Example 26 with Product

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

the class DefaultEntitlementCertServiceAdapterTest method testContentExtensionConsumerNoArchFact.

@Test
public void testContentExtensionConsumerNoArchFact() throws IOException {
    Set<Product> products = new HashSet<>();
    products.add(product);
    // set of content for an incompatible arch, which should
    // be in the cert, since this consumer has no arch fact therefore
    // should match everything
    String wrongArches = "s390";
    String noArchUrl = "/some/place/nice";
    Content wrongArchContent = createContent(CONTENT_NAME, CONTENT_ID, CONTENT_LABEL, CONTENT_TYPE, CONTENT_VENDOR, noArchUrl, CONTENT_GPG_URL, wrongArches);
    product.setProductContent(null);
    for (Content content : superContent) {
        product.addContent(content, false);
    }
    product.addContent(wrongArchContent, false);
    consumer.setFact("system.certificate_version", "3.3");
    Set<X509ByteExtensionWrapper> byteExtensions = certServiceAdapter.prepareV3ByteExtensions(product, getProductModels(product, products, "prefix", entitlement), "prefix", null);
    Map<String, X509ByteExtensionWrapper> byteMap = new HashMap<>();
    for (X509ByteExtensionWrapper ext : byteExtensions) {
        byteMap.put(ext.getOid(), ext);
    }
    assertTrue(byteMap.containsKey("1.3.6.1.4.1.2312.9.7"));
    List<String> contentSetList = new ArrayList<>();
    try {
        contentSetList = v3extensionUtil.hydrateContentPackage(byteMap.get("1.3.6.1.4.1.2312.9.7").getValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertEquals(8, contentSetList.size());
    for (String url : testUrls) {
        assertTrue(contentSetList.contains("/prefix" + url));
    }
    // verify our new wrong arch url is in there
    assertTrue(contentSetList.contains("/prefix" + noArchUrl));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Matchers.anyString(org.mockito.Matchers.anyString) CertificateExpiredException(java.security.cert.CertificateExpiredException) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExpectedException(org.junit.rules.ExpectedException) CertificateSizeException(org.candlepin.util.CertificateSizeException) IOException(java.io.IOException) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) EnvironmentContent(org.candlepin.model.EnvironmentContent) X509ByteExtensionWrapper(org.candlepin.pki.X509ByteExtensionWrapper) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with Product

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

the class DefaultProductServiceAdapterTest method productsByIds.

@Test
public void productsByIds() {
    Owner o = mock(Owner.class);
    List<String> ids = new ArrayList<>();
    CandlepinQuery<Product> ccmock = mock(CandlepinQuery.class);
    ResultIterator<Product> iterator = mock(ResultIterator.class);
    when(opc.getProductsByIds(any(Owner.class), anyCollection())).thenReturn(ccmock);
    when(ccmock.iterate(anyInt(), anyBoolean())).thenReturn(iterator);
    ids.add(someid);
    dpsa.getProductsByIds(o, ids);
    verify(opc).getProductsByIds(eq(o), eq(ids));
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) Test(org.junit.Test)

Example 28 with Product

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

the class CalculatedAttributesUtilTest method testQuantityIncrement.

@Test
public void testQuantityIncrement() {
    Product product2 = TestUtil.createProduct("blah", "blah");
    product2.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "12");
    productCurator.create(product2);
    Pool pool2 = createPool(owner1, product2, 500L, TestUtil.createDate(2000, 1, 1), TestUtil.createDate(3000, 1, 1));
    SuggestedQuantity suggested = new SuggestedQuantity();
    suggested.setSuggested(1L);
    suggested.setIncrement(12L);
    Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
    suggestedMap.put(pool2.getId(), suggested);
    when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
    Date date = new Date();
    attrUtil.setQuantityAttributes(pool2, consumer, date);
    assertEquals("1", pool2.getCalculatedAttributes().get("suggested_quantity"));
    assertEquals("12", pool2.getCalculatedAttributes().get("quantity_increment"));
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) SuggestedQuantity(org.candlepin.policy.js.quantity.SuggestedQuantity) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) List(java.util.List) Date(java.util.Date) Test(org.junit.Test)

Example 29 with Product

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

the class InstalledProductStatusCalculatorTest method validRangeIsNullWhenOnlyExpiredEntitlementExists.

@Test
public void validRangeIsNullWhenOnlyExpiredEntitlementExists() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    consumer.setCreated(now);
    DateRange range1 = this.rangeRelativeToDate(now, -4, -2);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(null, cip.getStartDate());
    assertEquals(null, cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Example 30 with Product

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

the class InstalledProductStatusCalculatorTest method validRangeWithMultipleWhereFutureEntitlementOverlaps.

@Test
public void validRangeWithMultipleWhereFutureEntitlementOverlaps() {
    Date now = new Date();
    Owner owner = TestUtil.createOwner();
    Product product = TestUtil.createProduct("p1", "product1");
    Consumer consumer = this.mockConsumer(owner, product);
    consumer.setCreated(now);
    DateRange range1 = this.rangeRelativeToDate(now, -4, 2);
    DateRange range2 = this.rangeRelativeToDate(now, 2, 4);
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range2, product));
    consumer.addEntitlement(this.mockEntitlement(owner, consumer, product, range1, product));
    this.mockConsumerEntitlements(consumer, consumer.getEntitlements());
    this.mockOwnerProducts(owner, Arrays.asList(product));
    this.consumerEnricher.enrich(consumer);
    ConsumerInstalledProduct cip = this.getInstalledProduct(consumer, product);
    assertEquals(range1.getStartDate(), cip.getStartDate());
    assertEquals(range2.getEndDate(), cip.getEndDate());
}
Also used : Owner(org.candlepin.model.Owner) DateRange(org.candlepin.policy.js.compliance.DateRange) Consumer(org.candlepin.model.Consumer) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Product (org.candlepin.model.Product)407 Test (org.junit.Test)281 Pool (org.candlepin.model.Pool)216 Owner (org.candlepin.model.Owner)153 Consumer (org.candlepin.model.Consumer)112 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)108 HashSet (java.util.HashSet)84 Date (java.util.Date)74 ArrayList (java.util.ArrayList)69 Entitlement (org.candlepin.model.Entitlement)67 LinkedList (java.util.LinkedList)66 HashMap (java.util.HashMap)65 Subscription (org.candlepin.model.dto.Subscription)47 Content (org.candlepin.model.Content)40 ValidationResult (org.candlepin.policy.ValidationResult)38 SourceSubscription (org.candlepin.model.SourceSubscription)36 Matchers.anyString (org.mockito.Matchers.anyString)31 List (java.util.List)29 PoolQuantity (org.candlepin.model.PoolQuantity)29 DateRange (org.candlepin.policy.js.compliance.DateRange)27