test: enhance Telegram bot application tests with context and token validation
This commit is contained in:
@@ -1,23 +1,38 @@
|
||||
package ru.cathub.telegabot;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@TestPropertySource(locations = "classpath:application.properties") // Указываем файл свойств
|
||||
@TestPropertySource(locations = "classpath:application.properties")
|
||||
class TelegramBotApplicationTests {
|
||||
|
||||
@Value("${bot.token}") // Инъекция значения из application.properties
|
||||
@Value("${bot.token}")
|
||||
private String botToken;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
assertNotNull(applicationContext, "Application context should load successfully");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBotTokenIsLoaded() {
|
||||
// Проверяем, что значение не пустое
|
||||
assertNotNull(botToken, "Bot token should not be null");
|
||||
System.out.println("Bot Token: " + botToken); // Для отладки
|
||||
assertTrue(botToken.length() > 30, "Bot token should be longer than 30 characters");
|
||||
assertTrue(botToken.matches("^\\d+:\\w+$"), "Bot token should match expected format");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBotTokenSecurity() {
|
||||
assertFalse(botToken.contains(" "), "Bot token should not contain spaces");
|
||||
assertFalse(botToken.contains("\n"), "Bot token should not contain newlines");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user