Example #1
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);
 }
Example #2
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));
 }
  @Test
  public void futureHealing() throws Exception {
    Consumer c = mock(Consumer.class);
    Owner o = mock(Owner.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    Entitler e = mock(Entitler.class);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    ConsumerInstalledProduct cip = mock(ConsumerInstalledProduct.class);
    Set<ConsumerInstalledProduct> products = new HashSet<ConsumerInstalledProduct>();
    products.add(cip);

    when(c.getOwner()).thenReturn(o);
    when(cip.getProductId()).thenReturn("product-foo");
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    String dtStr = "2011-09-26T18:10:50.184081+00:00";
    Date dt = ResourceDateParser.parseDateString(dtStr);
    cr.bind("fakeConsumer", null, null, null, null, null, false, dtStr, null, null, null);
    AutobindData data = AutobindData.create(c).on(dt);
    verify(e).bindByProducts(eq(data));
  }
Example #4
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");
   }
 }
Example #5
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);
  }