Exemplo n.º 1
0
  @Test
  public void testEntitleByProductsEmptyArray() throws Exception {
    Product product = TestUtil.createProduct();
    List<Pool> pools = Util.newList();
    Pool pool1 = TestUtil.createPool(product);
    pools.add(pool1);
    Date now = new Date();

    ValidationResult result = mock(ValidationResult.class);

    // Setup an installed product for the consumer, we'll make the bind request
    // with no products specified, so this should get used instead:
    String[] installedPids = new String[] {product.getId()};
    ComplianceStatus mockCompliance = new ComplianceStatus(now);
    mockCompliance.addNonCompliantProduct(installedPids[0]);
    when(complianceRules.getStatus(any(Consumer.class), any(Date.class)))
        .thenReturn(mockCompliance);

    when(mockPoolCurator.listAvailableEntitlementPools(
            any(Consumer.class),
            any(Owner.class),
            anyString(),
            eq(now),
            anyBoolean(),
            anyBoolean()))
        .thenReturn(pools);

    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool1);
    when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt()))
        .thenReturn(result);

    when(result.isSuccessful()).thenReturn(true);

    List<PoolQuantity> bestPools = new ArrayList<PoolQuantity>();
    bestPools.add(new PoolQuantity(pool1, 1));
    when(autobindRules.selectBestPools(
            any(Consumer.class),
            any(String[].class),
            any(List.class),
            any(ComplianceStatus.class),
            any(String.class),
            any(Set.class)))
        .thenReturn(bestPools);

    // Make the call but provide a null array of product IDs (simulates healing):
    manager.entitleByProducts(TestUtil.createConsumer(o), null, now);

    verify(autobindRules)
        .selectBestPools(
            any(Consumer.class),
            eq(installedPids),
            any(List.class),
            eq(mockCompliance),
            any(String.class),
            any(Set.class));
  }
Exemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Test
  public void testEntitleWithADate() throws Exception {
    Product product = TestUtil.createProduct();
    List<Pool> pools = Util.newList();
    Pool pool1 = TestUtil.createPool(product);
    pools.add(pool1);
    Pool pool2 = TestUtil.createPool(product);
    pools.add(pool2);
    Date now = new Date();

    ValidationResult result = mock(ValidationResult.class);

    when(mockPoolCurator.listAvailableEntitlementPools(
            any(Consumer.class),
            any(Owner.class),
            any(String.class),
            eq(now),
            anyBoolean(),
            anyBoolean()))
        .thenReturn(pools);
    when(mockPoolCurator.lockAndLoad(any(Pool.class))).thenReturn(pool1);
    when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt()))
        .thenReturn(result);

    when(result.isSuccessful()).thenReturn(true);

    List<PoolQuantity> bestPools = new ArrayList<PoolQuantity>();
    bestPools.add(new PoolQuantity(pool1, 1));
    when(autobindRules.selectBestPools(
            any(Consumer.class),
            any(String[].class),
            any(List.class),
            any(ComplianceStatus.class),
            any(String.class),
            any(Set.class)))
        .thenReturn(bestPools);

    List<Entitlement> e =
        manager.entitleByProducts(TestUtil.createConsumer(o), new String[] {product.getId()}, now);

    assertNotNull(e);
    assertEquals(e.size(), 1);
  }