quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
//items that have already received this promotion cannot get it again
assertTrue(quantity==1);
Offer tempOffer = new OfferImpl();
tempOffer.setCombinableWithOtherOffers(true);
tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.NONE);
tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
discount.setPromotion(tempOffer);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
//this item received a different promotion, but the restriction rule is NONE, so this item cannot be a qualifier
//for this promotion
assertTrue(quantity==1);
tempOffer.setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
// this item received a different promotion, but the restriction rule is TARGET,
// so this item can be a target of this promotion but since the "candidateOffer"
// is set to NONE, the quantity can only be 1
assertTrue(quantity == 1);
// Now set the candidateOffer to be "TARGET" and we can use the quantity
// for both promotions.
candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.TARGET);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
// this item received a different promotion, but the restriction rule is TARGET,
// so this item can be a target of this promotion but since the "candidateOffer"
// is set to NONE, the quantity can only be 1
assertTrue(quantity == 2);
priceDetail1.getPromotionDiscounts().clear();
// rest candidate offer
candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.NONE);
PromotionQualifier qualifier = new PromotionQualifier();
qualifier.setPromotion(offer);
qualifier.setQuantity(1);
priceDetail1.getPromotionQualifiers().add(qualifier);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
//items that have already qualified for this promotion cannot qualify again
assertTrue(quantity==1);
qualifier.setPromotion(tempOffer);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
//this item qualified for a different promotion, but the restriction rule is NONE,
// so this item cannot be a qualifier for this promotion
assertTrue(quantity==1);
tempOffer.setOfferItemQualifierRuleType(OfferItemRestrictionRuleType.TARGET);
candidateOffer.getOffer().setOfferItemTargetRuleType(OfferItemRestrictionRuleType.QUALIFIER);
quantity = priceDetail1.getQuantityAvailableToBeUsedAsTarget(candidateOffer);
//this item qualified for a different promotion, but the restriction rule is QUALIFIER,
// so this item can be a qualifier for this promotion
assertTrue(quantity==2);