126 lines
3.8 KiB
Java
126 lines
3.8 KiB
Java
package it.unisannio.ding.ids.wedroid.wrapper.api;
|
|
|
|
import static junit.framework.TestCase.assertNotNull;
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import it.unisannio.ding.ids.wedroid.wrapper.entity.Color;
|
|
import it.unisannio.ding.ids.wedroid.wrapper.entity.Swimlane;
|
|
import java.io.IOException;
|
|
import java.net.HttpURLConnection;
|
|
import java.util.List;
|
|
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;
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
@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();
|
|
}
|
|
}
|
|
|
|
static final String SWIMLANE_1 = "{\n\"_id\": \"BS4AA79YABBCpDDau\",\n\"title\": \"title 1\"\n}";
|
|
static final 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\"" +
|
|
"}";
|
|
}
|