public void verify(ZipInputStream zis, byte[] buf) throws IOException { OutputStream os = new FileOutputStream("/tmp/" + filename); int n; while ((n = zis.read(buf, 0, 1024)) > -1) { os.write(buf, 0, n); } os.flush(); os.close(); ObjectMapper om = SyncUtils.getObjectMapper( new MapConfiguration( new HashMap<String, String>() { { put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false"); } })); ConsumerDto c = om.readValue(new FileInputStream("/tmp/" + filename), ConsumerDto.class); assertEquals("localhost:8443/apiurl", c.getUrlApi()); assertEquals("localhost:8443/weburl", c.getUrlWeb()); assertEquals("8auuid", c.getUuid()); assertEquals("consumer_name", c.getName()); assertEquals(new ConsumerType(ConsumerTypeEnum.CANDLEPIN), c.getType()); }
public void store(Owner owner, ConsumerDto consumer, ConflictOverrides forcedConflicts) throws SyncDataFormatException { if (consumer.getUuid() == null) { throw new SyncDataFormatException(i18n.tr("No ID for upstream distributor")); } // Make sure no other owner is already using this upstream UUID: Owner alreadyUsing = curator.lookupWithUpstreamUuid(consumer.getUuid()); if (alreadyUsing != null && !alreadyUsing.getKey().equals(owner.getKey())) { log.error("Cannot import manifest for org: " + owner.getKey()); log.error( "Upstream distributor " + consumer.getUuid() + " already in use by org: " + alreadyUsing.getKey()); // NOTE: this is not a conflict that can be overridden because we simply don't // allow two orgs to use the same manifest at once. The other org would have to // delete their manifest after which it could be used elsewhere. throw new SyncDataFormatException( i18n.tr("This distributor has already been imported by another owner")); } if (owner.getUpstreamUuid() != null && !owner.getUpstreamUuid().equals(consumer.getUuid())) { if (!forcedConflicts.isForced(Importer.Conflict.DISTRIBUTOR_CONFLICT)) { throw new ImportConflictException( i18n.tr("Owner has already imported from another distributor"), Importer.Conflict.DISTRIBUTOR_CONFLICT); } else { log.warn("Forcing import from a new distributor for org: " + owner.getKey()); log.warn("Old distributor UUID: " + owner.getUpstreamUuid()); log.warn("New distributor UUID: " + consumer.getUuid()); } } owner.setUpstreamUuid(consumer.getUuid()); curator.merge(owner); }