forked from JetBrains/intellij-community
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce live integration tests for Tasks plugin. Add initial versio…
…n of such tests for Trello
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...s/tasks/tasks-tests/test/com/intellij/tasks/integration/live/LiveIntegrationTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.intellij.tasks.integration.live; | ||
|
||
import com.intellij.tasks.TaskManagerTestCase; | ||
import com.intellij.tasks.TaskRepository; | ||
|
||
/** | ||
* @author Mikhail Golubev | ||
*/ | ||
public abstract class LiveIntegrationTestCase<T extends TaskRepository> extends TaskManagerTestCase { | ||
protected T myRepository; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myRepository = createRepository(); | ||
} | ||
|
||
/** | ||
* @return new instance of task repository <b>with authenticated user<b/> | ||
*/ | ||
protected abstract T createRepository() throws Exception; | ||
} |
142 changes: 142 additions & 0 deletions
142
...ins/tasks/tasks-tests/test/com/intellij/tasks/integration/live/TrelloIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package com.intellij.tasks.integration.live; | ||
|
||
import com.intellij.openapi.util.Condition; | ||
import com.intellij.openapi.util.text.StringUtil; | ||
import com.intellij.tasks.trello.TrelloRepository; | ||
import com.intellij.tasks.trello.TrelloRepositoryType; | ||
import com.intellij.tasks.trello.model.*; | ||
import com.intellij.util.Function; | ||
import com.intellij.util.containers.ContainerUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Mikhail Golubev | ||
*/ | ||
public class TrelloIntegrationTest extends LiveIntegrationTestCase<TrelloRepository> { | ||
|
||
private static final String BOARD_1_NAME = "Board 1"; | ||
private static final String BOARD_1_ID = "53c416a8a6e5a78753562043"; | ||
|
||
private static final String LIST_1_1_NAME = "List 1-1"; | ||
private static final String LIST_1_1_ID = "53c416a8a6e5a78753562044"; | ||
|
||
private static final String CARD_1_1_1_NAME = "Card 1-1-1"; | ||
private static final String CARD_1_1_1_ID = "53c416d8b4bd36fb078446e5"; | ||
|
||
@Override | ||
protected TrelloRepository createRepository() throws Exception { | ||
TrelloRepository repository = new TrelloRepository(new TrelloRepositoryType()); | ||
String token = System.getProperty("tasks.tests.trello.token"); | ||
if (StringUtil.isEmpty(token)) { | ||
throw new AssertionError("Authorization token is not set"); | ||
} | ||
repository.setPassword(token); | ||
TrelloUser user = repository.fetchUserByToken(); | ||
assertNotNull(user); | ||
repository.setCurrentUser(user); | ||
return repository; | ||
} | ||
|
||
// TODO Check closed tasks exclusion | ||
// TODO Check various cards visibility corner cases | ||
|
||
public void testFetchBoard() throws Exception { | ||
TrelloBoard board = myRepository.fetchBoardById(BOARD_1_ID); | ||
assertNotNull(board); | ||
assertEquals(BOARD_1_NAME, board.getName()); | ||
} | ||
|
||
public void testFetchList() throws Exception { | ||
TrelloList list = myRepository.fetchListById(LIST_1_1_ID); | ||
assertNotNull(list); | ||
assertEquals(LIST_1_1_NAME, list.getName()); | ||
} | ||
|
||
public void testFetchCard() throws Exception { | ||
TrelloCard card = myRepository.fetchCardById(CARD_1_1_1_ID); | ||
assertNotNull(card); | ||
assertEquals(CARD_1_1_1_NAME, card.getName()); | ||
} | ||
|
||
public void testFetchBoardsOfUser() throws Exception { | ||
List<TrelloBoard> boards = myRepository.fetchUserBoards(); | ||
assertEquals(2, boards.size()); | ||
assertObjectsNamed("All boards of the user should be included", boards, "Board 1", "Board 2"); | ||
} | ||
|
||
public void testFetchListsOfBoard() throws Exception { | ||
TrelloBoard selectedBoard = myRepository.fetchBoardById(BOARD_1_ID); | ||
assertNotNull(selectedBoard); | ||
myRepository.setCurrentBoard(selectedBoard); | ||
List<TrelloList> lists = myRepository.fetchBoardLists(); | ||
assertEquals(3, lists.size()); | ||
assertObjectsNamed("All lists of the board should be included", lists, "List 1-1", "List 1-2", "List 1-3"); | ||
} | ||
|
||
@NotNull | ||
private List<TrelloCard> fetchCards(@Nullable String boardId, @Nullable String listId, boolean withClosed) throws Exception { | ||
if (boardId != null) { | ||
TrelloBoard selectedBoard = myRepository.fetchBoardById(BOARD_1_ID); | ||
assertNotNull(selectedBoard); | ||
myRepository.setCurrentBoard(selectedBoard); | ||
} | ||
if (listId != null) { | ||
TrelloList selectedList = myRepository.fetchListById(LIST_1_1_ID); | ||
assertNotNull(selectedList); | ||
myRepository.setCurrentList(selectedList); | ||
} | ||
return myRepository.fetchCards(100, withClosed); | ||
} | ||
|
||
public void testFetchingCardsOfUser() throws Exception { | ||
myRepository.setIncludeAllCards(true); | ||
List<TrelloCard> cards = fetchCards(null, null, true); | ||
assertObjectsNamed("All cards assigned to user should be included", cards, "Card 1-1-1"); | ||
} | ||
|
||
public void testFetchingCardsOfBoard() throws Exception { | ||
myRepository.setIncludeAllCards(true); | ||
List<TrelloCard> cards = fetchCards(BOARD_1_ID, null, true); | ||
assertObjectsNamed("All cards of the board should be included", | ||
cards, "Card 1-1-1", "Card 1-1-2", "Card 1-2-1", "Card 1-3-1", "Archived Card"); | ||
} | ||
|
||
public void testCardsFilteringByMembership() throws Exception { | ||
myRepository.setIncludeAllCards(true); | ||
List<TrelloCard> allCards = fetchCards(BOARD_1_ID, LIST_1_1_ID, true); | ||
assertObjectsNamed("All cards of the list should be included", allCards, "Card 1-1-1", "Card 1-1-2", "Archived Card"); | ||
|
||
myRepository.setIncludeAllCards(false); | ||
List<TrelloCard> assignedCards = fetchCards(BOARD_1_ID, LIST_1_1_ID, true); | ||
assertObjectsNamed("Only cards of the list assigned to user should be included", assignedCards, "Card 1-1-1"); | ||
} | ||
|
||
public void testCardsFilteringByStatus() throws Exception { | ||
myRepository.setIncludeAllCards(true); | ||
List<TrelloCard> allCards = fetchCards(BOARD_1_ID, LIST_1_1_NAME, true); | ||
assertObjectsNamed("All cards of the list should be included", allCards, "Card 1-1-1", "Card 1-1-2", "Archived Card"); | ||
|
||
TrelloCard card = ContainerUtil.find(allCards, new Condition<TrelloCard>() { | ||
@Override | ||
public boolean value(TrelloCard card) { | ||
return card.getName().equals("Archived Card"); | ||
} | ||
}); | ||
assertNotNull(card); | ||
assertTrue(card.isClosed()); | ||
assertFalse(card.isVisible()); | ||
} | ||
|
||
static void assertObjectsNamed(@NotNull String message, @NotNull Collection<? extends TrelloModel> objects, @NotNull String... names) { | ||
assertEquals(message, ContainerUtil.newHashSet(names), ContainerUtil.map2Set(objects, new Function<TrelloModel, String>() { | ||
@Override | ||
public String fun(TrelloModel model) { | ||
return model.getName(); | ||
} | ||
})); | ||
} | ||
} |