From c568defc1ed99fad87d00fff4273309203f03359 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Wed, 20 Sep 2017 08:16:00 +0200
Subject: [PATCH] [fix] Fix SYnchroResult deserialization, to get synchro with
 valid last execution time

---
 .../elasticsearch/model/SynchroResult.java    | 13 +++++++
 .../model/SynchroExecutionTest.java           | 37 +++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 duniter4j-es-core/src/test/java/org/duniter/elasticsearch/model/SynchroExecutionTest.java

diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java
index de746186..79e11851 100644
--- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java
+++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/model/SynchroResult.java
@@ -99,6 +99,7 @@ public class SynchroResult implements Serializable {
         return deleteTotal;
     }
 
+
     public long getInvalidSignatures() {
         return invalidSignatureTotal;
     }
@@ -108,6 +109,18 @@ public class SynchroResult implements Serializable {
         return insertTotal + updateTotal + deleteTotal;
     }
 
+    public void setInserts(long inserts) {
+        this.insertTotal = inserts;
+    }
+    public void setDeletes(long deletes) {
+        this.deleteTotal = deletes;
+    }
+    public void setUpdates(long updates) {
+        this.updateTotal = updates;
+    }
+    public void setInvalidSignatures(long invalidSignatures) {
+        this.invalidSignatureTotal = invalidSignatures;
+    }
 
     public String toString() {
         return new StringBuilder()
diff --git a/duniter4j-es-core/src/test/java/org/duniter/elasticsearch/model/SynchroExecutionTest.java b/duniter4j-es-core/src/test/java/org/duniter/elasticsearch/model/SynchroExecutionTest.java
new file mode 100644
index 00000000..4afd4e11
--- /dev/null
+++ b/duniter4j-es-core/src/test/java/org/duniter/elasticsearch/model/SynchroExecutionTest.java
@@ -0,0 +1,37 @@
+package org.duniter.elasticsearch.model;
+
+import org.duniter.core.client.model.bma.jackson.JacksonUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+
+public class SynchroExecutionTest {
+
+    @Test
+    public void deserialize() {
+        String json = "{\n" +
+                "        \"issuer\" : null,\n" +
+                "        \"hash\" : null,\n" +
+                "        \"signature\" : null,\n" +
+                "        \"time\" : 1505836503,\n" +
+                "        \"currency\" : \"g1\",\n" +
+                "        \"peer\" : \"CA99448CDD90AB3772474A4CBCCC5A392F4E9AD3F9FA1C4018C6FB432BC04BA8\",\n" +
+                "        \"result\" : {\n" +
+                "          \"inserts\" : 2,\n" +
+                "          \"updates\" : 0,\n" +
+                "          \"invalidSignatures\" : 0,\n" +
+                "          \"deletes\" : 0\n" +
+                "        }\n" +
+                "      }";
+
+        try {
+            SynchroExecution obj = JacksonUtils.getThreadObjectMapper().readValue(json, SynchroExecution.class);
+            Assert.assertNotNull(obj);
+        }
+        catch(IOException e) {
+            Assert.fail(e.getMessage());
+        }
+    }
+}
-- 
GitLab