Example #1
0
  @Test
  public void testIsNotVirtWhenFactIsEmpty() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Example #2
0
 @Test
 public void testVirtUses1IfNoVcpu() {
   // Ensure that we start this test with no entitlements.
   consumer.getEntitlements().clear();
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(SOCKET_FACT, "4");
   consumer.setFact(CORES_FACT, "8");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Example #3
0
 @Test
 public void testVirtIgnoresSockets() {
   // Ensure that we start this test with no entitlements.
   consumer.getEntitlements().clear();
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(SOCKET_FACT, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(1), suggested.getSuggested());
 }
Example #4
0
  @Test
  public void testInstanceBasedOnPhysicalNotEnoughAvailableUneven() {
    consumer.setFact(IS_VIRT, "false");
    consumer.setFact(SOCKET_FACT, "40"); // lots of ents required
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    pool.setQuantity(3L);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
    assertEquals(new Long(2), suggested.getIncrement());
  }
Example #5
0
 @Test
 public void testPhysicalRoundsUp() {
   consumer.setFact(SOCKET_FACT, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "3");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(2), suggested.getSuggested());
 }
Example #6
0
  @Test
  public void testFutureSuggested() {
    consumer.setFact(SOCKET_FACT, "4");

    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));

    Pool currentPool = TestUtil.createPool(owner, product);
    currentPool.setStartDate(TestUtil.createDate(2000, 1, 1));
    currentPool.setEndDate(TestUtil.createDate(5000, 1, 1));
    currentPool.getProduct().setAttribute("multi-entitlement", "yes");
    currentPool.getProduct().setAttribute("stacking_id", "1");

    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    currentPool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement currentEntitlement = TestUtil.createEntitlement(owner, consumer, currentPool, null);
    currentEntitlement.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(currentEntitlement);
    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(currentPool, consumer, TestUtil.createDate(2010, 6, 1));
    assertEquals(new Long(0), suggested.getSuggested());

    // Make sure current coverage does not affect the future
    suggested = quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(9000, 6, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
Example #7
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 #8
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 #9
0
  @Test
  public void testPhysicalIgnoresFutureConsumed() {
    // Setup a future pool for the same product:
    Pool futurePool = TestUtil.createPool(owner, product);
    futurePool.setStartDate(TestUtil.createDate(2050, 1, 1));
    futurePool.setEndDate(TestUtil.createDate(2060, 1, 1));

    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    futurePool.getProduct().setAttribute("multi-entitlement", "yes");
    futurePool.getProduct().setAttribute("stacking_id", "1");
    futurePool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green in future but we have nothing now:
    Entitlement e = createValidEntitlement(futurePool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(4), suggested.getSuggested());
  }
Example #10
0
  @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<Entitlement>();
    entSet.add(e);
    pool1.setEntitlements(entSet);
    pool1.getProduct().setAttribute("multi-entitlement", "yes");
    pool1.getProduct().setAttribute("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());
  }
Example #11
0
  @Test
  public void testDevPoolCreationAtBind() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    Product p = TestUtil.createProduct("test-product", "Test Product");

    p.setAttribute("support_level", "Premium");
    devProdDTOs.add(p.toDTO());
    Pool activePool = TestUtil.createPool(owner, p);
    List<Pool> activeList = new ArrayList<Pool>();
    activeList.add(activePool);
    Pool devPool = mock(Pool.class);

    Consumer devSystem = TestUtil.createConsumer(owner);
    devSystem.setFact("dev_sku", p.getId());

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

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

    when(pm.createPool(any(Pool.class))).thenReturn(devPool);
    when(devPool.getId()).thenReturn("test_pool_id");

    AutobindData ad = new AutobindData(devSystem);
    entitler.bindByProducts(ad);
    verify(pm).createPool(any(Pool.class));
  }
Example #12
0
 @Test
 public void testVirtRoundsUp() {
   consumer.setFact(IS_VIRT, "true");
   consumer.setFact(CORES_FACT, "8");
   pool.getProduct().setAttribute(VCPU_ATTRIBUTE, "6");
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(2), suggested.getSuggested());
 }
Example #13
0
 @Test
 public void testUnlimitedQuantity() {
   consumer.setFact(SOCKET_FACT, "8");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   pool.setQuantity(new Long(-1));
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(4), suggested.getSuggested());
 }
 private Consumer mockConsumer(String[] installedProducts) {
   Consumer c = new Consumer();
   for (String pid : installedProducts) {
     c.addInstalledProduct(new ConsumerInstalledProduct(pid, pid));
   }
   c.setFact("cpu.cpu_socket(s)", "8"); // 8 socket machine
   return c;
 }
