Search in sources :

Example 56 with Product

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

the class ImporterTest method testReturnsSubscriptionsFromManifest.

@Test
public void testReturnsSubscriptionsFromManifest() throws IOException, ImporterException {
    Owner owner = new Owner("admin", "Admin Owner");
    ExporterMetadataCurator emc = mock(ExporterMetadataCurator.class);
    when(emc.lookupByTypeAndOwner("per_user", owner)).thenReturn(null);
    ConsumerType stype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
    stype.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq("system"))).thenReturn(stype);
    when(consumerTypeCurator.find(eq(stype.getId()))).thenReturn(stype);
    OwnerCurator oc = mock(OwnerCurator.class);
    when(oc.lookupWithUpstreamUuid(any(String.class))).thenReturn(null);
    PoolManager pm = mock(PoolManager.class);
    Refresher refresher = mock(Refresher.class);
    when(pm.getRefresher(any(SubscriptionServiceAdapter.class), any(OwnerServiceAdapter.class))).thenReturn(refresher);
    Map<String, File> importFiles = new HashMap<>();
    File ruleDir = mock(File.class);
    File[] rulesFiles = createMockJsFile(mockJsPath);
    when(ruleDir.listFiles()).thenReturn(rulesFiles);
    File actualmeta = createFile("meta.json", "0.0.3", new Date(), "test_user", "prefix");
    importFiles.put(ImportFile.META.fileName(), actualmeta);
    ConsumerDTO consumerDTO = new ConsumerDTO();
    consumerDTO.setUuid("eb5e04bf-be27-44cf-abe3-0c0b1edd523e");
    consumerDTO.setName("mymachine");
    ConsumerTypeDTO typeDTO = new ConsumerTypeDTO();
    typeDTO.setLabel("candlepin");
    typeDTO.setManifest(true);
    consumerDTO.setType(typeDTO);
    consumerDTO.setUrlWeb("foo.example.com/subscription");
    consumerDTO.setUrlApi("/candlepin");
    consumerDTO.setContentAccessMode("");
    OwnerDTO ownerDTO = new OwnerDTO();
    ownerDTO.setKey("admin");
    ownerDTO.setDisplayName("Admin Owner");
    consumerDTO.setOwner(ownerDTO);
    ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
    ctype.setId("test-ctype");
    when(consumerTypeCurator.lookupByLabel(eq("candlepin"))).thenReturn(ctype);
    when(consumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
    File consumerFile = new File(folder.getRoot(), "consumer.json");
    mapper.writeValue(consumerFile, consumerDTO);
    importFiles.put(ImportFile.CONSUMER.fileName(), consumerFile);
    File cTypes = mock(File.class);
    when(cTypes.listFiles()).thenReturn(new File[] {});
    importFiles.put(ImportFile.CONSUMER_TYPE.fileName(), cTypes);
    Product prod = new Product("prodId", "prodTest", null);
    prod.setDependentProductIds(null);
    File prodFile = new File(folder.getRoot(), "product.json");
    mapper.writeValue(prodFile, prod);
    File products = mock(File.class);
    when(products.listFiles()).thenReturn(new File[] { prodFile });
    importFiles.put(ImportFile.PRODUCTS.fileName(), products);
    Entitlement ent = new Entitlement();
    Pool pool = new Pool();
    pool.setProduct(prod);
    ent.setPool(pool);
    ent.setQuantity(2);
    File entFile = new File(folder.getRoot(), "entitlement.json");
    mapper.writeValue(entFile, ent);
    File entitlements = mock(File.class);
    when(entitlements.listFiles()).thenReturn(new File[] { entFile });
    importFiles.put(ImportFile.ENTITLEMENTS.fileName(), entitlements);
    RulesImporter ri = mock(RulesImporter.class);
    importFiles.put(ImportFile.RULES_FILE.fileName(), rulesFiles[0]);
    ConflictOverrides co = mock(ConflictOverrides.class);
    Importer i = new Importer(consumerTypeCurator, pc, ri, oc, null, null, pm, null, config, emc, null, null, i18n, null, null, su, null, this.mockSubReconciler, this.ec, this.translator);
    List<Subscription> subscriptions = i.importObjects(owner, importFiles, co);
    assertEquals(1, subscriptions.size());
    assertEquals("prodId", subscriptions.get(0).getProduct().getId());
    assertEquals(2, subscriptions.get(0).getQuantity().longValue());
}
Also used : Owner(org.candlepin.model.Owner) HashMap(java.util.HashMap) ExporterMetadataCurator(org.candlepin.model.ExporterMetadataCurator) Product(org.candlepin.model.Product) OwnerCurator(org.candlepin.model.OwnerCurator) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerServiceAdapter(org.candlepin.service.OwnerServiceAdapter) Pool(org.candlepin.model.Pool) ConsumerType(org.candlepin.model.ConsumerType) Subscription(org.candlepin.model.dto.Subscription) SubscriptionServiceAdapter(org.candlepin.service.SubscriptionServiceAdapter) Refresher(org.candlepin.controller.Refresher) PoolManager(org.candlepin.controller.PoolManager) Date(java.util.Date) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) Entitlement(org.candlepin.model.Entitlement) ImportFile(org.candlepin.sync.Importer.ImportFile) File(java.io.File) Test(org.junit.Test)

