Ejemplo n.º 1
0
  @Test
  public void bindByPool() throws EntitlementRefusedException {
    String poolid = "pool10";
    Pool pool = mock(Pool.class);
    Entitlement ent = mock(Entitlement.class);
    List<Entitlement> eList = new ArrayList<Entitlement>();
    eList.add(ent);

    when(pm.find(eq(poolid))).thenReturn(pool);
    Map<String, Integer> pQs = new HashMap<String, Integer>();
    pQs.put(poolid, 1);
    when(pm.entitleByPools(eq(consumer), eq(pQs))).thenReturn(eList);

    List<Entitlement> ents = entitler.bindByPoolQuantity(consumer, poolid, 1);
    assertNotNull(ents);
    assertEquals(ent, ents.get(0));
  }
Ejemplo n.º 2
0
  private void bindByPoolErrorTest(String msg) {
    try {
      String poolid = "pool10";
      Pool pool = mock(Pool.class);
      Map<String, ValidationResult> fakeResult = new HashMap<String, ValidationResult>();
      fakeResult.put(poolid, fakeOutResult(msg));
      EntitlementRefusedException ere = new EntitlementRefusedException(fakeResult);

      when(pool.getId()).thenReturn(poolid);
      when(poolCurator.find(eq(poolid))).thenReturn(pool);
      Map<String, Integer> pQs = new HashMap<String, Integer>();
      pQs.put(poolid, 1);
      when(pm.entitleByPools(eq(consumer), eq(pQs))).thenThrow(ere);
      entitler.bindByPoolQuantity(consumer, poolid, 1);
    } catch (EntitlementRefusedException e) {
      fail(msg + ": threw unexpected error");
    }
  }