use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class PoolManagerTest method testEntitleByProductsEmptyArray.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testEntitleByProductsEmptyArray() throws Exception {
Product product = TestUtil.createProduct();
List<Pool> pools = new ArrayList<>();
Pool pool1 = TestUtil.createPool(product);
pools.add(pool1);
Date now = new Date();
ValidationResult result = mock(ValidationResult.class);
// Setup an installed product for the consumer, we'll make the bind request
// with no products specified, so this should get used instead:
String[] installedPids = new String[] { product.getUuid() };
ComplianceStatus mockCompliance = new ComplianceStatus(now);
mockCompliance.addNonCompliantProduct(installedPids[0]);
when(complianceRules.getStatus(any(Consumer.class), any(Date.class), any(Boolean.class))).thenReturn(mockCompliance);
Page page = mock(Page.class);
when(page.getPageData()).thenReturn(pools);
when(mockPoolCurator.listAvailableEntitlementPools(any(Consumer.class), any(String.class), anyString(), anyString(), 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);
// Make the call but provide a null array of product IDs (simulates healing):
ConsumerType ctype = this.mockConsumerType(TestUtil.createConsumerType());
Consumer consumer = TestUtil.createConsumer(ctype, owner);
AutobindData data = AutobindData.create(consumer, owner).on(now);
manager.entitleByProducts(data);
verify(autobindRules).selectBestPools(any(Consumer.class), eq(installedPids), any(List.class), eq(mockCompliance), any(String.class), any(Set.class), eq(false));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class EntitlerTest method testUnmappedGuestRevocation.
@Test
public void testUnmappedGuestRevocation() throws Exception {
Owner owner1 = new Owner("o1");
Owner owner2 = new Owner("o2");
Product product1 = TestUtil.createProduct();
Product product2 = TestUtil.createProduct();
Pool p1 = TestUtil.createPool(owner1, product1);
Pool p2 = TestUtil.createPool(owner2, product2);
p1.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
p2.setAttribute(Pool.Attributes.UNMAPPED_GUESTS_ONLY, "true");
Date thirtySixHoursAgo = new Date(new Date().getTime() - 36L * 60L * 60L * 1000L);
Date twelveHoursAgo = new Date(new Date().getTime() - 12L * 60L * 60L * 1000L);
Consumer c;
c = TestUtil.createConsumer(owner1);
c.setCreated(twelveHoursAgo);
Entitlement e1 = TestUtil.createEntitlement(owner1, c, p1, null);
e1.setEndDateOverride(new Date(new Date().getTime() + 1L * 60L * 60L * 1000L));
Set<Entitlement> entitlementSet1 = new HashSet<>();
entitlementSet1.add(e1);
p1.setEntitlements(entitlementSet1);
c = TestUtil.createConsumer(owner2);
c.setCreated(twelveHoursAgo);
Entitlement e2 = TestUtil.createEntitlement(owner2, c, p2, null);
e2.setEndDateOverride(thirtySixHoursAgo);
Set<Entitlement> entitlementSet2 = new HashSet<>();
entitlementSet2.add(e2);
p2.setEntitlements(entitlementSet2);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(e1, e2).iterator());
when(entitlementCurator.findByPoolAttribute(eq("unmapped_guests_only"), eq("true"))).thenReturn(cqmock);
int total = entitler.revokeUnmappedGuestEntitlements();
assertEquals(1, total);
verify(pm).revokeEntitlements(Arrays.asList(e2));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class AtomFeedResourceTest method getFeed.
@Test
public void getFeed() {
CandlepinQuery cqmock = mock(CandlepinQuery.class);
List<Event> events = getEvents(10);
when(cqmock.list()).thenReturn(events);
when(ec.listMostRecent(eq(1000))).thenReturn(cqmock);
Feed f = afr.getFeed();
assertNotNull(f);
assertEquals(10, f.getEntries().size());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class CrlResourceTest method testUnrevokeWithArguments.
@Test
@SuppressWarnings("unchecked")
public void testUnrevokeWithArguments() throws Exception {
String[] input = new String[] { "123", "456", "789" };
CandlepinQuery cqmock = mock(CandlepinQuery.class);
List<CertificateSerial> serials = new LinkedList<>();
serials.add(new CertificateSerial(123L));
serials.add(new CertificateSerial(456L));
serials.add(new CertificateSerial(789L));
when(cqmock.iterator()).thenReturn(serials.iterator());
when(this.certSerialCurator.listBySerialIds(eq(input))).thenReturn(cqmock);
this.resource.unrevoke(input);
verify(crlFileUtil).updateCRLFile(any(File.class), anyCollection(), anyCollection());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class CrlResourceTest method testUnrevokeWithNoArguments.
@Test
@SuppressWarnings("unchecked")
public void testUnrevokeWithNoArguments() throws Exception {
String[] input = new String[] {};
CandlepinQuery cqmock = mock(CandlepinQuery.class);
List<CertificateSerial> serials = new LinkedList<>();
when(cqmock.iterator()).thenReturn(serials.iterator());
when(this.certSerialCurator.listBySerialIds(eq(input))).thenReturn(cqmock);
this.resource.unrevoke(input);
verifyNoMoreInteractions(crlFileUtil);
}
Aggregations