Add SwimlanesService #7
@ -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<List<Swimlane>> getAllSwimlanes(@Path("boardId") String boardId);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/api/boards/{boardId}/swimlanes")
|
||||
Call<Swimlane> newSwimlane(@Path("boardId") String boardId, @Field("title") String SwimlaneTitle);
|
||||
}
|
25
wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java
Normal file
25
wrapper/src/main/java/wekan/wrapper/entity/Swimlane.java
Normal file
@ -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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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<Swimlane> 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}";
|
||||
}
|
Loading…
Reference in New Issue
Block a user