release 0.1 #30

Manually merged
noemi3 merged 150 commits from release/0.1 into master 2020-01-18 14:59:02 +00:00
11 changed files with 444 additions and 22 deletions
Showing only changes of commit 7337e1831b - Show all commits

View File

@ -0,0 +1,22 @@
package wekan.wrapper.api;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import wekan.wrapper.entity.Board;
import wekan.wrapper.entity.BoardPrototype;
import java.util.List;
public interface BoardService {
@GET("api/boards")
Call<List<Board>> getPublicBoards();
@POST("api/boards")
Call<Board> newBoard(@Body BoardPrototype boardPrototype);
@GET("api/boards/{boardId}")
Call<Board> getBoard(@Path("boardId") String boardId);
}

View File

@ -1,4 +0,0 @@
package wekan.wrapper.api;
public interface ExampleApi {
}

View File

@ -0,0 +1,143 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
public class Board {
@SerializedName("_id")
private String id;
private String title;
private String slug;
private boolean archived;
private Date createdAt;
private Date modifiedAt;
private int starts;
// TODO list of labels
// TODO list of members
private Permission permission;
private Color color;
private String description;
private String subtasksDefaultBoardId;
private String subtasksDefaultListId;
private boolean allowsSubtasks;
private PresentParentTask presentParentTask;
private Date startAt;
private Date dueAt;
private Date endAt;
private int spentTime;
private boolean isOvertime;
private String type;
private String defaultSwimlaneId;
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getSlug() {
return slug;
}
public boolean isArchived() {
return archived;
}
public Date getCreatedAt() {
return createdAt;
}
public Date getModifiedAt() {
return modifiedAt;
}
public int getStarts() {
return starts;
}
public Permission getPermission() {
return permission;
}
public Color getColor() {
return color;
}
public String getDescription() {
return description;
}
public String getSubtasksDefaultBoardId() {
return subtasksDefaultBoardId;
}
public String getSubtasksDefaultListId() {
return subtasksDefaultListId;
}
public boolean isAllowsSubtasks() {
return allowsSubtasks;
}
public PresentParentTask getPresentParentTask() {
return presentParentTask;
}
public Date getStartAt() {
return startAt;
}
public Date getDueAt() {
return dueAt;
}
public Date getEndAt() {
return endAt;
}
public int getSpentTime() {
return spentTime;
}
public boolean isOvertime() {
return isOvertime;
}
public String getType() {
return type;
}
public String getDefaultSwimlaneId() {
return defaultSwimlaneId;
}
@Override
public String toString() {
return "Board{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", slug='" + slug + '\'' +
", archived=" + archived +
", createdAt=" + createdAt +
", modifiedAt=" + modifiedAt +
", starts=" + starts +
", permission=" + permission +
", color=" + color +
", description='" + description + '\'' +
", subtasksDefaultBoardId='" + subtasksDefaultBoardId + '\'' +
", subtasksDefaultListId='" + subtasksDefaultListId + '\'' +
", allowsSubtasks=" + allowsSubtasks +
", presentParentTask='" + presentParentTask + '\'' +
", startAt=" + startAt +
", dueAt=" + dueAt +
", endAt=" + endAt +
", spentTime=" + spentTime +
", isOvertime=" + isOvertime +
", type='" + type + '\'' +
", defaultSwimlaneId='" + defaultSwimlaneId + '\'' +
'}';
}
}

View File

@ -0,0 +1,25 @@
package wekan.wrapper.entity;
public class BoardPrototype {
private String title;
private String owner;
private boolean isAdmin = true;
private boolean isActive = true;
private boolean isNoComments = false;
private boolean isCommentOnly = false;
private Permission permission = Permission.PRIVATE;
private Color color = Color.BELIZE;
public BoardPrototype(String title, String owner) {
this.title = title;
this.owner = owner;
}
public BoardPrototype(String title, String owner, Color color) {
this.title = title;
this.owner = owner;
this.color = color;
}
}

View File

@ -0,0 +1,30 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
public enum Color {
@SerializedName("belize")
BELIZE,
@SerializedName("nephritis")
NEPHRITIS,
@SerializedName("pomegranate")
POMEGRANATE,
@SerializedName("pumpkin")
PUMPIK,
@SerializedName("wisteria")
WISTERIA,
@SerializedName("moderatepink")
MODERATEPINK,
@SerializedName("strongcyan")
STRONGCYAN,
@SerializedName("limegreen")
LIMEGREEN,
@SerializedName("midnight")
MIDNIGHT,
@SerializedName("dark")
DARK,
@SerializedName("relax")
RELAX,
@SerializedName("corteza")
CORTEZA
}

View File

@ -1,5 +0,0 @@
package wekan.wrapper.entity;
public class ExampleEntity {
}

View File

@ -0,0 +1,10 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
public enum Permission {
@SerializedName("public")
PUBLIC,
@SerializedName("private")
PRIVATE
}

View File

