release 0.1 #30

Manually merged
noemi3 merged 150 commits from release/0.1 into master 2020-01-18 14:59:02 +00:00
6 changed files with 656 additions and 0 deletions
Showing only changes of commit 72b1ed8f4c - Show all commits

View File

@ -0,0 +1,162 @@
package wekan.wrapper.api;
import retrofit2.Call;
import retrofit2.http.*;
import wekan.wrapper.entity.Checklist;
import wekan.wrapper.entity.ChecklistItem;
import wekan.wrapper.entity.ChecklistPrototype;
import wekan.wrapper.entity.ChecklistItemStatus;
import java.util.List;
public interface ChecklistService {
/**
* Get all checklists attached on a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @return The list with the checklists
*/
@GET("/api/boards/{boardId}/cards/{cardId}/checklists")
Call<List<Checklist>> getAllChecklists(
@Path("boardId") String boardId,
@Path("cardId") String cardId
);
/**
* Attach new empty checklist to a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param title The title of the new checklist
* @return The new checklist
*/
@FormUrlEncoded
@POST("/api/boards/{boardId}/cards/{cardId}/checklists")
Call<Checklist> postChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Field("title") String title
);
/**
* Attach new checklist to a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistPrototype The prototype of the checklist
* @return The new checklist
* @see ChecklistPrototype
*/
@POST("/api/boards/{boardId}/cards/{cardId}/checklists")
Call<Checklist> postChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Body ChecklistPrototype checklistPrototype
);
/**
* Get the checklist attached on a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @return The checklist
*/
@GET("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}")
Call<Checklist> getChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId
);
/**
* Delete the checklist attached on a card.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @return The id of the checklist
*/
@DELETE("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}")
Call<Checklist> deleteChecklist(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId
);
/**
* Get the checklist item attached on a checklist.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @param itemId The ID of the item
* @return The checklist item
*/
@GET("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}")
Call<ChecklistItem> getChecklistItem(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId,
@Path("itemId") String itemId
);
/**
* Change the title of the checklist item.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @param itemId The ID of the item
* @param title The new title
* @return The ID of the checklist item
*/
@FormUrlEncoded
@PUT("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}")
Call<ChecklistItem> editChecklistItem(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId,
@Path("itemId") String itemId,
@Field("title") String title
);
/**
* Change the state of the checklist item.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @param itemId The ID of the item
* @param itemStatus The status of the item
* @return The ID of the checklist item
* @see ChecklistItemStatus
*/
@PUT("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}")
Call<ChecklistItem> editChecklistItem(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId,
@Path("itemId") String itemId,
@Body ChecklistItemStatus itemStatus
);
/**
* Delete a checklist item from the checklist.
*
* @param boardId The ID of the board
* @param cardId The ID of the card
* @param checklistId The ID of the checklist
* @param itemId The ID of the item
* @return The ID of the checklist item
*/
@DELETE("/api/boards/{boardId}/cards/{cardId}/checklists/{checklistId}/items/{itemId}")
Call<ChecklistItem> deleteChecklistItem(
@Path("boardId") String boardId,
@Path("cardId") String cardId,
@Path("checklistId") String checklistId,
@Path("itemId") String itemId
);
}

View File

@ -0,0 +1,64 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import java.util.List;
public class Checklist {
@SerializedName("_id")
private String id;
private String cardId;
private String title;
private List<ChecklistItem> items;
private Date finishedAt;
private Date createdAt;
private Date modifiedAt;
private int sort;
public String getId() {
return id;
}
public String getCardId() {
return cardId;
}
public String getTitle() {
return title;
}
public List<ChecklistItem> getItems() {
return items;
}
public Date getFinishedAt() {
return finishedAt;
}
public Date getCreatedAt() {
return createdAt;
}
public Date getModifiedAt() {
return modifiedAt;
}
public int getSort() {
return sort;
}
@Override
public String toString() {
return "Checklist{" +
"id='" + id + '\'' +
", cardId='" + cardId + '\'' +
", title='" + title + '\'' +
", items=" + items +
", finishedAt=" + finishedAt +
", createdAt=" + createdAt +
", modifiedAt=" + modifiedAt +
", sort=" + sort +
'}';
}
}

View File

@ -0,0 +1,70 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
public class ChecklistItem {
@SerializedName("_id")
private String id;
private String title;
private String checklistId;
private String cardId;
private String userId;
private int sort;
private Date createdAt;
private Date modifiedAt;
private boolean isFinished;
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getChecklistId() {
return checklistId;
}
public String getCardId() {
return cardId;
}
public String getUserId() {
return userId;
}
public int getSort() {
return sort;
}
public Date getCreatedAt() {
return createdAt;
}
public Date getModifiedAt() {
return modifiedAt;
}
public boolean isFinished() {
return isFinished;
}
@Override
public String toString() {
return "ChecklistItem{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", checklistId='" + checklistId + '\'' +
", cardId='" + cardId + '\'' +
", userId='" + userId + '\'' +
", sort=" + sort +
", createdAt=" + createdAt +
", modifiedAt=" + modifiedAt +
", isFinished=" + isFinished +
'}';
}
}

View File

@ -0,0 +1,9 @@
package wekan.wrapper.entity;
public class ChecklistItemStatus {
private boolean isFinished;
public ChecklistItemStatus(boolean isFinished) {
this.isFinished = isFinished;
}
}

