Search in sources :

Example 41 with CandlepinQuery

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));
}
Also used : PoolQuantity(org.candlepin.model.PoolQuantity) Set(java.util.Set) HashSet(java.util.HashSet) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ArrayList(java.util.ArrayList) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Product(org.candlepin.model.Product) Page(org.candlepin.common.paging.Page) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) CallerType(org.candlepin.policy.js.entitlement.Enforcer.CallerType) ValidationResult(org.candlepin.policy.ValidationResult) Date(java.util.Date) PageRequest(org.candlepin.common.paging.PageRequest) Consumer(org.candlepin.model.Consumer) PoolFilterBuilder(org.candlepin.model.PoolFilterBuilder) Pool(org.candlepin.model.Pool) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Matchers.anyList(org.mockito.Matchers.anyList) AutobindData(org.candlepin.resource.dto.AutobindData) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 42 with CandlepinQuery

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));
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) Pool(org.candlepin.model.Pool) CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 43 with CandlepinQuery

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());
}
Also used : Event(org.candlepin.audit.Event) CandlepinQuery(org.candlepin.model.CandlepinQuery) Feed(org.jboss.resteasy.plugins.providers.atom.Feed) Test(org.junit.Test)

Example 44 with CandlepinQuery

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());
}
Also used : CertificateSerial(org.candlepin.model.CertificateSerial) CandlepinQuery(org.candlepin.model.CandlepinQuery) File(java.io.File) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 45 with CandlepinQuery

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);
}
Also used : CertificateSerial(org.candlepin.model.CertificateSerial) CandlepinQuery(org.candlepin.model.CandlepinQuery) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

CandlepinQuery (org.candlepin.model.CandlepinQuery)50 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)25 Date (java.util.Date)21 Consumer (org.candlepin.model.Consumer)20 Entitlement (org.candlepin.model.Entitlement)14 Owner (org.candlepin.model.Owner)14 Pool (org.candlepin.model.Pool)14 ConsumerType (org.candlepin.model.ConsumerType)12 Product (org.candlepin.model.Product)11 List (java.util.List)10 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)10 MockResultIterator (org.candlepin.test.MockResultIterator)10 LinkedList (java.util.LinkedList)9 CertificateSerial (org.candlepin.model.CertificateSerial)9 InputStream (java.io.InputStream)8 HashSet (java.util.HashSet)8 Rules (org.candlepin.model.Rules)8 Matchers.anyString (org.mockito.Matchers.anyString)8 File (java.io.File)7