Search in sources :

Example 31 with CandlepinQuery

use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.

the class ConsumerResourceTest method testFetchAllConsumersForSomeUUIDs.

@Test
public void testFetchAllConsumersForSomeUUIDs() {
    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<String> uuids = new ArrayList<>();
    uuids.add("swiftuuid");
    List<ConsumerDTO> result = cr.list(null, null, null, uuids, null, null, null).list();
    assertEquals(consumers, result);
}
Also used : Owner(org.candlepin.model.Owner) ArrayList(java.util.ArrayList) CandlepinQuery(org.candlepin.model.CandlepinQuery) Matchers.anyString(org.mockito.Matchers.anyString) ConsumerTypeValidator(org.candlepin.resource.util.ConsumerTypeValidator) Consumer(org.candlepin.model.Consumer) ConsumerDTO(org.candlepin.dto.api.v1.ConsumerDTO) ArrayList(java.util.ArrayList) List(java.util.List) ModelTranslator(org.candlepin.dto.ModelTranslator) ConsumerType(org.candlepin.model.ConsumerType) Test(org.junit.Test)

Example 32 with CandlepinQuery

use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.

the class ContentResourceTest method getContent.

@Test
public void getContent() {
    Owner owner = mock(Owner.class);
    Content content = mock(Content.class);
    CandlepinQuery cqmock = mock(CandlepinQuery.class);
    ContentDTO expected = this.modelTranslator.translate(content, ContentDTO.class);
    when(cqmock.list()).thenReturn(Arrays.asList(owner));
    when(oc.listAll()).thenReturn(cqmock);
    when(cc.lookupByUuid(eq("10"))).thenReturn(content);
    ContentDTO output = cr.getContent("10");
    assertEquals(expected, output);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) Content(org.candlepin.model.Content) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) Test(org.junit.Test)

Example 33 with CandlepinQuery

use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.

the class EventResourceTest method testListEvents.

@Test
public void testListEvents() {
    EventResource er = new EventResource(ec, null, injector.getInstance(EventAdapter.class), translator);
    CandlepinQuery cpQueryMock = mock(CandlepinQuery.class);
    List<Event> events = new ArrayList<>();
    events.add(getEvent());
    List<EventDTO> eventDTOs = new ArrayList<>();
    eventDTOs.add(getEventDTO());
    when(ec.listAll()).thenReturn(cpQueryMock);
    when(cpQueryMock.list()).thenReturn(events);
    when(translator.translate(any(Event.class), any(Class.class))).thenReturn(getEventDTO());
    assertEquals(eventDTOs, er.listEvents());
}
Also used : ArrayList(java.util.ArrayList) EventDTO(org.candlepin.dto.api.v1.EventDTO) Event(org.candlepin.audit.Event) CandlepinQuery(org.candlepin.model.CandlepinQuery) EventAdapter(org.candlepin.audit.EventAdapter) Test(org.junit.Test)

Example 34 with CandlepinQuery

use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.

the class CertificateSerialResourceTest method listall.

@Test
public void listall() {
    CandlepinQuery cqmock = new EmptyCandlepinQuery();
    CertificateSerialCurator csc = mock(CertificateSerialCurator.class);
    when(csc.listAll()).thenReturn(cqmock);
    CertificateSerialResource csr = new CertificateSerialResource(csc, this.modelTranslator);
    CandlepinQuery<CertificateSerialDTO> result = csr.getCertificateSerials();
    assertNotNull(result);
    verify(csc, times(1)).listAll();
}
Also used : CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CandlepinQuery(org.candlepin.model.CandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) CertificateSerialCurator(org.candlepin.model.CertificateSerialCurator) Test(org.junit.Test)

Example 35 with CandlepinQuery

use of org.candlepin.model.CandlepinQuery in project candlepin by candlepin.

the class InstalledProductStatusCalculatorTest method mockConsumerEntitlements.

private void mockConsumerEntitlements(Consumer consumer, Collection<Entitlement> entitlements) {
    List<Entitlement> entList = new LinkedList(entitlements);
    CandlepinQuery mockCPQuery = mock(CandlepinQuery.class);
    when(mockCPQuery.list()).thenReturn(entList);
    when(mockCPQuery.iterator()).thenReturn(entitlements.iterator());
    when(entCurator.listByConsumer(eq(consumer))).thenReturn(entList);
    when(entCurator.listByConsumerAndDate(eq(consumer), any(Date.class))).thenReturn(mockCPQuery);
}
Also used : CandlepinQuery(org.candlepin.model.CandlepinQuery) Entitlement(org.candlepin.model.Entitlement) LinkedList(java.util.LinkedList) Date(java.util.Date)

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