use of org.candlepin.dto.rules.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.rules.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.rules.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));
}
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class Importer method importConsumer.
protected ConsumerDTO importConsumer(Owner owner, File consumerFile, File[] upstreamConsumer, ConflictOverrides forcedConflicts, Meta meta) throws IOException, SyncDataFormatException {
IdentityCertificate idcert = null;
for (File uc : upstreamConsumer) {
if (uc.getName().endsWith(".json")) {
log.debug("Import upstream consumeridentity certificate: {}", uc.getName());
try (Reader reader = new FileReader(uc)) {
CertificateDTO dtoCert = mapper.readValue(reader, CertificateDTO.class);
idcert = new IdentityCertificate();
populateEntity(idcert, dtoCert);
}
} else {
log.warn("Extra file found in upstream_consumer directory: {}", uc.getName());
}
}
ConsumerImporter importer = new ConsumerImporter(ownerCurator, idCertCurator, i18n, csCurator);
Reader reader = null;
ConsumerDTO consumer = null;
try {
reader = new FileReader(consumerFile);
consumer = importer.createObject(mapper, reader);
// we can not rely on the actual ConsumerType in the ConsumerDto
// because it could have an id not in our database. We need to
// stick with the label. Hence we need to lookup the ACTUAL type
// by label here before attempting to store the UpstreamConsumer
ConsumerType type = consumerTypeCurator.lookupByLabel(consumer.getType().getLabel());
consumer.setType(this.translator.translate(type, ConsumerTypeDTO.class));
// the metadata
if (StringUtils.isEmpty(consumer.getUrlWeb())) {
consumer.setUrlWeb(meta.getWebAppPrefix());
}
importer.store(owner, consumer, forcedConflicts, idcert);
} finally {
if (reader != null) {
reader.close();
}
}
return consumer;
}
use of org.candlepin.dto.rules.v1.ConsumerDTO in project candlepin by candlepin.
the class ConsumerExporter method export.
void export(ObjectMapper mapper, Writer writer, Consumer consumer, String weburl, String apiurl) throws IOException {
ConsumerDTO consumerDTO = this.translator.translate(consumer, ConsumerDTO.class);
consumerDTO.setUrlApi(apiurl);
consumerDTO.setUrlWeb(weburl);
mapper.writeValue(writer, consumerDTO);
}
Aggregations