Merge branch 'master' of https://github.com/slavino/TelegramBots into slavino-master

# Conflicts:
#	telegrambots-meta/src/test/java/org/telegram/telegrambots/meta/test/TestDeserialization.java
This commit is contained in:
Ruben Bermudez 2021-04-25 02:58:30 +01:00
commit 92e68b51da
6 changed files with 39 additions and 30 deletions

View File

@ -185,6 +185,10 @@ public final class TelegramBotsHelper {
return "{\"ok\": false,\"error_code\": 400,\"description\": \"Error descriptions\",\"parameters\": {\"migrate_to_chat_id\": 12345,\"retry_after\": 12}}";
}
public static String getResponseWithError409() {
return "{\"ok\": false,\"error_code\": 409,\"description\": \"Conflict: terminated by other getUpdates request; make sure that only one bot instance is running\"}";
}
public static String GetSetGameScoreBooleanResponse() {
return "{\"ok\": true,\"result\": true}";
}

View File

@ -51,7 +51,7 @@ class TestDeserialization {
}
@Test
void TestListUpdates() throws Exception {
void testListUpdates() throws Exception {
String updateText = "{\"ok\":true,\"result\":[{\"update_id\":79995144,\n" +
"\"message\":{\"message_id\":90,\"from\":{\"id\":1234567,\"is_bot\":false,\"first_name\":\"MyFirstName\",\"username\":\"MyUsername\",\"language_code\":\"en\"},\"chat\":{\"id\":1234567,\"first_name\":\"MyFirstName\",\"username\":\"MyUsername\",\"type\":\"private\"},\"date\":1604154223,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":79995145,\n" +
"\"message\":{\"message_id\":91,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"MyFirstName\",\"username\":\"MyUsername\",\"language_code\":\"it\"},\"chat\":{\"id\":12345678,\"first_name\":\"MyFirstName\",\"username\":\"MyUsername\",\"type\":\"private\"},\"date\":1604154306,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":79995146,\n" +
@ -89,7 +89,7 @@ class TestDeserialization {
}
@Test
void TestListUpdates2() throws Exception {
void testListUpdates2() throws Exception {
String updateText = "{\"ok\":true,\"result\":[{\"update_id\":259894298,\n" +
"\"message\":{\"message_id\":101,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FistName\",\"last_name\":\"LastName\",\"username\":\"username\"},\"chat\":{\"id\":12345678,\"first_name\":\"FistName\",\"last_name\":\"LastName\",\"username\":\"username\",\"type\":\"private\"},\"date\":1604171814,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":259894299,\n" +
"\"message\":{\"message_id\":102,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FistName\",\"last_name\":\"LastName\",\"username\":\"username\",\"language_code\":\"en\"},\"chat\":{\"id\":12345678,\"first_name\":\"FistName\",\"last_name\":\"LastName\",\"username\":\"username\",\"type\":\"private\"},\"date\":1604188661,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":259894300,\n" +
@ -106,7 +106,7 @@ class TestDeserialization {
}
@Test
void TestListUpdates3() throws Exception {
void testListUpdates3() throws Exception {
String updateText = "{\"ok\":true,\"result\":[{\"update_id\":259894302,\n" +
"\"message\":{\"message_id\":105,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226451,\"text\":\"/start\",\"entities\":[{\"offset\":0,\"length\":6,\"type\":\"bot_command\"}]}},{\"update_id\":259894303,\n" +
"\"message\":{\"message_id\":106,\"from\":{\"id\":12345678,\"is_bot\":false,\"first_name\":\"FirstName\",\"username\":\"Username\",\"language_code\":\"en\"},\"chat\":{\"id\":12345678,\"first_name\":\"FirstName\",\"username\":\"Username\",\"type\":\"private\"},\"date\":1604226480,\"document\":{\"file_name\":\"aaa.txt\",\"mime_type\":\"text/plain\",\"file_id\":\"FILEID\",\"file_unique_id\":\"AgADiQEAAjTe-VQ\",\"file_size\":2}}},{\"update_id\":259894304,\n" +
@ -165,7 +165,7 @@ class TestDeserialization {
}
@Test
void TestListUpdatesVoiceChat() throws Exception {
void testListUpdatesVoiceChat() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": [\n" +
@ -289,7 +289,7 @@ class TestDeserialization {
}
@Test
void TestDeserializationCloseMethod() throws Exception {
void testDeserializationCloseMethod() throws Exception {
String updateText = "{\"ok\":true,\"result\": true}";
Boolean response = new Close().deserializeResponse(updateText);
@ -298,7 +298,7 @@ class TestDeserialization {
}
@Test
void TestDeserializationChatMember() throws Exception {
void testDeserializationChatMember() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": {\n" +
@ -344,7 +344,7 @@ class TestDeserialization {
}
@Test
void TestDeserializationMessageAutodeleteChanged() throws Exception {
void testDeserializationMessageAutodeleteChanged() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": [\n" +
@ -387,7 +387,7 @@ class TestDeserialization {
}
@Test
void TestDeserializationLogoutMethod() throws Exception {
void testDeserializationLogoutMethod() throws Exception {
String updateText = "{\"ok\":true,\"result\": true}";
Boolean response = new LogOut().deserializeResponse(updateText);
@ -396,7 +396,7 @@ class TestDeserialization {
}
@Test
void TestDeserializationGetMyCommandsMethod() throws Exception {
void testDeserializationGetMyCommandsMethod() throws Exception {
String updateText = "{\n" +
" \"ok\": true,\n" +
" \"result\": [\n" +

View File

@ -28,7 +28,7 @@ class TestTelegramApi {
}
@Test
void TestTelegramApiMustBeInitializableForLongPolling() {
void testTelegramApiMustBeInitializableForLongPolling() {
try {
new TelegramBotsApi(BotSession.class);
} catch (TelegramApiException e) {
@ -37,7 +37,7 @@ class TestTelegramApi {
}
@Test
void TestTelegramApiMustBeInitializableForWebhook() {
void testTelegramApiMustBeInitializableForWebhook() {
try {
new TelegramBotsApi(BotSession.class, webhook);
} catch (TelegramApiException e) {
@ -46,7 +46,7 @@ class TestTelegramApi {
}
@Test
void TestTelegramApiMustBeThrowIfNotCreatedForWebhook() {
void testTelegramApiMustBeThrowIfNotCreatedForWebhook() {
try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(BotSession.class, null);
telegramBotsApi.registerBot(new WebhookBot() {

View File

@ -22,7 +22,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestInlineQueryIdMustBePresent() {
void testInlineQueryIdMustBePresent() {
try {
answerInlineQuery.validate();
} catch (TelegramApiValidationException e) {
@ -31,7 +31,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestInlineQueryIdCanNotBeEmpty() {
void testInlineQueryIdCanNotBeEmpty() {
answerInlineQuery.setInlineQueryId("");
try {
answerInlineQuery.validate();
@ -41,7 +41,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestResultsMustBePresent() {
void testResultsMustBePresent() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
try {
answerInlineQuery.validate();
@ -51,7 +51,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestSwitchPmTextCanNotBeEmpty() {
void testSwitchPmTextCanNotBeEmpty() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
answerInlineQuery.setResults(new ArrayList<>());
answerInlineQuery.setSwitchPmText("");
@ -64,7 +64,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestSwitchPmParameterIsMandatoryIfSwitchPmTextIsPresent() {
void testSwitchPmParameterIsMandatoryIfSwitchPmTextIsPresent() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
answerInlineQuery.setResults(new ArrayList<>());
answerInlineQuery.setSwitchPmText("Test Text");
@ -77,7 +77,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestSwitchPmParameterCanNotBeEmptyIfSwitchPmTextIsPresent() {
void testSwitchPmParameterCanNotBeEmptyIfSwitchPmTextIsPresent() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
answerInlineQuery.setResults(new ArrayList<>());
answerInlineQuery.setSwitchPmText("Test Text");
@ -91,7 +91,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestSwitchPmParameterContainsUpTo64Chars() {
void testSwitchPmParameterContainsUpTo64Chars() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
answerInlineQuery.setResults(new ArrayList<>());
answerInlineQuery.setSwitchPmText("Test Text");
@ -105,7 +105,7 @@ class TestAnswerInlineQuery {
}
@Test
void TestSwitchPmParameterOnlyContainsAcceptedCharacters() {
void testSwitchPmParameterOnlyContainsAcceptedCharacters() {
answerInlineQuery.setInlineQueryId("RANDOMEID");
answerInlineQuery.setResults(new ArrayList<>());
answerInlineQuery.setSwitchPmText("Test Text");

View File

@ -11,8 +11,7 @@ import org.telegram.telegrambots.meta.test.TelegramBotsHelper;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Ruben Bermudez
@ -32,14 +31,14 @@ class TestGetUpdates {
}
@Test
void TestGetUpdatesMustBeSerializable() throws Exception {
void testGetUpdatesMustBeSerializable() throws Exception {
String json = mapper.writeValueAsString(getUpdates);
assertNotNull(json);
assertEquals("{\"offset\":15,\"limit\":100,\"timeout\":50,\"method\":\"getupdates\"}", json);
}
@Test
void TestGetUpdatesMustDeserializeCorrectResponse() throws Exception {
void testGetUpdatesMustDeserializeCorrectResponse() throws Exception {
ArrayList<Update> result =
getUpdates.deserializeResponse(TelegramBotsHelper.GetResponseWithoutError());
assertNotNull(result);
@ -47,7 +46,7 @@ class TestGetUpdates {
}
@Test
void TestGetUpdatesMustThrowAnExceptionForInCorrectResponse() {
void testGetUpdatesMustThrowAnExceptionForInCorrectResponse() {
try {
getUpdates.deserializeResponse(TelegramBotsHelper.GetResponseWithError());
} catch (TelegramApiRequestException e) {
@ -56,4 +55,15 @@ class TestGetUpdates {
assertEquals("Error descriptions", e.getApiResponse());
}
}
@Test
void testGetUpdatesMustThrowAnExceptionForInCorrectResponse409() {
try {
getUpdates.deserializeResponse(TelegramBotsHelper.getResponseWithError409());
} catch (TelegramApiRequestException e) {
assertNull(e.getParameters());
assertEquals(Integer.valueOf(409), e.getErrorCode());
assertEquals("Conflict: terminated by other getUpdates request; make sure that only one bot instance is running", e.getApiResponse());
}
}
}

View File

@ -18,9 +18,4 @@
},
"text": "Original"
}
}
{
"ok": true,
"result": true
}