chore: little cleanup

devel
Davide Polonio 2023-03-26 21:13:01 +02:00
parent 0e6b1e00f9
commit a8f8539ce0
4 changed files with 29 additions and 40 deletions

View File

@ -34,10 +34,6 @@ public class App extends Jooby {
}
public App(Stage runningEnv, Collection<Module> modules) {
// FIXME change it in some configuration file!
setName("Mezzotre");
setVersion("1.0-SNAPSHOT");
// END FIXME
Collection<Module> toInject =
new ArrayList<>(Optional.ofNullable(modules).orElse(Collections.emptySet()));
@ -51,7 +47,7 @@ public class App extends Jooby {
install(new GuiceModule(injector)); // We need to do it here
install(new BannerModule("Mezzotre"));
install(new OpenAPIModule());
install(new OpenAPIModule("/docs"));
install(new GsonModule());
install(injector.getInstance(Key.get(Extension.class, Names.named("hikariPoolExtension"))));
install(

View File

@ -3,10 +3,8 @@ package com.github.polpetta.mezzotre.route;
import com.github.polpetta.mezzotre.orm.model.TgChat;
import com.github.polpetta.mezzotre.orm.model.query.QTgChat;
import com.github.polpetta.mezzotre.telegram.command.Router;
import com.github.polpetta.mezzotre.util.UUIDGenerator;
import com.github.polpetta.types.json.ChatContext;
import com.google.gson.Gson;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.model.Message;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.BaseRequest;
@ -29,25 +27,19 @@ public class Telegram {
static final String ENDPOINT = "tg";
private final Logger log;
private final TelegramBot bot;
private final Gson gson;
private final Executor completableFutureThreadPool;
private final UUIDGenerator uuidGenerator;
private final Router router;
@Inject
public Telegram(
Logger log,
TelegramBot bot,
Gson gson,
@Named("eventThreadPool") Executor completableFutureThreadPool,
UUIDGenerator uuidGenerator,
Router router) {
this.log = log;
this.bot = bot;
this.gson = gson;
this.completableFutureThreadPool = completableFutureThreadPool;
this.uuidGenerator = uuidGenerator;
this.router = router;
}

View File

@ -2,7 +2,7 @@ package com.github.polpetta.mezzotre.telegram.command;
import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
import com.github.polpetta.mezzotre.orm.model.TgChat;
import com.github.polpetta.mezzotre.util.Clock;import com.github.polpetta.types.json.ChatContext;
import com.github.polpetta.types.json.ChatContext;
import com.google.inject.Singleton;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.model.request.ParseMode;

View File

@ -1,13 +1,13 @@
package com.github.polpetta.mezzotre.route;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import com.github.polpetta.mezzotre.helper.Loader;
import com.github.polpetta.mezzotre.helper.TestConfig;
import com.github.polpetta.mezzotre.orm.model.TgChat;
import com.github.polpetta.mezzotre.telegram.command.Router;
import com.github.polpetta.mezzotre.util.UUIDGenerator;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.pengrad.telegrambot.TelegramBot;
@ -15,11 +15,13 @@ import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.response.SendResponse;
import io.ebean.Database;
import io.jooby.Context;
import io.jooby.MediaType;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import io.jooby.Context;import io.jooby.MediaType;import org.junit.jupiter.api.*;
import org.junit.jupiter.api.*;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
@ -57,10 +59,8 @@ class TelegramIntegrationTest {
telegram =
new Telegram(
LoggerFactory.getLogger(getClass()),
fakeTelegramBot,
new GsonBuilder().setPrettyPrinting().create(),
Executors.newSingleThreadExecutor(),
new UUIDGenerator(),
fakeRouter);
}
@ -78,27 +78,28 @@ class TelegramIntegrationTest {
final Context fakeContext = mock(Context.class);
final Update update =
gson.fromJson(
"{\n"
+ "\"update_id\":10000,\n"
+ "\"message\":{\n"
+ " \"date\":1441645532,\n"
+ " \"chat\":{\n"
+ " \"last_name\":\"Test Lastname\",\n"
+ " \"id\":1111111,\n"
+ " \"type\": \"private\",\n"
+ " \"first_name\":\"Test Firstname\",\n"
+ " \"username\":\"Testusername\"\n"
+ " },\n"
+ " \"message_id\":1365,\n"
+ " \"from\":{\n"
+ " \"last_name\":\"Test Lastname\",\n"
+ " \"id\":1111111,\n"
+ " \"first_name\":\"Test Firstname\",\n"
+ " \"username\":\"Testusername\"\n"
+ " },\n"
+ " \"text\":\"/start\"\n"
+ "}\n"
+ "}",
"""
{
"update_id":10000,
"message":{
"date":1441645532,
"chat":{
"last_name":"Test Lastname",
"id":1111111,
"type": "private",
"first_name":"Test Firstname",
"username":"Testusername"
},
"message_id":1365,
"from":{
"last_name":"Test Lastname",
"id":1111111,
"first_name":"Test Firstname",
"username":"Testusername"
},
"text":"/start"
}
}""",
Update.class);
final CompletableFuture<String> integerCompletableFuture = telegram.incomingUpdate(fakeContext, update);
verify(fakeContext, times(1)).setResponseType(MediaType.JSON);