Esempio n. 1
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);
  }
Esempio n. 2
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));
  }
Esempio n. 3
0
 @Test
 public void bindByProducts() throws Exception {
   String[] pids = {"prod1", "prod2", "prod3"};
   AutobindData data = AutobindData.create(consumer).forProducts(pids);
   entitler.bindByProducts(data);
   verify(pm).entitleByProducts(data);
 }
Esempio n. 4
0
 @Test
 public void bindByProductsString() throws Exception {
   String[] pids = {"prod1", "prod2", "prod3"};
   when(cc.findByUuid(eq("abcd1234"))).thenReturn(consumer);
   entitler.bindByProducts(pids, "abcd1234", null, null);
   AutobindData data = AutobindData.create(consumer).forProducts(pids);
   verify(pm).entitleByProducts(eq(data));
 }
Esempio n. 5
0
 private void bindByProductErrorTest(String msg) throws Exception {
   try {
     String[] pids = {"prod1", "prod2", "prod3"};
     Map<String, ValidationResult> fakeResult = new HashMap<String, ValidationResult>();
     fakeResult.put("blah", fakeOutResult(msg));
     EntitlementRefusedException ere = new EntitlementRefusedException(fakeResult);
     AutobindData data = AutobindData.create(consumer).forProducts(pids);
     when(pm.entitleByProducts(data)).thenThrow(ere);
     entitler.bindByProducts(data);
   } catch (EntitlementRefusedException e) {
     fail(msg + ": threw unexpected error");
   }
 }
Esempio n. 6
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);
  }
Esempio n. 7
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);
  }
Esempio n. 8
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());
    }
  }