From 97757895eae670220126b985f763933e0cc4c359 Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Wed, 8 Jan 2025 19:32:40 +0200 Subject: [PATCH] Fix deserialization failures in GetMyXYZ bot API methods --- .../client/TestTelegramClientIntegration.java | 93 ++++++++++++++++++- .../objects/description/BotDescription.java | 4 +- .../description/BotShortDescription.java | 4 +- .../meta/api/objects/name/BotName.java | 4 +- 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java index a45becc93..031d1bba7 100644 --- a/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java +++ b/telegrambots-client/src/test/java/org/telegram/telegrambots/client/TestTelegramClientIntegration.java @@ -14,6 +14,13 @@ import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.meta.TelegramUrl; import org.telegram.telegrambots.meta.api.methods.botapimethods.PartialBotApiMethod; +import org.telegram.telegrambots.meta.api.methods.commands.GetMyCommands; +import org.telegram.telegrambots.meta.api.methods.description.GetMyDescription; +import org.telegram.telegrambots.meta.api.methods.description.GetMyShortDescription; +import org.telegram.telegrambots.meta.api.methods.description.SetMyDescription; +import org.telegram.telegrambots.meta.api.methods.description.SetMyShortDescription; +import org.telegram.telegrambots.meta.api.methods.name.GetMyName; +import org.telegram.telegrambots.meta.api.methods.name.SetMyName; import org.telegram.telegrambots.meta.api.methods.send.SendAnimation; import org.telegram.telegrambots.meta.api.methods.send.SendAudio; import org.telegram.telegrambots.meta.api.methods.send.SendDocument; @@ -24,16 +31,22 @@ import org.telegram.telegrambots.meta.api.methods.send.SendVideoNote; import org.telegram.telegrambots.meta.api.methods.send.SendVoice; import org.telegram.telegrambots.meta.api.objects.InputFile; +import org.telegram.telegrambots.meta.api.objects.commands.BotCommand; +import org.telegram.telegrambots.meta.api.objects.description.BotDescription; +import org.telegram.telegrambots.meta.api.objects.description.BotShortDescription; import org.telegram.telegrambots.meta.api.objects.message.Message; +import org.telegram.telegrambots.meta.api.objects.name.BotName; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import java.io.File; import java.io.Serializable; +import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals; -public class TestTelegramClientIntegration { +class TestTelegramClientIntegration { private MockWebServer webServer; private static final String TOKEN = "testToken"; @@ -168,6 +181,84 @@ void testSendAnimation() throws TelegramApiException { assertEquals(responseMessage, parsedMessage); } + @Test + void testGetMyName() throws TelegramApiException { + var method = new GetMyName(); + + var expected = new BotName(TestData.BOT_USER.getFirstName()); + mockMethod(method, expected); + + var actual = client.execute(method); + assertEquals(expected, actual); + } + + @Test + void testSetMyName() throws TelegramApiException { + var method = new SetMyName(); + method.setName(TestData.BOT_USER.getFirstName()); + + mockMethod(method, Boolean.TRUE); + + assertTrue(client.execute(method)); + } + + @Test + void testGetMyDescription() throws TelegramApiException { + var method = new GetMyDescription(); + + var expected = new BotDescription("description"); + mockMethod(method, expected); + + var actual = client.execute(method); + assertEquals(expected, actual); + } + + @Test + void testSetMyDescription() throws TelegramApiException { + var method = new SetMyDescription(); + method.setDescription("description"); + + mockMethod(method, Boolean.TRUE); + + assertTrue(client.execute(method)); + } + + @Test + void testGetMyShortDescription() throws TelegramApiException { + var method = new GetMyShortDescription(); + + var expected = new BotShortDescription("short"); + mockMethod(method, expected); + + var actual = client.execute(method); + assertEquals(expected, actual); + } + + @Test + void testSetMyShortDescription() throws TelegramApiException { + var method = new SetMyShortDescription(); + method.setShortDescription("description"); + + mockMethod(method, Boolean.TRUE); + + assertTrue(client.execute(method)); + } + + @Test + void testGetMyCommands() throws TelegramApiException { + var method = new GetMyCommands(); + + var expected = new ArrayList(); + expected.add(BotCommand.builder() + .command("command") + .description("description") + .build()); + mockMethod(method, expected); + + var actual = client.execute(method); + assertEquals(expected, actual); + } + @Test void testSendMessageException() { SendMessage method = new SendMessage("someChatId", "someText"); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotDescription.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotDescription.java index aec597275..ebac7280d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotDescription.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotDescription.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; +import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; /** @@ -20,7 +21,8 @@ @ToString @AllArgsConstructor @Builder -public class BotDescription implements BotApiObject { +@Jacksonized +public class BotDescription implements BotApiObject { private static final String DESCRIPTION_FIELD = "description"; /** diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotShortDescription.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotShortDescription.java index 95418e979..a50489670 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotShortDescription.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/description/BotShortDescription.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; +import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; /** @@ -20,7 +21,8 @@ @ToString @AllArgsConstructor @Builder -public class BotShortDescription implements BotApiObject { +@Jacksonized +public class BotShortDescription implements BotApiObject { private static final String SHORT_DESCRIPTION_FIELD = "short_description"; /** diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/name/BotName.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/name/BotName.java index d6d70865a..2cd4400cd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/name/BotName.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/name/BotName.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.Setter; import lombok.ToString; +import lombok.extern.jackson.Jacksonized; import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; /** @@ -20,7 +21,8 @@ @ToString @AllArgsConstructor @Builder -public class BotName implements BotApiObject { +@Jacksonized +public class BotName implements BotApiObject { private static final String NAME_FIELD = "name"; /**