use of org.candlepin.model.Product in project candlepin by candlepin.
the class ProductManagerTest method testCreateProductThatAlreadyExists.
@Test(expected = IllegalStateException.class)
public void testCreateProductThatAlreadyExists() {
Owner owner = this.createOwner("test-owner", "Test Owner");
ProductDTO dto = TestUtil.createProductDTO("p1", "prod1");
Product output = this.productManager.createProduct(dto, owner);
assertNotNull(output);
assertEquals(output, this.ownerProductCurator.getProductById(owner, dto.getId()));
this.productManager.createProduct(dto, owner);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ProductManagerTest method testUpdateProduct.
@Test
@Parameters({ "false", "true" })
public void testUpdateProduct(boolean regenCerts) {
Owner owner = this.createOwner("test-owner", "Test Owner");
Product product = this.createProduct("p1", "prod1", owner);
ProductDTO update = TestUtil.createProductDTO("p1", "new product name");
Product output = this.productManager.updateProduct(update, owner, regenCerts);
assertNotEquals(output.getUuid(), product.getUuid());
assertEquals(output.getName(), update.getName());
// We expect the original to be kept around as an orphan until the orphan removal job
// gets around to removing them
assertNotNull(this.productCurator.find(product.getUuid()));
assertEquals(0, this.ownerProductCurator.getOwnerCount(product));
assertNotNull(this.ownerProductCurator.getProductById(owner, product.getId()));
if (regenCerts) {
// TODO: Is there a better way to do this? We won't know the exact product instance,
// we just know that a product should be refreshed as a result of this operation.
verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner)), anyCollectionOf(Product.class), anyBoolean());
} else {
verifyZeroInteractions(this.mockEntCertGenerator);
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ProductManagerTest method testUpdateProductDivergeFromExisting.
@Test
@Parameters({ "false", "true" })
public void testUpdateProductDivergeFromExisting(boolean regenCerts) {
Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
Product product = this.createProduct("p1", "prod1", owner1, owner2);
ProductDTO update = TestUtil.createProductDTO("p1", "updated product");
assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
Product output = this.productManager.updateProduct(update, owner1, regenCerts);
assertNotEquals(output.getUuid(), product.getUuid());
assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
if (regenCerts) {
verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner1)), anyCollectionOf(Product.class), anyBoolean());
} else {
verifyZeroInteractions(this.mockEntCertGenerator);
}
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ProductManagerTest method testUpdateProductNoChange.
@Test
public void testUpdateProductNoChange() {
Owner owner = this.createOwner("test-owner", "Test Owner");
Product product = this.createProduct("p1", "prod1", owner);
Product output = this.productManager.updateProduct(product.toDTO(), owner, true);
assertEquals(output.getUuid(), product.getUuid());
assertEquals(output, product);
verifyZeroInteractions(this.mockEntCertGenerator);
}
use of org.candlepin.model.Product in project candlepin by candlepin.
the class ActivationKeyTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(ActivationKey source, ActivationKeyDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dest.getId());
assertEquals(source.getName(), dest.getName());
assertEquals(source.getDescription(), dest.getDescription());
assertEquals(source.getServiceLevel(), dest.getServiceLevel());
assertEquals(source.isAutoAttach(), dest.isAutoAttach());
if (childrenGenerated) {
this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
for (Product prod : source.getProducts()) {
for (String prodDto : dest.getProductIds()) {
assertNotNull(prodDto);
if (prodDto.equals(prod.getId())) {
// Nothing else to assert on, since prodDto only holds the product id.
}
}
}
for (ActivationKeyPool akPool : source.getPools()) {
for (ActivationKeyDTO.ActivationKeyPoolDTO akPoolDto : dest.getPools()) {
assertNotNull(akPoolDto);
if (akPoolDto.getPoolId().equals(akPool.getId())) {
assertEquals(akPool.getQuantity(), akPoolDto.getQuantity());
}
}
}
for (ActivationKeyContentOverride akOverride : source.getContentOverrides()) {
for (ActivationKeyDTO.ActivationKeyContentOverrideDTO akOverrideDto : dest.getContentOverrides()) {
assertNotNull(akOverrideDto);
if (akOverrideDto.getName().equals(akOverride.getName())) {
assertEquals(akOverrideDto.getContentLabel(), akOverride.getContentLabel());
assertEquals(akOverrideDto.getValue(), akOverride.getValue());
}
}
}
Release releaseSource = source.getReleaseVer();
String releaseDestination = dest.getReleaseVersion();
if (releaseSource != null) {
assertEquals(releaseSource.getReleaseVer(), releaseDestination);
} else {
assertNull(releaseDestination);
}
} else {
assertNull(dest.getOwner());
assertNull(dest.getProductIds());
assertNull(dest.getPools());
assertNull(dest.getContentOverrides());
assertNull(dest.getReleaseVersion());
}
} else {
assertNull(dest);
}
}
Aggregations