From 97756c0a86f5e62e879240840d78946bc0b0ec24 Mon Sep 17 00:00:00 2001 From: norangebit Date: Mon, 11 Nov 2019 21:35:40 +0100 Subject: [PATCH 1/2] add getAllSwimlanes and newSwimlane --- .../wekan/wrapper/api/SwimlanesService.java | 16 ++++ .../java/wekan/wrapper/entity/Swimlane.java | 25 +++++ .../wrapper/api/SwimlanesServiceTest.java | 91 +++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java create mode 100644 wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java create mode 100644 wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java diff --git a/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java b/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java new file mode 100644 index 0000000..6600066 --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java @@ -0,0 +1,16 @@ +package wekan.wrapper.api; + +import retrofit2.Call; +import retrofit2.http.*; +import wekan.wrapper.entity.Swimlane; + +import java.util.List; + +public interface SwimlanesService { + @GET("/api/boards/{boardId}/swimlanes") + Call> getAllSwimlanes(@Path("boardId") String boardId); + + @FormUrlEncoded + @POST("/api/boards/{boardId}/swimlanes") + Call newSwimlane(@Path("boardId") String boardId, @Field("title") String SwimlaneTitle); +} diff --git a/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java b/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java new file mode 100644 index 0000000..9e3703e --- /dev/null +++ b/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java @@ -0,0 +1,25 @@ +package wekan.wrapper.entity; + +import com.google.gson.annotations.SerializedName; + +public class Swimlane { + @SerializedName("_id") + private String id; + private String title; + + public String getId() { + return id; + } + + public String getTitle() { + return title; + } + + @Override + public String toString() { + return "Swimlane{" + + "id='" + id + '\'' + + ", title='" + title + '\'' + + '}'; + } +} diff --git a/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java b/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java new file mode 100644 index 0000000..e90ce9e --- /dev/null +++ b/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java @@ -0,0 +1,91 @@ +package wekan.wrapper.api; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; +import wekan.wrapper.entity.Swimlane; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.List; + +import static org.junit.Assert.*; + +public class SwimlanesServiceTest { + private MockWebServer mockWebServer = new MockWebServer(); + private SwimlanesService service = null; + + @Before + public void setUp() { + try { + mockWebServer.start(); + service = new Retrofit.Builder() + .baseUrl(mockWebServer.url("/")) + .addConverterFactory(GsonConverterFactory.create()) + .build() + .create(SwimlanesService.class); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @After + public void teardown() { + try { + mockWebServer.shutdown(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void getAllSwimlanes() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody( + "[ " + SWIMLANE_1 + ", " + SWIMLANE_2 + " ]" + ); + + mockWebServer.enqueue(response); + + try { + List lists = service.getAllSwimlanes("board id").execute().body(); + + assertNotNull(lists); + + assertEquals(2, lists.size()); + + for (int i = 0; i < 2; i++) + assertEquals("title " + (i + 1), lists.get(i).getTitle()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void newSwimlane() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody( + "{\"_id\":\"ixM8fvtBMuNPqGRSX\"}" + ); + + mockWebServer.enqueue(response); + + try { + Swimlane sl = service.newSwimlane("board id", "new swimlane").execute().body(); + + assertNotNull(sl); + assertEquals("ixM8fvtBMuNPqGRSX", sl.getId()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + final static String SWIMLANE_1 = "{\n\"_id\": \"BS4AA79YABBCpDDau\",\n\"title\": \"title 1\"\n}"; + final static String SWIMLANE_2 = "{\n\"_id\": \"QxKYvz7ZW6pcDTwAq\",\n\"title\": \"title 2\"\n}"; +} -- 2.45.2 From 926f47c799eb83a4588509acf203b38a3ad3c813 Mon Sep 17 00:00:00 2001 From: norangebit Date: Tue, 12 Nov 2019 15:15:19 +0100 Subject: [PATCH 2/2] add getSwimlane and deleteSwimlane - add javadoc - edit Swimlane class --- .../wekan/wrapper/api/SwimlanesService.java | 34 ++++++++++++++- .../java/wekan/wrapper/entity/Swimlane.java | 43 +++++++++++++++++++ .../wrapper/api/SwimlanesServiceTest.java | 35 ++++++++++++++- 3 files changed, 110 insertions(+), 2 deletions(-) diff --git a/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java b/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java index 6600066..8a3cae9 100644 --- a/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java +++ b/wrapper/src/main/java/wekan/wrapper/api/SwimlanesService.java @@ -7,10 +7,42 @@ import wekan.wrapper.entity.Swimlane; import java.util.List; public interface SwimlanesService { + /** + * Get the list of swimlanes attached to a board. + * + * @param boardId The ID of the board + * @return The list of swimlanes + */ @GET("/api/boards/{boardId}/swimlanes") Call> getAllSwimlanes(@Path("boardId") String boardId); + /** + * Add a swimlane to a board. + * + * @param boardId The ID of the board + * @param swimlaneTitle The new title of the swimlane + * @return The new swimlane + */ @FormUrlEncoded @POST("/api/boards/{boardId}/swimlanes") - Call newSwimlane(@Path("boardId") String boardId, @Field("title") String SwimlaneTitle); + Call newSwimlane(@Path("boardId") String boardId, @Field("title") String swimlaneTitle); + + /** + * Get a swimlane. + * + * @param boardId The ID of the board + * @param swimlaneId The ID of the swimlane + * @return The swimlane + */ + @GET("/api/boards/{boardId}/swimlanes/{swimlaneId}") + Call getSwimlane(@Path("boardId") String boardId, @Path("swimlaneId") String swimlaneId); + + /** + * Delete a swimlane. + * + * @param boardId The ID of the board + * @param swimlaneId The ID of the swimlane + */ + @DELETE("/api/boards/{boardId}/swimlanes/{swimlaneId}") + Call deleteSwimlane(@Path("boardId") String boardId, @Path("swimlaneId") String swimlaneId); } diff --git a/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java b/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java index 9e3703e..c814763 100644 --- a/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java +++ b/wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java @@ -2,10 +2,19 @@ package wekan.wrapper.entity; import com.google.gson.annotations.SerializedName; +import java.util.Date; + public class Swimlane { @SerializedName("_id") private String id; private String title; + private String boardId; + private Date createdAt; + private int sort; + private Color color; + private Date updatedAt; + private Date modifiedAt; + private String type; public String getId() { return id; @@ -15,11 +24,45 @@ public class Swimlane { return title; } + public String getBoardId() { + return boardId; + } + + public Date getCreatedAt() { + return createdAt; + } + + public int getSort() { + return sort; + } + + public Color getColor() { + return color; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public Date getModifiedAt() { + return modifiedAt; + } + + public String getType() { + return type; + } + @Override public String toString() { return "Swimlane{" + "id='" + id + '\'' + ", title='" + title + '\'' + + ", boardId='" + boardId + '\'' + + ", createdAt=" + createdAt + + ", sort=" + sort + + ", updatedAt=" + updatedAt + + ", modifiedAt=" + modifiedAt + + ", type='" + type + '\'' + '}'; } } diff --git a/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java b/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java index e90ce9e..7686589 100644 --- a/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java +++ b/wrapper/src/test/java/wekan/wrapper/api/SwimlanesServiceTest.java @@ -7,6 +7,7 @@ import org.junit.Before; import org.junit.Test; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; +import wekan.wrapper.entity.Color; import wekan.wrapper.entity.Swimlane; import java.io.IOException; @@ -86,6 +87,38 @@ public class SwimlanesServiceTest { } } + @Test + public void getSwimlane() { + MockResponse response = new MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(SWIMLANE_2); + + mockWebServer.enqueue(response); + + try { + Swimlane sl = service.getSwimlane("TtjXrJyvPkG3xsbkw", "JNmpXKCupbtyPkYMG") + .execute().body(); + + assertNotNull(sl); + assertEquals("JNmpXKCupbtyPkYMG", sl.getId()); + assertEquals("title 2", sl.getTitle()); + assertEquals(Color.NAVY, sl.getColor()); + } catch (IOException e) { + e.printStackTrace(); + } + } + final static String SWIMLANE_1 = "{\n\"_id\": \"BS4AA79YABBCpDDau\",\n\"title\": \"title 1\"\n}"; - final static String SWIMLANE_2 = "{\n\"_id\": \"QxKYvz7ZW6pcDTwAq\",\n\"title\": \"title 2\"\n}"; + final static String SWIMLANE_2 = "{" + + "\"_id\":\"JNmpXKCupbtyPkYMG\"," + + "\"title\":\"title 2\"," + + "\"boardId\":\"TtjXrJyvPkG3xsbkw\"," + + "\"sort\":1," + + "\"archived\":false," + + "\"createdAt\":\"2019-11-11T20:34:57.649Z\"," + + "\"updatedAt\":\"2019-11-12T13:56:13.844Z\"," + + "\"modifiedAt\":\"2019-11-12T13:56:13.844Z\"," + + "\"type\":\"swimlane\"," + + "\"color\":\"navy\"" + + "}"; } -- 2.45.2