Example #1
0
  @Test
  public void testCreatedDevPoolAttributes() {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
    p1.setAttribute("support_level", "Premium");
    p1.setAttribute("expires_after", "47");
    Product p2 = TestUtil.createProduct("provided-product1", "Provided Product 1");
    Product p3 = TestUtil.createProduct("provided-product2", "Provided Product 2");
    devProdDTOs.add(p1.toDTO());
    devProdDTOs.add(p2.toDTO());
    devProdDTOs.add(p3.toDTO());
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p1.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p2));
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(p3));
    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);

    this.mockProducts(owner, p1, p2, p3);
    this.mockProductImport(owner, p1, p2, p3);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());

    Pool created = entitler.assembleDevPool(devSystem, devSystem.getFact("dev_sku"));
    Calendar cal = Calendar.getInstance();
    cal.setTime(created.getStartDate());
    cal.add(Calendar.DAY_OF_YEAR, 47);
    assertEquals(created.getEndDate(), cal.getTime());
    assertEquals("true", created.getAttributeValue(Pool.Attributes.DEVELOPMENT_POOL));
    assertEquals(devSystem.getUuid(), created.getAttributeValue(Pool.Attributes.REQUIRES_CONSUMER));
    assertEquals(p1.getId(), created.getProductId());
    assertEquals(2, created.getProvidedProducts().size());
    assertEquals("Premium", created.getProduct().getAttributeValue("support_level"));
    assertEquals(1L, created.getQuantity().longValue());
  }
Example #2
0
  @Test
  public void testDevPoolCreationAtBindNoFailMissingInstalledProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip1 = TestUtil.createProduct("test-product-installed-1", "Installed Test Product 1");
    Product ip2 = TestUtil.createProduct("test-product-installed-2", "Installed Test Product 2");
    devProdDTOs.add(p.toDTO());
    devProdDTOs.add(ip1.toDTO());

    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<Pool>();
    activeList.add(activePool);

    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip1));
    devSystem.addInstalledProduct(new ConsumerInstalledProduct(ip2));

    when(config.getBoolean(eq(ConfigProperties.STANDALONE))).thenReturn(false);
    when(poolCurator.hasActiveEntitlementPools(eq(owner), any(Date.class))).thenReturn(true);
    when(productAdapter.getProductsByIds(any(Owner.class), any(List.class)))
        .thenReturn(devProdDTOs);

    this.mockProducts(owner, p, ip1, ip2);
    this.mockProductImport(owner, p, ip1, ip2);
    this.mockContentImport(owner, Collections.<String, Content>emptyMap());

    Pool expectedPool = entitler.assembleDevPool(devSystem, p.getId());
    when(pm.createPool(any(Pool.class))).thenReturn(expectedPool);
    AutobindData ad = new AutobindData(devSystem);
    entitler.bindByProducts(ad);
  }
Example #3
0
  @Test
  public void testCreatedDevSkuWithNoSla() {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    final Product p1 = TestUtil.createProduct("dev-product", "Dev Product");
    devProdDTOs.add(p1.toDTO());
    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p1.getId());

    when(productAdapter.getProductsByIds(eq(owner), any(List.class))).thenReturn(devProdDTOs);
    mockUpdateProduct(p1, owner);

    this.mockContentImport(owner, Collections.<String, Content>emptyMap());
    when(productManager.importProducts(eq(owner), any(Map.class), any(Map.class)))
        .thenAnswer(
            new Answer<ImportResult<Product>>() {
              @Override
              public ImportResult<Product> answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                Map<String, ProductData> productData = (Map<String, ProductData>) args[1];
                ImportResult<Product> importResult = new ImportResult<Product>();
                Map<String, Product> output = importResult.getCreatedEntities();

                // We need to copy the attributes from the product data to the product to
                // simulate a proper update.
                for (ProductData pdata : productData.values()) {
                  if (pdata != null) {
                    if (p1.getId().equals(pdata.getId())) {
                      p1.clearAttributes();
                      if (pdata.getAttributes() != null) {
                        for (ProductAttributeData attrib : pdata.getAttributes()) {
                          p1.setAttribute(attrib.getName(), attrib.getValue());
                        }
                      }

                      output.put(p1.getId(), p1);
                    } else {
                      Product product = new Product(pdata.getId(), pdata.getName());
                      // Do we care about this product? Probably not.
                      output.put(product.getId(), product);
                    }
                  }
                }

                return importResult;
              }
            });

    Pool created = entitler.assembleDevPool(devSystem, devSystem.getFact("dev_sku"));
    assertEquals(entitler.DEFAULT_DEV_SLA, created.getProduct().getAttributeValue("support_level"));
  }