Example #15
0
  @Test
  public void testCalculatedValueIsZeroWhenNegativeIsCalculated() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(1000);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(0), suggested.getSuggested());
  }
Example #16
0
  @Test
  public void testTotalConsumedDoesNotIncludeFutureEntitlements() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Entitlement e = TestUtil.createEntitlement(owner, consumer, pool, null);
    pool.setStartDate(TestUtil.createDate(9000, 1, 1));
    pool.setEndDate(TestUtil.createDate(9001, 1, 1));
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested =
        quantityRules.getSuggestedQuantity(pool, consumer, TestUtil.createDate(2010, 1, 1));
    assertEquals(new Long(2), suggested.getSuggested());
  }
Example #17
0
  @Test
  public void testTotalConsumedIsZeroWhenNoMatches() {
    consumer.setFact(IS_VIRT, "");
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");

    Product product2 = TestUtil.createProduct();
    Pool pool2 = TestUtil.createPool(owner, product2);

    Entitlement e = createValidEntitlement(pool2);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Example #18
0
  @Test
  public void testSingleSocketInstanceBasedOnPhysical() {
    consumer.setFact(IS_VIRT, "false");
    consumer.setFact(SOCKET_FACT, "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
    assertEquals(new Long(2), suggested.getIncrement());
  }
Example #19
0
  /*
   * Distributors should always get suggested=1, increment=1
   */
  @Test
  public void testInstanceBasedOnDistributor() {
    Consumer dist = TestUtil.createConsumer(owner);
    dist.getType().setManifest(true);
    dist.setFact(IS_VIRT, "false");
    dist.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
    pool.getProduct().setAttribute(INSTANCE_ATTRIBUTE, "2");

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, dist, new Date());
    assertEquals(new Long(1), suggested.getSuggested());
    assertEquals(new Long(1), suggested.getIncrement());
  }
Example #20
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"));
  }
Example #21
0
 /*
  * Guest limit should not have any bearing on the suggested quantity
  */
 @Test
 public void testInsufficientGuestLimit() {
   consumer.setFact(SOCKET_FACT, "8");
   Map<String, String> guestAttrs = new HashMap<String, String>();
   guestAttrs.put("virtWhoType", "libvirt");
   guestAttrs.put("active", "1");
   for (int i = 0; i < 5; i++) {
     consumer.addGuestId(new GuestId("" + i, consumer, guestAttrs));
   }
   pool.getProduct().setAttribute(GUEST_LIMIT_ATTRIBUTE, "4");
   pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "2");
   pool.setQuantity(new Long(-1));
   SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
   assertEquals(new Long(4), suggested.getSuggested());
 }
Example #22
0
  @Test
  public void testPhysicalAccountsForCurrentlyConsumed() {
    consumer.setFact(SOCKET_FACT, "4");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(2);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, new Date());
    assertEquals(new Long(2), suggested.getSuggested());
  }
Example #23
0
  @Test(expected = ForbiddenException.class)
  public void testDevPoolCreationAtBindFailNotActive() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    devProdDTOs.add(p.toDTO());

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

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

    AutobindData ad = new AutobindData(devSystem);
    entitler.bindByProducts(ad);
  }
Example #24
0
  @Test
  public void testRevokesLapsedUnmappedGuestEntitlementsOnAutoHeal() throws Exception {
    Owner owner1 = new Owner("o1");

    Product product = TestUtil.createProduct();

    Pool p1 = TestUtil.createPool(owner1, product);

    p1.addAttribute(new PoolAttribute("unmapped_guests_only", "true"));

    Date thirtySixHoursAgo = new Date(new Date().getTime() - 36L * 60L * 60L * 1000L);
    Date twelveHoursAgo = new Date(new Date().getTime() - 12L * 60L * 60L * 1000L);

    Consumer c;

    c = TestUtil.createConsumer(owner1);
    c.setCreated(thirtySixHoursAgo);
    c.setFact("virt.uuid", "1");

    Entitlement e1 = TestUtil.createEntitlement(owner1, c, p1, null);
    e1.setEndDateOverride(twelveHoursAgo);
    Set<Entitlement> entitlementSet1 = new HashSet<Entitlement>();
    entitlementSet1.add(e1);

    p1.setEntitlements(entitlementSet1);

    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    when(cqmock.iterator()).thenReturn(Arrays.asList(e1).iterator());
    when(entitlementCurator.findByPoolAttribute(eq(c), eq("unmapped_guests_only"), eq("true")))
        .thenReturn(cqmock);

    String[] pids = {product.getId(), "prod2"};
    when(cc.findByUuid(eq("abcd1234"))).thenReturn(c);
    entitler.bindByProducts(pids, "abcd1234", null, null);
    AutobindData data = AutobindData.create(c).forProducts(pids);
    verify(pm).entitleByProducts(eq(data));
    verify(pm).revokeEntitlement(e1);
  }
