@Test public void testSingle() throws IOException { DataPacketDto dataPacketDto = new DataPacketDto("test-data".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"); when(transaction.receive()).thenReturn(dataPacketDto.toDataPacket()).thenReturn(null); assertEquals(transactionCompletion, receiverSupplier.get().receiveFiles()); objectMapper.writeValue(expectedData, Arrays.asList(dataPacketDto)); assertEquals(expectedData.toString(), data.toString()); }
public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); }
SiteToSiteReceiver { public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } }
SiteToSiteReceiver { public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } SiteToSiteReceiver(SiteToSiteClient siteToSiteClient, OutputStream output); }
SiteToSiteReceiver { public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } SiteToSiteReceiver(SiteToSiteClient siteToSiteClient, OutputStream output); TransactionCompletion receiveFiles(); }
SiteToSiteReceiver { public TransactionCompletion receiveFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.RECEIVE); JsonGenerator jsonGenerator = new JsonFactory().createJsonGenerator(output); jsonGenerator.writeStartArray(); DataPacket dataPacket; while ((dataPacket = transaction.receive()) != null) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("attributes"); jsonGenerator.writeStartObject(); Map<String, String> attributes = dataPacket.getAttributes(); if (attributes != null) { for (Map.Entry<String, String> stringStringEntry : attributes.entrySet()) { jsonGenerator.writeStringField(stringStringEntry.getKey(), stringStringEntry.getValue()); } } jsonGenerator.writeEndObject(); InputStream data = dataPacket.getData(); if (data != null) { jsonGenerator.writeBinaryField("data", IOUtils.toByteArray(data)); } jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.close(); transaction.confirm(); return transaction.complete(); } SiteToSiteReceiver(SiteToSiteClient siteToSiteClient, OutputStream output); TransactionCompletion receiveFiles();  }