Search in sources :

Example 66 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyResourceTest method testActivationKeyWithNullQuantity.

@Test
public void testActivationKeyWithNullQuantity() {
    ActivationKey ak = genActivationKey();
    ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
    Pool p = genPool();
    PoolManager poolManager = mock(PoolManager.class);
    when(akc.verifyAndLookupKey(eq("testKey"))).thenReturn(ak);
    when(poolManager.find(eq("testPool"))).thenReturn(p);
    ActivationKeyResource akr = new ActivationKeyResource(akc, i18n, poolManager, serviceLevelValidator, activationKeyRules, null, new ProductCachedSerializationModule(productCurator), this.modelTranslator);
    akr.addPoolToKey("testKey", "testPool", null);
}
Also used : ProductCachedSerializationModule(org.candlepin.jackson.ProductCachedSerializationModule) ActivationKeyCurator(org.candlepin.model.activationkeys.ActivationKeyCurator) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) Pool(org.candlepin.model.Pool) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) PoolManager(org.candlepin.controller.PoolManager) Test(org.junit.Test)

Example 67 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ConsumerResourceCreationTest method mockActivationKeys.

private List<String> mockActivationKeys() {
    ActivationKey key1 = new ActivationKey("key1", owner);
    when(activationKeyCurator.lookupForOwner("key1", owner)).thenReturn(key1);
    List<String> keys = new LinkedList<>();
    keys.add(key1.getName());
    return keys;
}
Also used : ActivationKey(org.candlepin.model.activationkeys.ActivationKey) LinkedList(java.util.LinkedList)

Example 68 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyRulesTest method testActivationKeyRules.

@Test
public void testActivationKeyRules() {
    ActivationKey key = new ActivationKey();
    key.addPool(genPool(), new Long(1));
    key.addPool(genPool(), new Long(1));
    Pool pool = genPool();
    ValidationResult result = actKeyRules.runPreActKey(key, pool, new Long(1));
    assertTrue(result.getErrors().isEmpty());
    assertTrue(result.getWarnings().isEmpty());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 69 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyRulesTest method testPhysicalOnlyOnKeyWithNullInstanceBased.

/*
     * Similar to above, but because quantity of the instance based
     * subscription is null, it will attempt to bind the correct
     * amount for physical or virtual systems.
     */
@Test
public void testPhysicalOnlyOnKeyWithNullInstanceBased() {
    ActivationKey key = new ActivationKey();
    key.addPool(genInstanceBased(), null);
    Pool pool = genPhysOnlyPool();
    // Should be a valid combination
    ValidationResult result = actKeyRules.runPreActKey(key, pool, new Long(1));
    assertTrue(result.getWarnings().isEmpty());
    assertTrue(result.getErrors().isEmpty());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Example 70 with ActivationKey

use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.

the class ActivationKeyRulesTest method testActivationKeyRulesBadQuantity.

@Test
public void testActivationKeyRulesBadQuantity() {
    ActivationKey key = new ActivationKey();
    Pool pool = genPool();
    ValidationResult result = actKeyRules.runPreActKey(key, pool, new Long(-1));
    assertTrue(result.getWarnings().isEmpty());
    assertEquals(1, result.getErrors().size());
    String expected = "rulefailed.invalid.quantity";
    assertEquals(expected, result.getErrors().get(0).getResourceKey());
}
Also used : Pool(org.candlepin.model.Pool) ValidationResult(org.candlepin.policy.ValidationResult) ActivationKey(org.candlepin.model.activationkeys.ActivationKey) Test(org.junit.Test)

Aggregations

ActivationKey (org.candlepin.model.activationkeys.ActivationKey)76 Test (org.junit.Test)55 Pool (org.candlepin.model.Pool)38 Product (org.candlepin.model.Product)16 ActivationKeyPool (org.candlepin.model.activationkeys.ActivationKeyPool)15 ArrayList (java.util.ArrayList)14 ValidationResult (org.candlepin.policy.ValidationResult)14 Consumer (org.candlepin.model.Consumer)13 ActivationKeyCurator (org.candlepin.model.activationkeys.ActivationKeyCurator)13 PoolManager (org.candlepin.controller.PoolManager)11 ProductCachedSerializationModule (org.candlepin.jackson.ProductCachedSerializationModule)10 Owner (org.candlepin.model.Owner)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 BadRequestException (org.candlepin.common.exceptions.BadRequestException)9 Date (java.util.Date)8 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)8 HashSet (java.util.HashSet)6