ActivationKeyRules { public ValidationResult runPoolValidationForActivationKey(ActivationKey key, Pool pool, Long quantity) { ValidationResult result = new ValidationResult(); if (quantity != null && quantity < 1) { result.addError(ErrorKeys.INVALID_QUANTITY); } if (!PropertyConverter.toBoolean(pool.getMergedProductAttribute(Pool.Attributes.MULTI_ENTITLEMENT))) { if (quantity != null && quantity > 1) { result.addError(ErrorKeys.INVALID_NON_MULTIENT_QUANTITY); } for (ActivationKeyPool akPool : key.getPools()) { if (pool.getId().equals(akPool.getPool().getId())) { result.addError(ErrorKeys.ALREADY_EXISTS); break; } } } if (ConsumerType.ConsumerTypeEnum.PERSON.getLabel().equalsIgnoreCase( pool.getMergedAttribute(Pool.Attributes.REQUIRES_CONSUMER_TYPE))) { result.addError(ErrorKeys.CANNOT_USE_PERSON_POOLS); } return result; } @Inject  ActivationKeyRules(I18n i18n); ValidationResult runPoolValidationForActivationKey(ActivationKey key, Pool pool, Long quantity); String validatePoolForActivationKey(ActivationKey key, Pool pool, Long quantity);  }
@Test public void testActivationKeyRulesNoPools() { ActivationKey key = new ActivationKey(); Pool pool = genPool(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testPhysicalOnlyOnKeyWithNullInstanceBased() { ActivationKey key = new ActivationKey(); key.addPool(genInstanceBased(), null); Pool pool = genPhysOnlyPool(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testAllowsAddingVirtQuantityInstanceBased() { ActivationKey key = new ActivationKey(); key.addPool(genPool(), new Long(1)); Pool pool = genInstanceBased(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testActivationKeyRulesBadQuantity() { ActivationKey key = new ActivationKey(); Pool pool = genPool(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(-1)); assertEquals(1, result.getErrorKeys().size()); assertEquals(ActivationKeyRules.ErrorKeys.INVALID_QUANTITY, result.getErrorKeys().get(0)); }
@Test public void testActivationKeyRulesSufficientQuantity() { ActivationKey key = new ActivationKey(); Pool pool = genPool(); pool.setQuantity(5L); pool.setConsumed(4L); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(2)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testActivationKeyRulesUnlimitedQuantity() { ActivationKey key = new ActivationKey(); Pool pool = genPool(); pool.setQuantity(-1L); pool.setConsumed(4L); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(2)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testDoesntAllowPeoplePools() { ActivationKey key = new ActivationKey(); Pool pool = genPoolForType("person"); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertEquals(1, result.getErrorKeys().size()); assertEquals(ActivationKeyRules.ErrorKeys.CANNOT_USE_PERSON_POOLS, result.getErrorKeys().get(0)); }
@Test public void testDoesAllowSameConsumerTypePools() { ActivationKey key = new ActivationKey(); key.addPool(genPoolForType("system"), 1L); Pool pool = genPoolForType("system"); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testDoesAllowSameHostRequires() { ActivationKey key = new ActivationKey(); key.addPool(genHostRestricted("host1"), 1L); Pool pool = genHostRestricted("host1"); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testNonMultientOne() { ActivationKey key = new ActivationKey(); Pool pool = genNonMultiEnt(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }
@Test public void testNonMultientMultipleQuantity() { ActivationKey key = new ActivationKey(); Pool pool = genNonMultiEnt(); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(2)); assertEquals(1, result.getErrorKeys().size()); assertEquals(ActivationKeyRules.ErrorKeys.INVALID_NON_MULTIENT_QUANTITY, result.getErrorKeys().get(0)); }
@Test public void testNonMultientOneTwice() { ActivationKey key = new ActivationKey(); Pool pool = genNonMultiEnt(); key.addPool(pool, 1L); ValidationResult result = actKeyRules.runPoolValidationForActivationKey(key, pool, new Long(1)); assertEquals(1, result.getErrorKeys().size()); assertEquals(ActivationKeyRules.ErrorKeys.ALREADY_EXISTS, result.getErrorKeys().get(0)); }
@Test public void testNullQuantityInstanceAndPhysicalOnly() { ActivationKey key = new ActivationKey(); key.addPool(genInstanceBased(), null); ValidationResult result = actKeyRules.runPoolValidationForActivationKey( key, genPhysOnlyPool(), new Long(1)); assertTrue(result.getErrorKeys().isEmpty()); }