Search in sources :

Example 81 with Product

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

the class X509V3ExtensionUtilTest method testPrefixLogic.

@Test
public void testPrefixLogic() {
    Owner owner = new Owner("Test Corporation");
    Product p = new Product("JarJar", "Binks");
    Content c = new Content();
    c.setContentUrl("/some/path");
    ProductContent pc = new ProductContent(p, c, true);
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
    c.setContentUrl("some/path");
    assertEquals("/some/path", util.createFullContentPath(null, pc));
    assertEquals("/some/path", util.createFullContentPath("", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
    c.setContentUrl("///////some/path");
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is/", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is", pc));
    assertEquals("/this/is/some/path", util.createFullContentPath("/this/is///", pc));
    assertEquals("/some/path", util.createFullContentPath(null, pc));
    assertEquals("/some/path", util.createFullContentPath("", pc));
    c.setContentUrl("http://some/path");
    assertEquals("http://some/path", util.createFullContentPath("/this/is", pc));
    c.setContentUrl("https://some/path");
    assertEquals("https://some/path", util.createFullContentPath("/this/is", pc));
    c.setContentUrl("ftp://some/path");
    assertEquals("ftp://some/path", util.createFullContentPath("/this/is", pc));
    c.setContentUrl("file://some/path");
    assertEquals("file://some/path", util.createFullContentPath("/this/is", pc));
}
Also used : Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) Test(org.junit.Test)

Example 82 with Product

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

the class TestUtil method createPool.

public static Pool createPool(Owner owner, Product product, Collection<Product> providedProducts, Product derivedProduct, Collection<Product> subProvidedProducts, int quantity) {
    Pool pool = createPool(owner, product, providedProducts, quantity);
    Set<Product> subProvided = new HashSet<>();
    if (subProvidedProducts != null) {
        subProvided.addAll(subProvidedProducts);
    }
    pool.setDerivedProduct(derivedProduct);
    pool.setDerivedProvidedProducts(subProvided);
    return pool;
}
Also used : Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) HashSet(java.util.HashSet)

Example 83 with Product

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

the class EntitlementCertificateGeneratorTest method testGenerateEntitlementCertificate.

@Test
public void testGenerateEntitlementCertificate() throws GeneralSecurityException, IOException {
    this.ecGenerator = new EntitlementCertificateGenerator(this.mockEntCertCurator, this.mockEntCertAdapter, this.mockEntitlementCurator, this.mockPoolCurator, this.mockEventSink, this.mockEventFactory, this.mockProductCurator);
    Consumer consumer = mock(Consumer.class);
    Pool pool = mock(Pool.class);
    Product product = mock(Product.class);
    when(pool.getId()).thenReturn("Swift");
    when(pool.getProduct()).thenReturn(product);
    Entitlement entitlement = mock(Entitlement.class);
    when(entitlement.getConsumer()).thenReturn(consumer);
    Map<String, Product> expectedProducts = new HashMap<>();
    expectedProducts.put("Swift", product);
    Map<String, Entitlement> expected = new HashMap<>();
    expected.put("Swift", entitlement);
    Map<String, PoolQuantity> poolQuantityMap = new HashMap<>();
    poolQuantityMap.put("Swift", new PoolQuantity(pool, 0));
    ecGenerator.generateEntitlementCertificate(pool, entitlement);
    verify(mockEntCertAdapter).generateEntitlementCerts(eq(consumer), eq(poolQuantityMap), eq(expected), eq(expectedProducts), eq(true));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) Product(org.candlepin.model.Product) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Test(org.junit.Test)

Example 84 with Product

use of org.candlepin.model.Product 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 85 with Product

use of org.candlepin.model.Product 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)

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