use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class OwnerResourceTest method consumerCanListConsumersByIdWhenOtherParametersPresent.
@Test
public void consumerCanListConsumersByIdWhenOtherParametersPresent() {
Consumer c = createConsumer(owner);
List<String> uuids = new ArrayList<>();
uuids.add(c.getUuid());
setupPrincipal(owner, Access.ALL);
securityInterceptor.enable();
Set<String> types = new HashSet<>();
types.add("type");
consumerTypeCurator.create(new ConsumerType("type"));
CandlepinQuery<ConsumerDTO> result = ownerResource.listConsumers(owner.getKey(), "username", types, uuids, null, null, null, null, null, new PageRequest());
assertNotNull(result);
List<ConsumerDTO> consumers = result.list();
assertEquals(0, consumers.size());
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class EntitlementImporterTest method init.
@Before
public void init() {
this.owner = new Owner();
this.translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator);
i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
this.importer = new EntitlementImporter(certSerialCurator, cdnCurator, i18n, mockProductCurator, ec, translator);
ConsumerType ctype = TestUtil.createConsumerType();
ctype.setId("test-ctype");
consumer = TestUtil.createConsumer(ctype, owner);
consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
consumerDTO.setUrlWeb("");
consumerDTO.setUrlApi("");
when(this.mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype);
when(this.mockConsumerTypeCurator.find(eq(ctype.getId()))).thenReturn(ctype);
cert = createEntitlementCertificate("my-test-key", "my-cert");
cert.setId("test-id");
reader = mock(Reader.class);
meta = new Meta();
meta.setCdnLabel("test-cdn");
testCdn = new Cdn("test-cdn", "Test CDN", "https://test.url.com");
when(cdnCurator.lookupByLabel("test-cdn")).thenReturn(testCdn);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithNullUuidOnOwnerShouldSetUuid.
@Test
public void importConsumerWithNullUuidOnOwnerShouldSetUuid() throws ImporterException {
OwnerDTO ownerDTO = mock(OwnerDTO.class);
Owner owner = mock(Owner.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(ownerDTO.getId()).thenReturn("test-owner-id");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(), idCert);
// now verify that the owner has the upstream consumer set
ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
verify(owner).setUpstreamConsumer(arg.capture());
assertEquals("test-uuid", arg.getValue().getUuid());
verify(curator).merge(owner);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithSameUuidOnAnotherOwnerShouldThrowException.
@Test(expected = SyncDataFormatException.class)
public void importConsumerWithSameUuidOnAnotherOwnerShouldThrowException() throws ImporterException {
Owner owner = new Owner();
UpstreamConsumer uc = new UpstreamConsumer("test-uuid");
owner.setUpstreamConsumer(uc);
ConsumerDTO consumer = new ConsumerDTO();
consumer.setUuid("test-uuid");
Owner anotherOwner = new Owner("other", "Other");
anotherOwner.setId("blah");
anotherOwner.setUpstreamConsumer(uc);
when(curator.lookupWithUpstreamUuid(consumer.getUuid())).thenReturn(anotherOwner);
importer.store(owner, consumer, new ConflictOverrides(), null);
}
use of org.candlepin.dto.api.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldThrowException.
@Test
public void importConsumerWithMismatchedUuidShouldThrowException() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
try {
importer.store(owner, consumer, new ConflictOverrides(), null);
fail();
} catch (ImportConflictException e) {
assertFalse(e.message().getConflicts().isEmpty());
assertTrue(e.message().getConflicts().contains(Importer.Conflict.DISTRIBUTOR_CONFLICT));
}
}
Aggregations