Example #25
0
  @Test
  public void testDevPoolCreationAtBindFailNoSkuProduct() throws Exception {
    Owner owner = TestUtil.createOwner("o");
    List<ProductData> devProdDTOs = new ArrayList<ProductData>();
    Product p = TestUtil.createProduct("test-product", "Test Product");
    Product ip = TestUtil.createProduct("test-product-installed", "Installed Test Product");
    devProdDTOs.add(ip.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(ip));

    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);
    when(ownerProductCurator.getProductById(eq(owner), eq(p.getId()))).thenReturn(p);
    when(ownerProductCurator.getProductById(eq(owner), eq(ip.getId()))).thenReturn(ip);

    mockUpdateProduct(p, owner);
    mockUpdateProduct(ip, owner);
    mockProductImport(owner, p, ip);
    mockContentImport(owner, new Content[] {});

    AutobindData ad = new AutobindData(devSystem);
    try {
      entitler.bindByProducts(ad);
    } catch (ForbiddenException fe) {
      assertEquals(
          i18n.tr("SKU product not available to this development unit: ''{0}''", p.getId()),
          fe.getMessage());
    }
  }
Example #26
0
  @Test
  public void testPhysicalIgnoresPastConsumed() {
    pool.getProduct().setAttribute("multi-entitlement", "yes");
    pool.getProduct().setAttribute("stacking_id", "1");
    pool.getProduct().setAttribute(SOCKET_ATTRIBUTE, "1");

    consumer.setFact(SOCKET_FACT, "4");

    // Green now, but we will ask for suggested quantity on a date in the future:
    Entitlement e = createValidEntitlement(pool);
    e.setQuantity(4);

    Set<Entitlement> ents = new HashSet<Entitlement>();
    ents.add(e);

    consumer.setEntitlements(ents);

    // Ask for quantity in the future, past the end of the current pool:
    Calendar c = Calendar.getInstance();
    c.setTime(pool.getEndDate());
    Date futureDate = TestUtil.createDate(c.get(Calendar.YEAR) + 1, 1, 1);
    SuggestedQuantity suggested = quantityRules.getSuggestedQuantity(pool, consumer, futureDate);
    assertEquals(new Long(4), suggested.getSuggested());
  }
  @Test
  public void testcheckForGuestsMigration() {
    ConsumerResource cr =
        Mockito.spy(
            new ConsumerResource(
                mockedConsumerCurator,
                null,
                null,
                null,
                null,
                null,
                null,
                i18n,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                new CandlepinCommonTestConfig(),
                null,
                null,
                null,
                null,
                productCurator,
                null));
    List<GuestId> startGuests = new ArrayList<GuestId>();
    List<GuestId> updatedGuests = new ArrayList<GuestId>();
    VirtConsumerMap guestConsumerMap = new VirtConsumerMap();
    Owner o = mock(Owner.class);
    Consumer host = new Consumer();

    Consumer cOne = new Consumer();
    cOne.setFact("virt.is_guest", "true");
    cOne.setFact("virt.uuid", cOne.getUuid() + "-vuuid");
    cOne.setOwner(o);
    GuestId one = new GuestId(cOne.getFact("virt.uuid"));
    startGuests.add(one);
    guestConsumerMap.add(cOne.getFact("virt.uuid"), cOne);

    Consumer cTwo = new Consumer();
    cTwo.setFact("virt.is_guest", "true");
    cTwo.setFact("virt.uuid", cTwo.getUuid() + "-vuuid");
    cTwo.setOwner(o);
    GuestId two = new GuestId(cTwo.getFact("virt.uuid"));
    startGuests.add(two);
    updatedGuests.add(two);
    guestConsumerMap.add(cTwo.getFact("virt.uuid"), cTwo);

    Consumer cThree = new Consumer();
    cThree.setFact("virt.is_guest", "true");
    cThree.setFact("virt.uuid", cThree.getUuid() + "-vuuid");
    cThree.setOwner(o);
    GuestId three = new GuestId(cThree.getFact("virt.uuid"));
    updatedGuests.add(three);
    guestConsumerMap.add(cThree.getFact("virt.uuid"), cThree);

    cr.checkForGuestsMigration(host, startGuests, updatedGuests, guestConsumerMap);
    verify(cr).checkForGuestMigration(host, cOne);
    verify(cr).checkForGuestMigration(host, cTwo);
    verify(cr).checkForGuestMigration(host, cThree);
  }