示例#1
0
  @Test
  public void testUnmappedGuestRevocation() throws Exception {
    Owner owner1 = new Owner("o1");
    Owner owner2 = new Owner("o2");

    Product product1 = TestUtil.createProduct();
    Product product2 = TestUtil.createProduct();

    Pool p1 = TestUtil.createPool(owner1, product1);
    Pool p2 = TestUtil.createPool(owner2, product2);

    p1.addAttribute(new PoolAttribute("unmapped_guests_only", "true"));
    p2.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(twelveHoursAgo);

    Entitlement e1 = TestUtil.createEntitlement(owner1, c, p1, null);
    e1.setEndDateOverride(new Date(new Date().getTime() + 1L * 60L * 60L * 1000L));
    Set<Entitlement> entitlementSet1 = new HashSet<Entitlement>();
    entitlementSet1.add(e1);

    p1.setEntitlements(entitlementSet1);

    c = TestUtil.createConsumer(owner2);
    c.setCreated(twelveHoursAgo);

    Entitlement e2 = TestUtil.createEntitlement(owner2, c, p2, null);
    e2.setEndDateOverride(thirtySixHoursAgo);
    Set<Entitlement> entitlementSet2 = new HashSet<Entitlement>();
    entitlementSet2.add(e2);

    p2.setEntitlements(entitlementSet2);

    CandlepinQuery cqmock = mock(CandlepinQuery.class);

    when(cqmock.iterator()).thenReturn(Arrays.asList(e1, e2).iterator());
    when(entitlementCurator.findByPoolAttribute(eq("unmapped_guests_only"), eq("true")))
        .thenReturn(cqmock);

    int total = entitler.revokeUnmappedGuestEntitlements();
    assertEquals(1, total);

    verify(pm).revokeEntitlement(e1);
  }
示例#2
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);
  }