Test card service
This commit is contained in:
parent
63297f3817
commit
f990979d93
@ -1,4 +1,196 @@
|
||||
package wekan.wrapper.api;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import wekan.wrapper.entity.Card;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CardServiceTest {
|
||||
private MockWebServer mockWebServer = new MockWebServer();
|
||||
private CardService service = null;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
try {
|
||||
mockWebServer.start();
|
||||
service = new Retrofit.Builder()
|
||||
.baseUrl(mockWebServer.url(""))
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
.create(CardService.class);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
try {
|
||||
mockWebServer.shutdown();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllCardsTest(){
|
||||
MockResponse response = new MockResponse()
|
||||
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.setBody(
|
||||
"[{\"_id\":\"J5a86fPe2DhqN3QbF0\",\"title\":\"card 0\",\"description\":\"proof 0\"}," +
|
||||
"{\"_id\":\"J5a86fPe2DhqN3QbF1\",\"title\":\"card 1\",\"description\":\"proof 1\"}]"
|
||||
);
|
||||
|
||||
mockWebServer.enqueue(response);
|
||||
|
||||
try {
|
||||
List<Card> cards = service.getAllCards("oKthRbLqoXZr5NNua","iA6pmp6fENvF7AaTX").
|
||||
execute().body();
|
||||
|
||||
assertNotNull(cards);
|
||||
assertEquals("Numbero of card not ok",2, cards.size());
|
||||
|
||||
for (int i = 0; i < cards.size(); i++) {
|
||||
assertEquals("J5a86fPe2DhqN3QbF" + i, cards.get(i).getId());
|
||||
assertEquals("card " + i, cards.get(i).getTitle());
|
||||
assertEquals("proof " + i, cards.get(i).getDescription());
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCardTest(){
|
||||
MockResponse response = new MockResponse()
|
||||
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.setBody(card);
|
||||
try {
|
||||
Card card = service.getCard(
|
||||
"oKthRbLqoXZr5NNua","iA6pmp6fENvF7AaTX","J5a86fPe2DhqN3QbF")
|
||||
.execute().body();
|
||||
assertNotNull(card);
|
||||
assertEquals("J5a86fPe2DhqN3QbF", card.getId() );
|
||||
assertEquals("patch", card.getTitle());
|
||||
assertEquals("iA6pmp6fENvF7AaTX", card.getListId());
|
||||
assertEquals("2019-11-10T11:21:31.116Z", card.getCreatedAt().toString());
|
||||
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
mockWebServer.enqueue(response);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newCardTest(){
|
||||
MockResponse response = new MockResponse()
|
||||
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.setBody(
|
||||
"{\"_id\":\"FGgYsTzrwLJM8QT6W\"}"
|
||||
);
|
||||
|
||||
mockWebServer.enqueue(response);
|
||||
|
||||
try {
|
||||
Card card = service.newCard(
|
||||
cardToAdd,
|
||||
"oKthRbLqoXZr5NNua","iA6pmp6fENvF7AaTX")
|
||||
.execute().body();
|
||||
|
||||
assertNotNull(card);
|
||||
assertEquals("FGgYsTzrwLJM8QT6W", card.getId());
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCardsForSwimlaneTest() throws IOException {
|
||||
MockResponse response = new MockResponse()
|
||||
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.setBody("[{\"_id\":\"J5a86fPe2DhqN3QbF0\",\"title\":\"card 0\",\"description\":\"proof\",\"listId\":\"iA6pmp6fENvF7AaTX0\"}," +
|
||||
"{\"_id\":\"J5a86fPe2DhqN3QbF1\",\"title\":\"card 1\",\"description\":\"proof\",\"listId\":\"iA6pmp6fENvF7AaTX1\"}," +
|
||||
"{\"_id\":\"J5a86fPe2DhqN3QbF2\",\"title\":\"card 2\",\"description\":\"proof\",\"listId\":\"iA6pmp6fENvF7AaTX2\"}]");
|
||||
|
||||
mockWebServer.enqueue(response);
|
||||
List<Card> cards = service.getCardsForswimlane(
|
||||
"oKthRbLqoXZr5NNua","ScwkAWCRW23duajxJ")
|
||||
.execute().body();
|
||||
assertNotNull(cards);
|
||||
assertEquals(3, cards.size());
|
||||
for(int i = 0; i < cards.size(); i++){
|
||||
assertEquals("J5a86fPe2DhqN3QbF" + i, cards.get(i).getId());
|
||||
assertEquals("card " + i, cards.get(i).getTitle());
|
||||
assertEquals("iA6pmp6fENvF7AaTX" + i, cards.get(i).getListId());
|
||||
assertEquals("proof", cards.get(i).getDescription());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateCardTest() throws Exception {
|
||||
MockResponse response = new MockResponse()
|
||||
.setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.setBody("{\"_id\":\"sig8KLcMcPTGx5GfF\"}");
|
||||
|
||||
mockWebServer.enqueue(response);
|
||||
Card update = new Card();
|
||||
update.setTitle("newTitle");
|
||||
|
||||
Card card = service.putCard(update, "","","")
|
||||
.execute().body();
|
||||
assertNotNull(card);
|
||||
assertEquals("sig8KLcMcPTGx5GfF", card.getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static final String card =
|
||||
"{"+
|
||||
"\"_id\":\"J5a86fPe2DhqN3QbF\"," +
|
||||
"\"title\":\"title1\","+
|
||||
"\"boardId\":\"oKthRbLqoXZr5NNua\"," +
|
||||
"\"listId\":\"iA6pmp6fENvF7AaTX\"," +
|
||||
"\"description\":\"proof\"," +
|
||||
"\"userId\":\"jPdkf3a9bmfZWx3GR\"," +
|
||||
"\"swimlaneId\":\"ScwkAWCRW23duajxJ\"," +
|
||||
"\"sort\":\"1\"," +
|
||||
"\"members\":\"[]\"," +
|
||||
"\"archived\":\"false\"," +
|
||||
"\"parentId\":\"\"," +
|
||||
"\"coverId\":\"\"," +
|
||||
"\"createdAt\":\"2019-11-10T11:21:31.116Z\"," +
|
||||
"\"modifiedAt\":\"2019-11-10T21:49:58.023Z\"," +
|
||||
"\"customFields\":\"[]\"," +
|
||||
"\"dateLastActivity\":\"2019-11-10T21:49:58.024Z\"," +
|
||||
"\"requestedBy\":\"\"," +
|
||||
"\"assignedBy\":\"\"," +
|
||||
"\"labelIds\":\"[]\"," +
|
||||
"\"assignees\":\"[]\"," +
|
||||
"\"spentTime\":\"0\"," +
|
||||
"\"isOvertime\":\"false\"," +
|
||||
"\"subtaskSort\":\"-1\"," +
|
||||
"\"type\":\"cardType-card\"," +
|
||||
"\"linkedId\":\"" +
|
||||
"}";
|
||||
private static final Card cardToAdd = new Card(
|
||||
"jPdkf3a9bmfZWx3GR","cardAdded","ScwkAWCRW23duajxJ",
|
||||
"proof");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user