ConsumerExporter { 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); } @Inject  ConsumerExporter(ModelTranslator translator);   }
@Test public void testConsumerExport() throws IOException { ObjectMapper mapper = TestSyncUtils .getTestSyncUtils(new MapConfiguration(new HashMap<String, String>() { { put(ConfigProperties.FAIL_ON_UNKNOWN_IMPORT_PROPERTIES, "false"); } })); translator = new StandardTranslator(mockConsumerTypeCurator, mockEnvironmentCurator, ownerCurator); ConsumerExporter exporter = new ConsumerExporter(translator); ConsumerType ctype = new ConsumerType("candlepin"); ctype.setId("8888"); ctype.setManifest(true); StringWriter writer = new StringWriter(); Consumer consumer = new Consumer().setUuid("test-uuid"); consumer.setName("testy consumer"); consumer.setType(ctype); consumer.setContentAccessMode("access_mode"); when(mockConsumerTypeCurator.getConsumerType(eq(consumer))).thenReturn(ctype); exporter.export(mapper, writer, consumer, "/subscriptions", "/candlepin"); StringBuffer json = new StringBuffer(); json.append("{\"uuid\":\"").append(consumer.getUuid()).append("\","); json.append("\"name\":\"").append(consumer.getName()).append("\","); json.append("\"type\":"); json.append("{\"id\":\"").append(ctype.getId()).append("\","); json.append("\"label\":\"").append(ctype.getLabel()).append("\","); json.append("\"manifest\":").append(ctype.isManifest()).append("},"); json.append("\"owner\":null,"); json.append("\"urlWeb\":\"/subscriptions\","); json.append("\"urlApi\":\"/candlepin\","); json.append("\"contentAccessMode\":\"access_mode\"}"); assertTrue(TestUtil.isJsonEqual(json.toString(), writer.toString()), json.toString() + "\n" + writer.toString()); json = new StringBuffer(); json.append("{\"uuid\":\"").append(consumer.getUuid()).append("\","); json.append("\"type\":"); json.append("{\"id\":\"").append(ctype.getId()).append("\","); json.append("\"label\":\"").append(ctype.getLabel()).append("\","); json.append("\"manifest\":").append(ctype.isManifest()).append("},"); json.append("\"owner\":null,"); json.append("\"name\":\"").append(consumer.getName()).append("\","); json.append("\"urlApi\":\"/candlepin\","); json.append("\"urlWeb\":\"/subscriptions\","); json.append("\"contentAccessMode\":\"access_mode\"}"); assertTrue(TestUtil.isJsonEqual(json.toString(), writer.toString())); }