use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ConsumerTranslatorTest method initSourceObject.
@Override
protected Consumer initSourceObject() {
ConsumerType ctype = this.consumerTypeTranslatorTest.initSourceObject();
Consumer consumer = new Consumer();
consumer.setUuid("consumer_uuid");
consumer.setUsername("consumer_user_name");
consumer.setServiceLevel("consumer_service_level");
Owner owner = this.ownerTranslatorTest.initSourceObject();
when(mockOwnerCurator.findOwnerById(eq(owner.getId()))).thenReturn(owner);
consumer.setOwner(owner);
consumer.setType(ctype);
Map<String, String> facts = new HashMap<>();
for (int i = 0; i < 5; ++i) {
facts.put("fact-" + i, "value-" + i);
}
consumer.setFacts(facts);
Set<ConsumerInstalledProduct> installedProducts = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerInstalledProduct installedProduct = new ConsumerInstalledProduct();
installedProduct.setProductId("installedProduct-" + i);
installedProducts.add(installedProduct);
}
consumer.setInstalledProducts(installedProducts);
Set<ConsumerCapability> capabilities = new HashSet<>();
for (int i = 0; i < 5; ++i) {
ConsumerCapability capability = new ConsumerCapability();
capability.setName("capability-" + i);
capabilities.add(capability);
}
consumer.setCapabilities(capabilities);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
return consumer;
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ConsumerTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Consumer source, ConsumerDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getUuid(), dest.getUuid());
assertEquals(source.getUsername(), dest.getUsername());
assertEquals(source.getServiceLevel(), dest.getServiceLevel());
assertEquals(source.getFacts(), dest.getFacts());
assertEquals(source.getCreated(), dest.getCreated());
assertEquals(source.getUpdated(), dest.getUpdated());
if (childrenGenerated) {
ConsumerType ctype = this.mockConsumerTypeCurator.getConsumerType(source);
assertEquals(source.getOwnerId(), dest.getOwner().getId());
this.consumerTypeTranslatorTest.verifyOutput(ctype, dest.getType(), true);
if (source.getInstalledProducts() != null) {
for (ConsumerInstalledProduct cip : source.getInstalledProducts()) {
boolean verified = false;
for (String cipDTO : dest.getInstalledProducts()) {
assertNotNull(cip);
assertNotNull(cipDTO);
if (cip.getProductId().contentEquals(cipDTO)) {
verified = true;
}
}
assertTrue(verified);
}
} else {
assertNull(dest.getInstalledProducts());
}
if (source.getCapabilities() != null) {
for (ConsumerCapability cc : source.getCapabilities()) {
boolean verified = false;
for (String ccDTO : dest.getCapabilities()) {
assertNotNull(cc);
assertNotNull(ccDTO);
if (cc.getName().contentEquals(ccDTO)) {
verified = true;
}
}
assertTrue(verified);
}
} else {
assertNull(dest.getCapabilities());
}
} else {
assertNull(dest.getOwner());
assertNull(dest.getType());
assertNull(dest.getInstalledProducts());
assertNull(dest.getCapabilities());
}
} else {
assertNull(dest);
}
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class DefaultEntitlementCertServiceAdapterTest method ensureV3CertIsCreatedWhenV3CapabilityPresent.
@Test
public void ensureV3CertIsCreatedWhenV3CapabilityPresent() throws Exception {
ConsumerType ctype = new ConsumerType(ConsumerType.ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-id");
consumer.setType(ctype);
when(mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
when(mockConsumerTypeCurator.getConsumerType(consumer)).thenReturn(ctype);
Set<ConsumerCapability> set = new HashSet<>();
set.add(new ConsumerCapability(consumer, "cert_v3"));
consumer.setCapabilities(set);
DefaultEntitlementCertServiceAdapter entAdapter = this.initCertServiceAdapter();
entAdapter.createX509Certificate(consumer, owner, pool, entitlement, product, new HashSet<>(), getProductModels(product, new HashSet<>(), "prefix", entitlement), new BigInteger("1234"), keyPair, true);
verify(mockV3extensionUtil).getExtensions();
verify(mockV3extensionUtil).getByteExtensions(eq(product), any(List.class), any(String.class), any(Map.class));
verifyZeroInteractions(mockExtensionUtil);
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementWithDerivedProductCapabilitySuccessOnBestPools.
@Test
public void preEntitlementWithDerivedProductCapabilitySuccessOnBestPools() {
Consumer c = this.createMockConsumer(true);
HashSet<ConsumerCapability> capabilities = new HashSet<>();
capabilities.add(new ConsumerCapability(c, "derived_product"));
c.setCapabilities(capabilities);
Product prod = TestUtil.createProduct();
Product derived = TestUtil.createProduct("sub-prod-id");
Pool p = TestUtil.createPool(prod);
p.setDerivedProduct(derived);
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BEST_POOLS);
assertNotNull(results);
assertTrue("Expected no warnings or errors.", results.isSuccessful());
}
use of org.candlepin.model.ConsumerCapability in project candlepin by candlepin.
the class ManifestEntitlementRulesTest method preEntitlementNoInstanceCapableBindError.
@Test
public void preEntitlementNoInstanceCapableBindError() {
// Test with sockets to make sure that they are skipped.
Consumer c = this.createMockConsumer(true);
Set<ConsumerCapability> caps = new HashSet<>();
c.setCapabilities(caps);
Product prod = TestUtil.createProduct();
prod.setAttribute(Product.Attributes.INSTANCE_MULTIPLIER, "2");
Pool p = TestUtil.createPool(prod);
p.setId("poolId");
ValidationResult results = enforcer.preEntitlement(c, p, 1, CallerType.BIND);
assertNotNull(results);
assertEquals(0, results.getWarnings().size());
ValidationError error = results.getErrors().get(0);
assertEquals("rulefailed.instance.unsupported.by.consumer", error.getResourceKey());
}
Aggregations