Search in sources :

Example 1 with PoolComplianceType

use of org.candlepin.model.Pool.PoolComplianceType in project candlepin by candlepin.

the class CalculatedAttributesUtilTest method testCalculatedAttributesPresent.

@Test
public void testCalculatedAttributesPresent() {
    for (PoolComplianceType type : PoolComplianceType.values()) {
        when(mockPool.getComplianceType()).thenReturn(type);
        Date date = new Date();
        Map<String, String> attrs = attrUtil.buildCalculatedAttributes(mockPool, date);
        assertTrue(attrs.containsKey("compliance_type"));
    }
    SuggestedQuantity suggested = new SuggestedQuantity();
    suggested.setSuggested(1L);
    suggested.setIncrement(1L);
    Map<String, SuggestedQuantity> suggestedMap = new HashMap<>();
    suggestedMap.put(pool1.getId(), suggested);
    when(quantityRules.getSuggestedQuantities(any(List.class), any(Consumer.class), any(Date.class))).thenReturn(suggestedMap);
    Date date = new Date();
    attrUtil.setQuantityAttributes(pool1, consumer, date);
    assertTrue(pool1.getCalculatedAttributes().containsKey("suggested_quantity"));
    assertTrue(pool1.getCalculatedAttributes().containsKey("quantity_increment"));
}
Also used : Consumer(org.candlepin.model.Consumer) HashMap(java.util.HashMap) SuggestedQuantity(org.candlepin.policy.js.quantity.SuggestedQuantity) List(java.util.List) Date(java.util.Date) PoolComplianceType(org.candlepin.model.Pool.PoolComplianceType) Test(org.junit.Test)

Example 2 with PoolComplianceType

use of org.candlepin.model.Pool.PoolComplianceType in project candlepin by candlepin.

the class CalculatedAttributesUtilTest method testCalculatedAttributesNotSoTemporary.

@Test
public void testCalculatedAttributesNotSoTemporary() {
    for (PoolComplianceType type : PoolComplianceType.values()) {
        when(mockPool.getComplianceType()).thenReturn(type);
        when(mockPool.isUnmappedGuestPool()).thenReturn(false);
        Date date = new Date();
        Map<String, String> attrs = attrUtil.buildCalculatedAttributes(mockPool, date);
        assertTrue(attrs.containsKey("compliance_type"));
        assertEquals(type.getDescription(), attrs.get("compliance_type"));
    }
}
Also used : Date(java.util.Date) PoolComplianceType(org.candlepin.model.Pool.PoolComplianceType) Test(org.junit.Test)

Example 3 with PoolComplianceType

use of org.candlepin.model.Pool.PoolComplianceType in project candlepin by candlepin.

the class CalculatedAttributesUtilTest method testCalculatedAttributesTemporary.

@Test
public void testCalculatedAttributesTemporary() {
    for (PoolComplianceType type : PoolComplianceType.values()) {
        when(mockPool.getComplianceType()).thenReturn(type);
        when(mockPool.isUnmappedGuestPool()).thenReturn(true);
        Date date = new Date();
        Map<String, String> attrs = attrUtil.buildCalculatedAttributes(mockPool, date);
        assertTrue(attrs.containsKey("compliance_type"));
        assertEquals(type.getDescription() + " (Temporary)", attrs.get("compliance_type"));
    }
}
Also used : Date(java.util.Date) PoolComplianceType(org.candlepin.model.Pool.PoolComplianceType) Test(org.junit.Test)

Example 4 with PoolComplianceType

use of org.candlepin.model.Pool.PoolComplianceType in project candlepin by candlepin.

the class CalculatedAttributesUtil method buildCalculatedAttributes.

public Map<String, String> buildCalculatedAttributes(Pool pool, Date date) {
    Map<String, String> attrMap = new HashMap<>();
    PoolComplianceType type = pool.getComplianceType();
    // TODO: Check that this doesn't break our translation stuff. We may need to have the
    // description strings translated instead.
    attrMap.put("compliance_type", i18n.tr("{0}{1}", type.getDescription(), (pool.isUnmappedGuestPool() ? " (Temporary)" : "")));
    return attrMap;
}
Also used : HashMap(java.util.HashMap) PoolComplianceType(org.candlepin.model.Pool.PoolComplianceType)

Aggregations

PoolComplianceType (org.candlepin.model.Pool.PoolComplianceType)4 Date (java.util.Date)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)1 Consumer (org.candlepin.model.Consumer)1 SuggestedQuantity (org.candlepin.policy.js.quantity.SuggestedQuantity)1