use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ManifestManagerTest method verifyConsumerIsDistributorBeforeSchedulingManifestGeneration.
@Test
public void verifyConsumerIsDistributorBeforeSchedulingManifestGeneration() throws Exception {
Owner owner = TestUtil.createOwner();
Consumer consumer = this.createMockConsumer(owner, false);
ConsumerType ctype = consumerTypeCurator.getConsumerType(consumer);
Cdn cdn = new Cdn("test-cdn", "Test CDN", "");
String webAppPrefix = "webapp-prefix";
String apiUrl = "api-url";
Map<String, String> extData = new HashMap<>();
when(consumerCurator.verifyAndLookupConsumer(eq(consumer.getUuid()))).thenReturn(consumer);
when(cdnCurator.lookupByLabel(eq(cdn.getLabel()))).thenReturn(cdn);
try {
manager.generateManifestAsync(consumer.getUuid(), owner.getKey(), cdn.getLabel(), webAppPrefix, apiUrl, extData);
fail("Expected ForbiddenException not thrown");
} catch (Exception e) {
assertTrue(e instanceof ForbiddenException);
String expectedMsg = String.format("Unit %s cannot be exported. A manifest cannot be made for " + "units of type \"%s\".", consumer.getUuid(), ctype.getLabel());
assertEquals(e.getMessage(), expectedMsg);
}
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class PoolManagerTest method testDeleteExcessEntitlementsBatch.
@Test
public void testDeleteExcessEntitlementsBatch() throws EntitlementRefusedException {
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("testing-subid");
pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
final Pool derivedPool = TestUtil.createPool(owner, product, 1);
derivedPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool.setConsumed(3L);
derivedPool.setId("derivedPool");
Entitlement masterEnt = new Entitlement(pool, consumer, owner, 5);
Entitlement derivedEnt = new Entitlement(derivedPool, consumer, owner, 1);
derivedEnt.setId("1");
Entitlement derivedEnt2 = new Entitlement(derivedPool, consumer, owner, 1);
derivedEnt2.setId("2");
final Pool derivedPool2 = TestUtil.createPool(owner, product, 1);
derivedPool2.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool2.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool2.setConsumed(2L);
derivedPool2.setId("derivedPool2");
Entitlement derivedEnt3 = new Entitlement(derivedPool2, consumer, owner, 1);
derivedEnt3.setId("3");
Set<Entitlement> ents = new HashSet<>();
ents.add(derivedEnt);
ents.add(derivedEnt2);
derivedPool.setEntitlements(ents);
Set<Entitlement> ents2 = new HashSet<>();
ents2.add(derivedEnt3);
derivedPool2.setEntitlements(ents2);
Pool derivedPool3 = TestUtil.createPool(owner, product, 1);
derivedPool3.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool3.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool3.setConsumed(2L);
derivedPool3.setId("derivedPool3");
// before
assertEquals(3, derivedPool.getConsumed().intValue());
assertEquals(2, derivedPool2.getConsumed().intValue());
assertEquals(2, derivedPool3.getConsumed().intValue());
when(mockPoolCurator.lockAndLoad(pool)).thenReturn(pool);
when(enforcerMock.update(any(Consumer.class), any(Entitlement.class), any(Integer.class))).thenReturn(new ValidationResult());
when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(any(String.class), anyMap())).thenReturn(Arrays.asList(derivedPool, derivedPool2, derivedPool3));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool)))).thenReturn(Arrays.asList(derivedEnt, derivedEnt2));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool2)))).thenReturn(Arrays.asList(derivedEnt3));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(eq(Arrays.asList(derivedPool3)))).thenReturn(new ArrayList<>());
Collection<Pool> overPools = new ArrayList<Pool>() {
{
add(derivedPool);
add(derivedPool2);
}
};
when(mockPoolCurator.lockAndLoad(any(Collection.class))).thenReturn(overPools);
when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool);
when(mockPoolCurator.lockAndLoad(eq(derivedPool2))).thenReturn(derivedPool2);
when(mockPoolCurator.lockAndLoad(eq(derivedPool3))).thenReturn(derivedPool3);
pool.setId("masterpool");
manager.adjustEntitlementQuantity(consumer, masterEnt, 3);
Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class;
ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass);
verify(entitlementCurator).batchDelete(arg.capture());
List<Entitlement> entsDeleted = arg.getValue();
assertThat(entsDeleted, hasItems(derivedEnt, derivedEnt2, derivedEnt3));
assertEquals(1, derivedPool.getConsumed().intValue());
assertEquals(1, derivedPool2.getConsumed().intValue());
assertEquals(2, derivedPool3.getConsumed().intValue());
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class PoolManagerTest method testEntitleWithADate.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testEntitleWithADate() throws Exception {
Product product = TestUtil.createProduct();
List<Pool> pools = new ArrayList<>();
Pool pool1 = TestUtil.createPool(product);
pools.add(pool1);
Pool pool2 = TestUtil.createPool(product);
pools.add(pool2);
Date now = new Date();
ValidationResult result = mock(ValidationResult.class);
Page page = mock(Page.class);
when(page.getPageData()).thenReturn(pools);
when(mockPoolCurator.listAvailableEntitlementPools(any(Consumer.class), any(String.class), any(String.class), any(String.class), eq(now), any(PoolFilterBuilder.class), any(PageRequest.class), anyBoolean(), anyBoolean(), anyBoolean(), any(Date.class))).thenReturn(page);
CandlepinQuery mockQuery = mock(CandlepinQuery.class);
when(mockPoolCurator.listAllByIds(any(List.class))).thenReturn(mockQuery);
when(mockQuery.iterator()).thenReturn(Arrays.asList(pool1).listIterator());
when(enforcerMock.preEntitlement(any(Consumer.class), any(Pool.class), anyInt(), any(CallerType.class))).thenReturn(result);
when(result.isSuccessful()).thenReturn(true);
List<PoolQuantity> bestPools = new ArrayList<>();
bestPools.add(new PoolQuantity(pool1, 1));
when(autobindRules.selectBestPools(any(Consumer.class), any(String[].class), any(List.class), any(ComplianceStatus.class), any(String.class), any(Set.class), eq(false))).thenReturn(bestPools);
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
AutobindData data = AutobindData.create(consumer, owner).forProducts(new String[] { product.getUuid() }).on(now);
doNothing().when(mockPoolCurator).flush();
doNothing().when(mockPoolCurator).clear();
List<Entitlement> e = manager.entitleByProducts(data);
assertNotNull(e);
assertEquals(e.size(), 1);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class PoolManagerTest method testDeleteExcessEntitlements.
@Test
public void testDeleteExcessEntitlements() throws EntitlementRefusedException {
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
Subscription sub = TestUtil.createSubscription(owner, product);
sub.setId("testing-subid");
pool.setSourceSubscription(new SourceSubscription(sub.getId(), "master"));
Pool derivedPool = TestUtil.createPool(owner, product, 1);
derivedPool.setAttribute(Pool.Attributes.DERIVED_POOL, "true");
derivedPool.setSourceSubscription(new SourceSubscription(sub.getId(), "der"));
derivedPool.setConsumed(3L);
derivedPool.setId("derivedPool");
Entitlement masterEnt = new Entitlement(pool, consumer, owner, 5);
Entitlement derivedEnt = new Entitlement(derivedPool, consumer, owner, 1);
derivedEnt.setId("1");
Set<Entitlement> ents = new HashSet<>();
ents.add(derivedEnt);
derivedPool.setEntitlements(ents);
// before
assertEquals(3, derivedPool.getConsumed().intValue());
assertEquals(1, derivedPool.getEntitlements().size());
Collection<Pool> overPools = Collections.singletonList(derivedPool);
when(mockPoolCurator.lockAndLoad(any(Collection.class))).thenReturn(overPools);
when(mockPoolCurator.lockAndLoad(pool)).thenReturn(pool);
when(enforcerMock.update(any(Consumer.class), any(Entitlement.class), any(Integer.class))).thenReturn(new ValidationResult());
when(mockPoolCurator.lookupOversubscribedBySubscriptionIds(any(String.class), anyMap())).thenReturn(Collections.singletonList(derivedPool));
when(mockPoolCurator.retrieveOrderedEntitlementsOf(anyListOf(Pool.class))).thenReturn(Collections.singletonList(derivedEnt));
when(mockPoolCurator.lockAndLoad(eq(derivedPool))).thenReturn(derivedPool);
pool.setId("masterpool");
manager.adjustEntitlementQuantity(consumer, masterEnt, 3);
Class<List<Entitlement>> listClass = (Class<List<Entitlement>>) (Class) ArrayList.class;
ArgumentCaptor<List<Entitlement>> arg = ArgumentCaptor.forClass(listClass);
verify(entitlementCurator).batchDelete(arg.capture());
List<Entitlement> entsDeleted = arg.getValue();
assertThat(entsDeleted, hasItem(derivedEnt));
assertEquals(2, derivedPool.getConsumed().intValue());
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerCuratorPermissionsTest method setUpTestObjects.
@Before
public void setUpTestObjects() {
owner = new Owner("Example Corporation");
ownerCurator.create(owner);
consumerType = new ConsumerType(CONSUMER_TYPE_NAME);
consumerTypeCurator.create(consumerType);
}
Aggregations