use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class Exporter method exportDistributorVersions.
private void exportDistributorVersions(File baseDir) throws IOException {
List<DistributorVersion> versions = distVerCurator.findAll();
if (versions == null || versions.isEmpty()) {
return;
}
File distVerDir = new File(baseDir.getCanonicalPath(), "distributor_version");
distVerDir.mkdir();
FileWriter writer = null;
for (DistributorVersion dv : versions) {
if (log.isDebugEnabled()) {
log.debug("Exporting Distributor Version" + dv.getName());
}
try {
File file = new File(distVerDir.getCanonicalPath(), dv.getName() + ".json");
writer = new FileWriter(file);
distVerExporter.export(mapper, writer, dv);
} finally {
if (writer != null) {
writer.close();
}
}
}
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class ImporterTest method createTestDistributerVersion.
private DistributorVersion createTestDistributerVersion() {
DistributorVersion dVersion = new DistributorVersion("test-dist-ver");
Set<DistributorVersionCapability> capabilities = new HashSet<>();
capabilities.add(new DistributorVersionCapability(null, "capability-1"));
capabilities.add(new DistributorVersionCapability(null, "capability-2"));
capabilities.add(new DistributorVersionCapability(null, "capability-3"));
dVersion.setCapabilities(capabilities);
return dVersion;
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class ExporterTest method exportDistributorVersions.
@Test
public void exportDistributorVersions() throws ExportCreationException, IOException {
config.setProperty(ConfigProperties.SYNC_WORK_DIR, "/tmp/");
config.setProperty(ConfigProperties.PREFIX_WEBURL, "localhost:8443/weburl");
config.setProperty(ConfigProperties.PREFIX_APIURL, "localhost:8443/apiurl");
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");
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);
ConsumerType ctype = new ConsumerType(ConsumerTypeEnum.CANDLEPIN);
ctype.setId("test-ctype");
KeyPair keyPair = createKeyPair();
when(consumer.getKeyPair()).thenReturn(keyPair);
when(pki.getPemEncoded(keyPair.getPrivateKey())).thenReturn("privateKey".getBytes());
when(pki.getPemEncoded(keyPair.getPublicKey())).thenReturn("publicKey".getBytes());
when(consumer.getUuid()).thenReturn("8auuid");
when(consumer.getName()).thenReturn("consumer_name");
when(consumer.getTypeId()).thenReturn(ctype.getId());
when(ctc.getConsumerType(eq(consumer))).thenReturn(ctype);
when(ctc.find(eq(ctype.getId()))).thenReturn(ctype);
DistributorVersion dv = new DistributorVersion("test-dist-ver");
Set<DistributorVersionCapability> dvcSet = new HashSet<>();
dvcSet.add(new DistributorVersionCapability(dv, "capability-1"));
dvcSet.add(new DistributorVersionCapability(dv, "capability-2"));
dvcSet.add(new DistributorVersionCapability(dv, "capability-3"));
dv.setCapabilities(dvcSet);
List<DistributorVersion> dvList = new ArrayList<>();
dvList.add(dv);
when(dvc.findAll()).thenReturn(dvList);
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);
when(ctc.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);
verifyContent(export, "export/distributor_version/test-dist-ver.json", new VerifyDistributorVersion("test-dist-ver.json"));
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class Importer method importDistributorVersions.
protected void importDistributorVersions(File[] versionFiles) throws IOException {
DistributorVersionImporter importer = new DistributorVersionImporter(distVerCurator);
Set<DistributorVersion> distVers = new HashSet<>();
for (File verFile : versionFiles) {
Reader reader = null;
try {
reader = new FileReader(verFile);
distVers.add(importer.createObject(mapper, reader));
} finally {
if (reader != null) {
reader.close();
}
}
}
importer.store(distVers);
}
use of org.candlepin.model.DistributorVersion in project candlepin by candlepin.
the class ImporterTest method importDistributorVersionUpdate.
@Test
public void importDistributorVersionUpdate() throws Exception {
DistributorVersionCurator dvc = mock(DistributorVersionCurator.class);
Importer i = new Importer(null, null, null, null, null, null, null, null, null, null, null, null, i18n, dvc, null, su, null, this.mockSubReconciler, this.ec, this.translator);
when(dvc.findByName("test-dist-ver")).thenReturn(new DistributorVersion("test-dist-ver"));
File[] distVer = new File[1];
distVer[0] = new File(folder.getRoot(), "dist-ver.json");
mapper.writeValue(distVer[0], createTestDistributerVersion());
i.importDistributorVersions(distVer);
verify(dvc, never()).create(any(DistributorVersion.class));
verify(dvc).merge(any(DistributorVersion.class));
}
Aggregations