Example 57 with Product

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

the class ProductCertCreationTest method validProduct.

@Test
public void validProduct() {
    Owner owner = TestUtil.createOwner("Example-Corporation");
    Product product = this.createProduct("50", "Test Product", "Standard", "1", "x86_64", "Base");
    ProductCertificate cert = this.createCert(owner, product);
    Assert.assertEquals(product, cert.getProduct());
}
Also used : Owner(org.candlepin.model.Owner) ProductCertificate(org.candlepin.model.ProductCertificate) Product(org.candlepin.model.Product) Test(org.junit.Test)

Example 58 with Product

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

the class ProductImporterTest method testCreateObject.

@Test
public void testCreateObject() throws Exception {
    Product product = TestUtil.createProduct();
    product.setAttribute("a1", "a1");
    product.setAttribute("a2", "a2");
    String json = getJsonForProduct(product);
    Reader reader = new StringReader(json);
    ProductDTO created = importer.createObject(mapper, reader, owner);
    assertEquals(product.getUuid(), created.getUuid());
    assertEquals(product.getName(), created.getName());
    assertEquals(product.getAttributes(), created.getAttributes());
}
Also used : StringReader(java.io.StringReader) Product(org.candlepin.model.Product) Reader(java.io.Reader) StringReader(java.io.StringReader) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) Test(org.junit.Test)

Example 59 with Product

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

the class ProductImporterTest method testContentCreated.

@Test
public void testContentCreated() throws Exception {
    Product product = TestUtil.createProduct();
    addContentTo(product);
    String json = getJsonForProduct(product);
    Reader reader = new StringReader(json);
    ProductDTO created = importer.createObject(mapper, reader, owner);
    ContentDTO c = created.getProductContent().iterator().next().getContent();
    // Metadata expiry should be overridden to 0 on import:
    assertEquals(new Long(1), c.getMetadataExpire());
}
Also used : ContentDTO(org.candlepin.dto.manifest.v1.ContentDTO) StringReader(java.io.StringReader) Product(org.candlepin.model.Product) Reader(java.io.Reader) StringReader(java.io.StringReader) ProductDTO(org.candlepin.dto.manifest.v1.ProductDTO) Test(org.junit.Test)

Example 60 with Product

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

the class TestUtil method copyFromSub.

/**
 * Returns a pool which will look like it was created from the given subscription
 * during refresh pools.
 *
 * @param sub source subscription
 * @return pool for subscription
 */
public static Pool copyFromSub(Subscription sub) {
    Product product = createProduct((ProductData) sub.getProduct());
    Product derivedProduct = createProduct((ProductData) sub.getDerivedProduct());
    List<Product> providedProducts = new LinkedList<>();
    if (sub.getProvidedProducts() != null) {
        for (ProductData pdata : sub.getProvidedProducts()) {
            if (pdata != null) {
                providedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    List<Product> derivedProvidedProducts = new LinkedList<>();
    if (sub.getDerivedProvidedProducts() != null) {
        for (ProductData pdata : sub.getDerivedProvidedProducts()) {
            if (pdata != null) {
                derivedProvidedProducts.add(TestUtil.createProduct(pdata));
            }
        }
    }
    Pool pool = new Pool(sub.getOwner(), product, providedProducts, sub.getQuantity(), sub.getStartDate(), sub.getEndDate(), sub.getContractNumber(), sub.getAccountNumber(), sub.getOrderNumber());
    pool.setDerivedProduct(derivedProduct);
    pool.setDerivedProvidedProducts(derivedProvidedProducts);
    if (sub.getId() != null) {
        pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
    }
    pool.setUpstreamPoolId(sub.getUpstreamPoolId());
    pool.setUpstreamConsumerId(sub.getUpstreamConsumerId());
    pool.setUpstreamEntitlementId(sub.getUpstreamEntitlementId());
    for (Branding branding : sub.getBranding()) {
        pool.getBranding().add(new Branding(branding.getProductId(), branding.getType(), branding.getName()));
    }
    return pool;
}
Also used : ProductData(org.candlepin.model.dto.ProductData) SourceSubscription(org.candlepin.model.SourceSubscription) Product(org.candlepin.model.Product) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) Branding(org.candlepin.model.Branding) LinkedList(java.util.LinkedList)

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