@ -0,0 +1,16 @@
package wekan.wrapper.entity;
import com.google.gson.annotations.SerializedName;
public enum PresentParentTask {
@SerializedName("prefix-with-full-path")
PREFIX_WITH_FULL_PATH,
@SerializedName("prefix-with-parent")
PREFIX_WITH_PARENT,
@SerializedName("subtext-with-full-path")
SUBTEXT_WITH_FULL_PATH,
@SerializedName("subtext-with-parent")
SUBTEXT_WITH_PARENT,
@SerializedName("no-parent")
NO_PARENT
}

View File

@ -0,0 +1,147 @@
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 BoardServiceTest {
private MockWebServer mockWebServer = new MockWebServer();
private BoardService service = null;
@Before
public void setUp() {
try {
mockWebServer.start();
service = new Retrofit.Builder()
.baseUrl(mockWebServer.url("/"))
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(BoardService.class);
} catch (IOException e) {
e.printStackTrace();
}
}
@After
public void teardown() {
try {
mockWebServer.shutdown();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getPublicBoard() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"[{\"_id\":\"e7pJ3T7WciDz5P2v0\",\"title\":\"board 0\"}," +
"{\"_id\":\"e7pJ3T7WciDz5P2v1\",\"title\":\"board 1\"}]"
);
mockWebServer.enqueue(response);
try {
List<Board> boards = service.getPublicBoards().
execute().body();
assertNotNull(boards);
assertEquals(2, boards.size());
for (int i = 0; i < boards.size(); i++) {
assertEquals("e7pJ3T7WciDz5P2v" + i, boards.get(i).getId());
assertEquals("board " + i, boards.get(i).getTitle());
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void newBoardTest() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"{\"_id\":\"cYGkSRfKfEEFDQjv2\",\"defaultSwimlaneId\":\"TffifkXqDvwz9LJNs\"}"
);
mockWebServer.enqueue(response);
try {
Board board = service.newBoard(new BoardPrototype("title", "owner"))
.execute().body();
assertNotNull(board);
assertEquals("cYGkSRfKfEEFDQjv2", board.getId());
assertEquals("TffifkXqDvwz9LJNs", board.getDefaultSwimlaneId());
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void getBoardTest() {
MockResponse response = new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
"{" +
"\"_id\":\"id\"," +
"\"title\":\"my title\"," +
"\"members\":[{\"userId\":\"Si69gNgkJfQuk6uiJ\",\"isAdmin\":true,\"isActive\":true,\"isNoComments\":false,\"isCommentOnly\":false}]," +
"\"permission\":\"private\"," +
"\"color\":\"corteza\"," +
"\"slug\":\"my-title\"," +
"\"archived\":false," +
"\"createdAt\":\"2019-11-09T10:01:21.280Z\"," +
"\"modifiedAt\":\"2019-11-09T10:01:21.280Z\"," +
"\"stars\":0," +
"\"labels\":[{\"color\":\"green\",\"_id\":\"3NvZnG\",\"name\":\"\"},{\"color\":\"yellow\",\"_id\":\"AcBqR9\",\"name\":\"\"},{\"color\":\"orange\",\"_id\":\"JxEw9Z\",\"name\":\"\"},{\"color\":\"red\",\"_id\":\"grdRCS\",\"name\":\"\"},{\"color\":\"purple\",\"_id\":\"buMfKA\",\"name\":\"\"},{\"color\":\"blue\",\"_id\":\"sbi9FZ\",\"name\":\"\"}]," +
"\"subtasksDefaultBoardId\":null," +
"\"subtasksDefaultListId\":null," +
"\"allowsSubtasks\":true," +
"\"presentParentTask\":\"no-parent\"," +
"\"isOvertime\":false," +
"\"type\":\"board\"" +
"}"
);
mockWebServer.enqueue(response);
try {
Board board = service.getBoard("id")
.execute().body();
assertNotNull(board);
assertEquals("id", board.getId());
assertEquals("my title", board.getTitle());
assertEquals("my-title", board.getSlug());
assertFalse(board.isArchived());
assertEquals(0, board.getStarts());
assertEquals(Permission.PRIVATE, board.getPermission());
assertEquals(Color.CORTEZA, board.getColor());
assertTrue(board.isAllowsSubtasks());
assertEquals(PresentParentTask.NO_PARENT, board.getPresentParentTask());
assertEquals(0, board.getSpentTime());
assertFalse(board.isOvertime());
assertEquals("board", board.getType());
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,51 @@
package wekan.wrapper.api;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import wekan.wrapper.entity.Board;
import java.io.IOException;
import java.util.List;
public class BoardServiceTestX {
@Test
public void test() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.addHeader("Authorization", "Bearer GC0ibjF-5OlYczYe6WKCXX_72MtXVC-OEUK4puf9VeI")
.addHeader("Accept", "application/json")
.build();
return chain.proceed(request);
}
});
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://board.norangeb.it")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
BoardService boardService = retrofit.create(BoardService.class);
try {
List<Board> list = boardService.getPublicBoard().execute().body();
for (Board b : list){
System.out.println(b.getId());
System.out.println(b.getTitle());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,13 +0,0 @@
package wekan.wrapper.api;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class ExampleTest {
@Test
public void test() {
assertTrue(true);
}
}