-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pavlo
committed
Jun 4, 2022
1 parent
34687e3
commit 204da8f
Showing
8 changed files
with
273 additions
and
10 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/com/pablojuice/framework/base/BaseAPITest.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,14 @@ | ||
package com.pablojuice.framework.base; | ||
|
||
import io.restassured.RestAssured; | ||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; | ||
import org.testng.annotations.BeforeTest; | ||
|
||
public abstract class BaseAPITest extends AbstractTestNGSpringContextTests { | ||
@BeforeTest | ||
public void setup() { | ||
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); | ||
} | ||
|
||
public abstract void test(); | ||
} |
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,4 @@ | ||
package com.pablojuice.framework.base; | ||
|
||
public abstract class BaseBiz { | ||
} |
2 changes: 1 addition & 1 deletion
2
...ablojuice/framework/ui/base/BasePage.java → ...m/pablojuice/framework/base/BasePage.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
2 changes: 1 addition & 1 deletion
2
...lojuice/framework/ui/base/BaseUITest.java → ...pablojuice/framework/base/BaseUITest.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
4 changes: 0 additions & 4 deletions
4
src/main/java/com/pablojuice/framework/ui/base/BaseAPITest.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
199 changes: 199 additions & 0 deletions
199
src/test/java/com/pablojuice/framework/api/TrelloApiBiz.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,199 @@ | ||
package com.pablojuice.framework.api; | ||
|
||
import com.pablojuice.framework.base.BaseBiz; | ||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.testng.Assert; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class TrelloApiBiz extends BaseBiz { | ||
|
||
private static final String BASE_URI = "https://api.trello.com"; | ||
private static final String BASE_PATH = "/1"; | ||
|
||
private final String apiKey; | ||
private final String apiToken; | ||
|
||
private final List<String> boardIDs = new ArrayList<>(); | ||
private final List<String> listIDs = new ArrayList<>(); | ||
private final List<String> cardIDs = new ArrayList<>(); | ||
|
||
public TrelloApiBiz(String apiKey, String apiToken) { | ||
this.apiKey = apiKey; | ||
this.apiToken = apiToken; | ||
RestAssured.baseURI = BASE_URI; | ||
RestAssured.basePath = BASE_PATH; | ||
} | ||
|
||
public TrelloApiBiz createBoard() { | ||
String randomBoardName = "newBoard" + getRandomString(); | ||
String boardID = givenTrelloRequest() | ||
.queryParam("name", randomBoardName) | ||
.post("/boards") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.assertThat() | ||
.body("name", equalTo(randomBoardName)) | ||
.extract().path("id"); | ||
Assert.assertNotNull(boardID); | ||
boardIDs.add(boardID); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz checkIfBoardExists() { | ||
Assert.assertNotNull(getLatestBoardID(), "Board id is null"); | ||
givenTrelloRequest() | ||
.get("/boards/" + getLatestBoardID()) | ||
.then() | ||
.assertThat() | ||
.statusCode(200); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz renameBoard() { | ||
Assert.assertNotNull(getLatestBoardID(), "Board id is null"); | ||
String newBoardName = "newBoard" + getRandomString(); | ||
givenTrelloRequest() | ||
.queryParam("name", newBoardName) | ||
.put("/boards/" + getLatestBoardID()) | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.assertThat() | ||
.body("name", equalTo(newBoardName)); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz deleteBoard() { | ||
Assert.assertNotNull(getLatestBoardID(), "Board id is null"); | ||
givenTrelloRequest() | ||
.delete("/boards/" + getLatestBoardID()) | ||
.then() | ||
.statusCode(200); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz createCardList() { | ||
Assert.assertNotNull(getLatestBoardID(), "Board id is null"); | ||
String randomListName = "newList" + getRandomString(); | ||
listIDs.add( | ||
givenTrelloRequest() | ||
.queryParam("name", randomListName) | ||
.post("/boards/" + getLatestBoardID() + "/lists") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.assertThat() | ||
.body("name", equalTo(randomListName)) | ||
.extract().path("id") | ||
); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz moveCardsToAnotherList() { | ||
Assert.assertNotNull(getLatestListID(), "List id is null"); | ||
Assert.assertTrue(listIDs.size() > 1); | ||
givenTrelloRequest() | ||
.queryParam("idList", getLatestListID()) | ||
.post("/lists/" + listIDs.get(listIDs.size() - 2) + "/moveAllCards") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz createCard() { | ||
Assert.assertNotNull(getLatestListID(), "List id is null"); | ||
String randomCardName = "newCard" + getRandomString(); | ||
cardIDs.add( | ||
givenTrelloRequest() | ||
.queryParam("name", randomCardName) | ||
.queryParam("idList", getLatestListID()) | ||
.queryParam("desc", "initial Test Description") | ||
.post("/cards") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.assertThat() | ||
.body("name", equalTo(randomCardName)) | ||
.extract().path("id") | ||
); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz editCard() { | ||
Assert.assertNotNull(getLatestCardID(), "Card id is null"); | ||
givenTrelloRequest() | ||
.queryParam("name", "newCard0") | ||
.queryParam("desc", "edited Test Description") | ||
.put("/cards/" + getLatestCardID()) | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.JSON) | ||
.assertThat() | ||
.body("desc", equalTo("edited Test Description")) | ||
.extract().path("id"); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz commentCard() { | ||
Assert.assertNotNull(getLatestCardID(), "Card id is null"); | ||
givenTrelloRequest() | ||
.queryParam("text", "testComment") | ||
.post("/cards/" + getLatestCardID() + "/actions/comments") | ||
.then() | ||
.statusCode(200); | ||
return this; | ||
} | ||
|
||
public TrelloApiBiz deleteCard() { | ||
Assert.assertNotNull(getLatestCardID(), "Card id is null"); | ||
givenTrelloRequest() | ||
.delete("/cards/" + getLatestCardID()) | ||
.then() | ||
.statusCode(200); | ||
return this; | ||
} | ||
|
||
private String getLatestBoardID() { | ||
if (boardIDs.size() > 0) { | ||
return boardIDs.get(boardIDs.size() - 1); | ||
} | ||
return null; | ||
} | ||
|
||
private String getLatestListID() { | ||
if (listIDs.size() > 0) { | ||
return listIDs.get(listIDs.size() - 1); | ||
} | ||
return null; | ||
} | ||
|
||
private String getLatestCardID() { | ||
if (cardIDs.size() > 0) { | ||
return cardIDs.get(cardIDs.size() - 1); | ||
} | ||
return null; | ||
} | ||
|
||
private RequestSpecification givenTrelloRequest() { | ||
return given() | ||
.contentType(ContentType.JSON) | ||
.log().all() | ||
.when() | ||
.queryParam("key", apiKey) | ||
.queryParam("token", apiToken); | ||
} | ||
|
||
private static String getRandomString() { | ||
return UUID.randomUUID().toString(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/pablojuice/framework/api/TrelloApiTest.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,54 @@ | ||
package com.pablojuice.framework.api; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
public class TrelloApiTest { | ||
private static final String KEY = "f037495712ba064a957e97dad510b26b"; | ||
private static final String TOKEN = "f02f1be70c984f4535604d200aa9d074e0fa2eb12f1f937a9ed8076d6fd31816"; | ||
|
||
private final TrelloApiBiz trelloApiBiz = new TrelloApiBiz(KEY, TOKEN); | ||
|
||
@Test | ||
public void testTrelloBoardApi() { | ||
trelloApiBiz | ||
.createBoard() | ||
.checkIfBoardExists() | ||
.renameBoard() | ||
.deleteBoard(); | ||
} | ||
|
||
@Test | ||
public void testTrelloCardListApi() { | ||
trelloApiBiz | ||
.createBoard() | ||
.checkIfBoardExists() | ||
.createCardList() | ||
.deleteBoard(); | ||
} | ||
|
||
@Test | ||
public void testTrelloCardApi() { | ||
trelloApiBiz | ||
.createBoard() | ||
.checkIfBoardExists() | ||
.createCardList() | ||
.createCard().editCard() | ||
.createCard().commentCard() | ||
.createCard().deleteCard() | ||
.deleteBoard(); | ||
} | ||
|
||
@Test | ||
public void testTrelloMoveApi() { | ||
trelloApiBiz | ||
.createBoard() | ||
.checkIfBoardExists() | ||
.createCardList() | ||
.createCard() | ||
.createCard() | ||
.createCard() | ||
.createCardList() | ||
.moveCardsToAnotherList() | ||
.deleteBoard(); | ||
} | ||
} |