This is an automated email from the git hooks/post-receive script. New commit to branch feature/sync in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 7aee74f456fbabd342f9171a373f83427f0cef3c Author: servantie <servantie.c@gmail.com> Date: Tue Jun 21 10:27:46 2016 +0200 added a test for taskToJSONFormat --- .../java/org/chorem/jtimer/entities/TimerTask.java | 10 +++++ .../jtimer/ui/report/TimerTaskUpdaterView.java | 2 +- .../jtimer/entities/TimerTaskHelperTest.java | 47 ++++++++++++++++++++++ .../jtimer/io/GTimerIncrementalSaverTest.java | 2 +- src/test/resources/testdata/41.task | 8 ++++ src/test/resources/testdata/41.task.sync | 3 ++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/chorem/jtimer/entities/TimerTask.java b/src/main/java/org/chorem/jtimer/entities/TimerTask.java index be6b5c7..f782e55 100644 --- a/src/main/java/org/chorem/jtimer/entities/TimerTask.java +++ b/src/main/java/org/chorem/jtimer/entities/TimerTask.java @@ -313,6 +313,16 @@ public class TimerTask implements Cloneable, } /** + * Adds a new synchronization info with just url provided + * (default isActive = true and time is minimum) + * @param url a String + */ + public void addSyncInfo(String url) { + addSyncInfo(url, LocalDateTime.MIN, true); + } + + + /** * Removes a synchronisation info attached to a url if it exists * @param url : the url of the info to remove * diff --git a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java index bc20e94..3929948 100644 --- a/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java +++ b/src/main/java/org/chorem/jtimer/ui/report/TimerTaskUpdaterView.java @@ -562,7 +562,7 @@ public class TimerTaskUpdaterView extends FrameView implements DocumentListener, String urlToAdd = (String) urlComboBox.getSelectedItem(); if ((!urlToAdd.isEmpty()) && (!task.getSynchronizingURLList().contains(urlToAdd))) { urlComboBox.addItem(urlToAdd); - task.addSyncInfo(urlToAdd, LocalDateTime.MIN, true); + task.addSyncInfo(urlToAdd); core.getData().changeSyncInfo(task, urlToAdd); } if (lastUpdate != null) { diff --git a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java index 88eb68f..abd36ea 100644 --- a/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java +++ b/src/test/java/org/chorem/jtimer/entities/TimerTaskHelperTest.java @@ -21,10 +21,15 @@ */ package org.chorem.jtimer.entities; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import org.chorem.jtimer.AbstractJTimerTest; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -49,4 +54,46 @@ public class TimerTaskHelperTest extends AbstractJTimerTest { Assert.assertEquals(components.get(1), task1); Assert.assertEquals(components.get(2), task2); } + + /** + * Test json production + */ + @Test + public void taskToJSONFormatTest() { + TimerTask task = new TimerTask(); + task.setName("JsonBuilder Test"); + task.addSyncInfo("http://localhost:3000"); + //date : 2016-05-10 + task.setTime(new Date(1462831200000L), 452000L); + //date : 2016-05-12 + task.setTime(new Date(1463004000000L), 4533000L); + + //create json object list to get + List<JsonObject> listOfObjects = new ArrayList<>(); + + JsonObject objectToHave = new JsonObject(); + JsonArray periodArray = new JsonArray(); + JsonObject periodElement1 = new JsonObject(); + periodElement1.addProperty("id", "2016-05-10"); + periodElement1.addProperty("startDate", "2016-05-10T00:00:00+01:00"); + periodElement1.addProperty("duration", 452); + periodArray.add(periodElement1); + JsonObject periodElement2 = new JsonObject(); + periodElement2.addProperty("id", "2016-05-12"); + periodElement2.addProperty("startDate", "2016-05-12T00:00:00+01:00"); + periodElement2.addProperty("duration", 4533); + periodArray.add(periodElement2); + + objectToHave.addProperty("URL", "http://localhost:3000"); + objectToHave.addProperty("startDate", "2016-05-10T00:00:00+01:00"); + objectToHave.addProperty("endDate", "2016-05-20T00:00:00+01:00"); + objectToHave.add("periods", periodArray); + listOfObjects.add(objectToHave); + + + //make a list of json objects from the task + List<JsonObject> taskJsonList = TimerTaskHelper.taskToJSONFormat(task, new Date(1462831200000L), new Date(1463695200000L), false, "+01:00"); + //compare it + Assert.assertEquals(taskJsonList, listOfObjects); + } } diff --git a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java index 3a153a6..774776a 100644 --- a/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java +++ b/src/test/java/org/chorem/jtimer/io/GTimerIncrementalSaverTest.java @@ -88,7 +88,7 @@ public class GTimerIncrementalSaverTest extends AbstractJTimerTest { Assert.assertNotNull(projects); Assert.assertEquals(getProjectsCount(projects), 6); - Assert.assertEquals(getTasksCount(projects), 40); + Assert.assertEquals(getTasksCount(projects), 41); Assert.assertEquals(getAnnotationsCount(projects), 9); Assert.assertEquals(getAlertsCount(projects), 6); diff --git a/src/test/resources/testdata/41.task b/src/test/resources/testdata/41.task new file mode 100644 index 0000000..a64c2cc --- /dev/null +++ b/src/test/resources/testdata/41.task @@ -0,0 +1,8 @@ +Format: 1.2 +Name: JsonBuilder Test +Created: 1243600123 +Options: 0 +Project: 1 +Data: +20090131 452 +20090205 4533 diff --git a/src/test/resources/testdata/41.task.sync b/src/test/resources/testdata/41.task.sync new file mode 100644 index 0000000..01cb6d9 --- /dev/null +++ b/src/test/resources/testdata/41.task.sync @@ -0,0 +1,3 @@ +Format: 1.2 +SyncInfo: +http://localhost:3000 true -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.