@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));
  }
  @Test(expected = BadRequestException.class)
  public void testBindMultipleParamsBodyAndProducts() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            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,
            consumerBindUtil,
            productCurator,
            null);

    PoolIdAndQuantity[] pools = new PoolIdAndQuantity[2];
    pools[0] = new PoolIdAndQuantity("first", 1);
    pools[1] = new PoolIdAndQuantity("second", 2);

    consumerResource.bind(
        "fake uuid",
        null,
        new String[] {"12232"},
        null,
        null,
        null,
        false,
        null,
        null,
        pools,
        null);
  }
  @Test
  public void testProductNoPool() 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);
    String[] prodIds = {"notthere"};

    when(c.getOwner()).thenReturn(o);
    when(sa.hasUnacceptedSubscriptionTerms(eq(o))).thenReturn(false);
    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(c);
    when(e.bindByProducts(any(AutobindData.class))).thenReturn(null);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            e,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);
    Response r =
        cr.bind("fakeConsumer", null, prodIds, null, null, null, false, null, null, null, null);
    assertEquals(null, r.getEntity());
  }
  @Test(expected = BadRequestException.class)
  public void testBindMultipleParams() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            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,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.bind(
        "fake uuid",
        "fake pool uuid",
        new String[] {"12232"},
        1,
        null,
        null,
        false,
        null,
        null,
        null,
        null);
  }
  @Test(expected = NotFoundException.class)
  public void testBindByPoolBadConsumerUuid() throws Exception {
    ConsumerCurator consumerCurator = mock(ConsumerCurator.class);
    when(consumerCurator.verifyAndLookupConsumerWithEntitlements(any(String.class)))
        .thenThrow(new NotFoundException(""));
    ConsumerResource consumerResource =
        new ConsumerResource(
            consumerCurator,
            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,
            consumerBindUtil,
            productCurator,
            null);

    consumerResource.bind(
        "notarealuuid", "fake pool uuid", null, null, null, null, false, null, null, null, null);
  }
  @SuppressWarnings("unchecked")
  @Test
  public void testBindByPools() throws Exception {
    PoolIdAndQuantity[] pools = new PoolIdAndQuantity[2];
    pools[0] = new PoolIdAndQuantity("first", 1);
    pools[1] = new PoolIdAndQuantity("second", 2);
    ConsumerCurator cc = mock(ConsumerCurator.class);
    SubscriptionServiceAdapter sa = mock(SubscriptionServiceAdapter.class);
    PoolManager pm = mock(PoolManager.class);
    Owner owner = TestUtil.createOwner();
    Consumer consumer = TestUtil.createConsumer(owner);

    when(cc.verifyAndLookupConsumerWithEntitlements(eq("fakeConsumer"))).thenReturn(consumer);
    when(sa.hasUnacceptedSubscriptionTerms(any(Owner.class))).thenReturn(false);

    ConsumerResource cr =
        new ConsumerResource(
            cc,
            null,
            null,
            sa,
            null,
            null,
            null,
            i18n,
            null,
            null,
            null,
            null,
            null,
            pm,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            new CandlepinCommonTestConfig(),
            null,
            null,
            null,
            consumerBindUtil,
            productCurator,
            null);

    Response rsp =
        cr.bind(
            "fakeConsumer",
            null,
            null,
            null,
            null,
            null,
            true,
            null,
            null,
            pools,
            new TrustedUserPrincipal("TaylorSwift"));

    JobDetail detail = (JobDetail) rsp.getEntity();
    PoolIdAndQuantity[] pQs =
        (PoolIdAndQuantity[]) detail.getJobDataMap().get("pool_and_quantities");
    boolean firstFound = false;
    boolean secondFound = false;
    for (PoolIdAndQuantity pq : pQs) {
      if (pq.getPoolId().contentEquals("first")) {
        firstFound = true;
        assertEquals(1, pq.getQuantity().intValue());
      }
      if (pq.getPoolId().contentEquals("second")) {
        secondFound = true;
        assertEquals(2, pq.getQuantity().intValue());
      }
    }
    assertTrue(firstFound);
    assertTrue(secondFound);
  }