use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ExporterTest method exportIdentityCertificate.
@Test
public void exportIdentityCertificate() throws Exception {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
Rules mrules = mock(Rules.class);
Consumer consumer = mock(Consumer.class);
Principal principal = mock(Principal.class);
when(mrules.getRules()).thenReturn("foobar");
when(pki.getSHA256WithRSAHash(any(InputStream.class))).thenReturn("signature".getBytes());
when(rc.getRules()).thenReturn(mrules);
when(pprov.get()).thenReturn(principal);
when(principal.getUsername()).thenReturn("testUser");
// specific to this test
IdentityCertificate idcert = new IdentityCertificate();
idcert.setSerial(new CertificateSerial(10L, new Date()));
idcert.setKey("euh0876puhapodifbvj094");
idcert.setCert("hpj-08ha-w4gpoknpon*)&^%#");
idcert.setCreated(new Date());
idcert.setUpdated(new Date());
when(consumer.getIdCert()).thenReturn(idcert);
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
CandlepinQuery cqmock = mock(CandlepinQuery.class);
when(cqmock.iterator()).thenReturn(Arrays.asList(new ConsumerType("system")).iterator());
when(ctc.listAll()).thenReturn(cqmock);
CandlepinQuery emptyIteratorMock = mock(CandlepinQuery.class);
when(emptyIteratorMock.iterate()).thenReturn(new MockResultIterator(Arrays.asList().iterator()));
when(emptyIteratorMock.iterator()).thenReturn(Arrays.asList().iterator());
when(cdnc.listAll()).thenReturn(emptyIteratorMock);
// FINALLY test this badboy
Exporter e = new Exporter(ctc, oc, me, ce, cte, re, ece, ecsa, pe, psa, pce, ec, ee, pki, config, exportRules, pprov, dvc, dve, cdnc, cdne, pc, su, exportExtensionAdapter, translator);
File export = e.getFullExport(consumer);
// VERIFY
assertNotNull(export);
assertTrue(export.exists());
verifyContent(export, "export/upstream_consumer/10.pem", new VerifyIdentityCert("10.pem"));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class DatabaseTestFixture method createConsumerType.
protected ConsumerType createConsumerType(String label, boolean manifest) {
ConsumerType ctype = new ConsumerType(label);
ctype.setManifest(manifest);
return this.consumerTypeCurator.create(ctype);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class DatabaseTestFixture method createDistributor.
protected Consumer createDistributor(Owner owner) {
ConsumerType type = this.createConsumerType(true);
Consumer consumer = new Consumer("test-distributor", "test-user", owner, type);
return this.consumerCurator.create(consumer);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
if (source == null) {
throw new IllegalArgumentException("source is null");
}
if (dest == null) {
throw new IllegalArgumentException("destination is null");
}
dest.setUuid(source.getUuid()).setName(source.getName()).setContentAccessMode(source.getContentAccessMode());
// Process nested objects if we have a ModelTranslator to use to the translation...
if (translator != null) {
if (source.getOwnerId() != null) {
Owner owner = this.ownerCurator.findOwnerById(source.getOwnerId());
dest.setOwner(owner != null ? translator.translate(owner, OwnerDTO.class) : null);
}
// Temporary measure to maintain API compatibility
if (source.getTypeId() != null) {
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
} else {
dest.setType(null);
}
} else {
dest.setOwner(null);
dest.setType(null);
}
return dest;
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerTypeTranslatorTest method initSourceObject.
@Override
public ConsumerType initSourceObject() {
ConsumerType type = new ConsumerType();
type.setId("test_id");
type.setLabel("type_label");
type.setManifest(true);
return type;
}
Aggregations