use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ConsumerResourceTest method testFetchAllConsumersForOwner.
public void testFetchAllConsumersForOwner() {
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, mockOwnerCurator, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
ArrayList<Consumer> consumers = new ArrayList<>();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(consumers);
when(cqmock.iterator()).thenReturn(consumers.iterator());
when(mockOwnerCurator.lookupByKey(eq("taylorOwner"))).thenReturn(new Owner());
when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
List<ConsumerDTO> result = cr.list(null, null, "taylorOwner", null, null, null, null).list();
assertEquals(consumers, result);
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ConsumerResourceTest method testGetComplianceStatusList.
@Test
public void testGetComplianceStatusList() {
Owner owner = this.createOwner();
Consumer c = this.createConsumer(owner);
Consumer c2 = this.createConsumer(owner);
List<Consumer> consumers = new ArrayList<>();
consumers.add(c);
consumers.add(c2);
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(consumers);
when(cqmock.iterator()).thenReturn(consumers.iterator());
List<String> uuids = new ArrayList<>();
uuids.add(c.getUuid());
uuids.add(c2.getUuid());
when(mockConsumerCurator.findByUuids(eq(uuids))).thenReturn(cqmock);
ComplianceStatus status = new ComplianceStatus();
when(mockComplianceRules.getStatus(any(Consumer.class), any(Date.class))).thenReturn(status);
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, null, null, null, mockComplianceRules, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
Map<String, ComplianceStatus> results = cr.getComplianceStatusList(uuids);
assertEquals(2, results.size());
assertTrue(results.containsKey(c.getUuid()));
assertTrue(results.containsKey(c2.getUuid()));
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class ConsumerResourceTest method testFetchAllConsumersForUser.
@Test
public void testFetchAllConsumersForUser() {
ModelTranslator mockTranslator = mock(ModelTranslator.class);
ConsumerResource cr = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.config, null, null, null, null, null, null, this.factValidator, new ConsumerTypeValidator(null, null), consumerEnricher, migrationProvider, mockTranslator);
ArrayList<Consumer> consumers = new ArrayList<>();
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.list()).thenReturn(consumers);
when(cqmock.iterator()).thenReturn(consumers.iterator());
when(mockConsumerCurator.searchOwnerConsumers(any(Owner.class), anyString(), (java.util.Collection<ConsumerType>) any(Collection.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class), any(List.class))).thenReturn(cqmock);
when(mockTranslator.translateQuery(eq(cqmock), eq(ConsumerDTO.class))).thenReturn(cqmock);
List<ConsumerDTO> result = cr.list("TaylorSwift", null, null, null, null, null, null).list();
assertEquals(consumers, result);
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class EventResourceTest method listEventsNoEvents.
@Test
public void listEventsNoEvents() {
EventResource er = new EventResource(ec, null, injector.getInstance(EventAdapter.class), translator);
CandlepinQuery cpQueryMock = mock(CandlepinQuery.class);
when(ec.listAll()).thenReturn(cpQueryMock);
assertTrue(er.listEvents().isEmpty());
}
use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.
the class EntitlerJobTest method respondWithValidationErrors.
@Test
public void respondWithValidationErrors() throws JobExecutionException, EntitlementRefusedException {
PoolIdAndQuantity[] pQs = new PoolIdAndQuantity[1];
pQs[0] = new PoolIdAndQuantity("pool10", 1);
JobDetail detail = EntitlerJob.bindByPoolAndQuantities(consumer, owner.getKey(), pQs);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
HashMap<String, ValidationResult> mapResult = new HashMap<>();
ValidationResult result = new ValidationResult();
result.addError("rulefailed.no.entitlements.available");
mapResult.put("hello", result);
when(e.bindByPoolQuantities(eq(consumerUuid), anyMapOf(String.class, Integer.class))).thenThrow(new EntitlementRefusedException(mapResult));
EntitlerJob job = new EntitlerJob(e, null, pC, i18n);
injector.injectMembers(job);
Pool p = new Pool();
p.setId("hello");
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(p).iterator());
when(pC.listAllByIds(anyListOf(String.class))).thenReturn(cqmock);
job.execute(ctx);
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
verify(ctx).setResult(argumentCaptor.capture());
List<PoolIdAndErrors> resultErrors = (List<PoolIdAndErrors>) argumentCaptor.getValue();
assertEquals(1, resultErrors.size());
assertEquals("hello", resultErrors.get(0).getPoolId());
assertEquals(1, resultErrors.get(0).getErrors().size());
assertEquals("No subscriptions are available from the pool with ID \"hello\".", resultErrors.get(0).getErrors().get(0));
}
Aggregations