View File

@ -0,0 +1,57 @@
package wekan.wrapper.entity;
import java.util.ArrayList;
import java.util.List;
public class ChecklistPrototype {
private String title;
private List<String> items;
private ChecklistPrototype(String title, List<String> items) {
this.title = title;
this.items = items;
}
public static class Builder {
private String title;
private List<String> items;
public Builder() {
items = new ArrayList<>();
}
/**
* Create a new ChecklistPrototype.
*
* @return The ChecklistPrototype
*/
public ChecklistPrototype build() {
return new ChecklistPrototype(
title,
items
);
}
/**
* Set the title of the new checklist
*
* @param title The title of the new board
* @return The builder
*/
public Builder setTitle(String title) {
this.title = title;
return this;
}
/**
* Add a new checklist item to the checklist
*
* @param item The item to add to the checklist
* @return The builder
*/
public Builder addItems(String item) {
items.add(item);
return this;
}
}
}

View File

@ -0,0 +1,294 @@
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.*;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.List;
import static org.junit.Assert.*;
public class ChecklistServiceTest {
private MockWebServer mockWebServer = new MockWebServer();
private ChecklistService service = null;
@Before
public void setUp() {
try {
mockWebServer.start();
service = new Retrofit.Builder()
.baseUrl(mockWebServer.url("/"))
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ChecklistService.class);
} catch (IOException e) {
e.printStackTrace();
}
}
@After
public void teardown() {
try {
mockWebServer.shutdown();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getAllChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"[ " + CHECKLIST_1 + ", " + CHECKLIST_2 + " ]"
);
mockWebServer.enqueue(response);
try {
List<Checklist> checklists = service.getAllChecklists(
"board id", "card id"
).
execute().body();
assertNotNull(checklists);
assertEquals(2, checklists.size());
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void postChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_2
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.postChecklist(
"board id",
"card id",
"title"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void postChecklistChecklistPrototype() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_2
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.postChecklist(
"board id",
"card id",
new ChecklistPrototype.Builder()
.setTitle("title")
.addItems("item 1")
.addItems("item 2")
.build()
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
CHECKLIST_1
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.getChecklist(
"board id",
"card id",
"checklist id"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void deleteChecklist() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"{ \"_id\": \"jdisfoSIkf0\" }"
);
mockWebServer.enqueue(response);
try {
Checklist checklist = service.deleteChecklist(
"board id",
"card id",
"checklist id"
)
.execute().body();
assertNotNull(checklist);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getChecklistItem() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(ITEM);
mockWebServer.enqueue(response);
try {
ChecklistItem item = service.getChecklistItem(
"board id",
"card id",
"checklist id",
"item id"
)
.execute().body();
assertNotNull(item);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void editChecklistItemTitle() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody("{ \"_id\": \"id\" }");
mockWebServer.enqueue(response);
try {
ChecklistItem item = service.editChecklistItem(
"board id",
"card id",
"checklist id",
"item id",
"new title"
)
.execute().body();
assertNotNull(item);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void editChecklistItemState() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody("{ \"_id\": \"id\" }");
mockWebServer.enqueue(response);
try {
ChecklistItem item = service.editChecklistItem(
"board id",
"card id",
"checklist id",
"item id",
new ChecklistItemStatus(true)
)
.execute().body();
assertNotNull(item);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void deleteChecklistItem() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody("{ \"_id\": \"id\" }");
mockWebServer.enqueue(response);
try {
ChecklistItem item = service.deleteChecklistItem(
"board id",
"card id",
"checklist id",
"item id"
)
.execute().body();
assertNotNull(item);
} catch (IOException e) {
e.printStackTrace();
}
}
private static final String CHECKLIST_1 = "{" +
"\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," +
"\"title\":\"clist 1\"," +
"\"cardId\":\"bndtZCrJ9kshcFuw8\"," +
"\"sort\":0," +
"\"createdAt\":\"2019-11-13T18:22:59.987Z\"," +
"\"modifiedAt\":\"2019-11-13T19:34:48.650Z\"," +
"\"items\":[" +
"{\"_id\":\"9J8n6d6u3TkCAGvhw\",\"title\":\"item 1\",\"isFinished\":false}," +
"{\"_id\":\"iehKbi7qFruCyMRNQ\",\"title\":\"item 2\",\"isFinished\":false}" +
"]" +
"}";
private static final String CHECKLIST_2 = "{" +
"\"_id\":\"Tv6FuHLWaDR4Z3ig2\"," +
"\"title\":\"clist 1\"" +
"}";
private static final String ITEM = "{" +
"\"_id\":\"3HhzyoYBYGSr4mLdY\"," +
"\"title\":\"cosa da fare 1\"," +
"\"checklistId\":\"LyE7odMhtqZrgrXL9\"," +
"\"cardId\":\"bndtZCrJ9kshcFuw8\"," +
"\"sort\":0," +
"\"isFinished\":true," +
"\"createdAt\":\"2019-11-14T16:12:46.672Z\"," +
"\"modifiedAt\":\"2019-11-14T16:17:16.159Z\"," +
"\"userId\":\"Si69gNgkJfQuk6uiJ\"" +
"}";
}