use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testReaddingProductIDs.
@Test(expected = BadRequestException.class)
public void testReaddingProductIDs() {
ActivationKey key = new ActivationKey();
Owner owner = createOwner();
Product product = this.createProduct(owner);
key.setOwner(owner);
key.setName("dd");
key = activationKeyCurator.create(key);
assertNotNull(key.getId());
activationKeyResource.addProductIdToKey(key.getId(), product.getId());
assertEquals(1, key.getProducts().size());
activationKeyResource.addProductIdToKey(key.getId(), product.getId());
// ^ Kaboom.
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testReaddingPools.
@Test(expected = BadRequestException.class)
public void testReaddingPools() {
ActivationKey key = new ActivationKey();
Product product = this.createProduct(owner);
Pool pool = createPool(owner, product, 10L, new Date(), new Date());
key.setOwner(owner);
key.setName("dd");
key = activationKeyCurator.create(key);
assertNotNull(key.getId());
activationKeyResource.addPoolToKey(key.getId(), pool.getId(), 1L);
assertTrue(key.getPools().size() == 1);
activationKeyResource.addPoolToKey(key.getId(), pool.getId(), 1L);
// ^ Kaboom.
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testCreateReadDelete.
@Test(expected = BadRequestException.class)
public void testCreateReadDelete() {
ActivationKey key = new ActivationKey();
key.setOwner(owner);
key.setName("dd");
key.setServiceLevel("level1");
key.setReleaseVer(new Release("release1"));
activationKeyCurator.create(key);
assertNotNull(key.getId());
ActivationKeyDTO output = activationKeyResource.getActivationKey(key.getId());
assertNotNull(output);
output.setName("JarJarBinks");
output.setServiceLevel("level2");
output.setReleaseVersion("release2");
activationKeyResource.updateActivationKey(key.getId(), output);
output = activationKeyResource.getActivationKey(key.getId());
assertEquals("JarJarBinks", output.getName());
assertEquals("level2", output.getServiceLevel());
assertEquals("release2", output.getReleaseVersion());
activationKeyResource.deleteActivationKey(key.getId());
output = activationKeyResource.getActivationKey(key.getId());
assertNull(output);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResourceTest method testActivationKeyWithLargePoolQuantity.
@Test
public void testActivationKeyWithLargePoolQuantity() {
ActivationKey ak = genActivationKey();
ActivationKeyCurator akc = mock(ActivationKeyCurator.class);
Pool p = genPool();
p.getProduct().setAttribute(Pool.Attributes.MULTI_ENTITLEMENT, "yes");
p.setQuantity(10L);
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", 15L);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerResourceCreationTest method registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner.
@Test
public void registerFailsWithKeyWhenAutobindOnKeyAndDisabledOnOwner() {
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.SYSTEM);
ConsumerTypeDTO ctypeDTO = this.modelTranslator.translate(ctype, ConsumerTypeDTO.class);
this.mockConsumerType(ctype);
// Disable autobind for the owner.
owner.setAutobindDisabled(true);
// Create a key that has autobind disabled.
ActivationKey key = new ActivationKey("autobind-disabled-key", owner);
key.setAutoAttach(true);
when(activationKeyCurator.lookupForOwner(key.getName(), owner)).thenReturn(key);
// No auth should be required for registering with keys:
Principal p = new NoAuthPrincipal();
ConsumerDTO consumer = TestUtil.createConsumerDTO("sys.example.com", null, null, ctypeDTO);
resource.create(consumer, p, null, owner.getKey(), key.getName(), true);
}
Aggregations