chore: little cleanup
parent
0e6b1e00f9
commit
a8f8539ce0
|
@ -34,10 +34,6 @@ public class App extends Jooby {
|
||||||
}
|
}
|
||||||
|
|
||||||
public App(Stage runningEnv, Collection<Module> modules) {
|
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 =
|
Collection<Module> toInject =
|
||||||
new ArrayList<>(Optional.ofNullable(modules).orElse(Collections.emptySet()));
|
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 GuiceModule(injector)); // We need to do it here
|
||||||
|
|
||||||
install(new BannerModule("Mezzotre"));
|
install(new BannerModule("Mezzotre"));
|
||||||
install(new OpenAPIModule());
|
install(new OpenAPIModule("/docs"));
|
||||||
install(new GsonModule());
|
install(new GsonModule());
|
||||||
install(injector.getInstance(Key.get(Extension.class, Names.named("hikariPoolExtension"))));
|
install(injector.getInstance(Key.get(Extension.class, Names.named("hikariPoolExtension"))));
|
||||||
install(
|
install(
|
||||||
|
|
|
@ -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.TgChat;
|
||||||
import com.github.polpetta.mezzotre.orm.model.query.QTgChat;
|
import com.github.polpetta.mezzotre.orm.model.query.QTgChat;
|
||||||
import com.github.polpetta.mezzotre.telegram.command.Router;
|
import com.github.polpetta.mezzotre.telegram.command.Router;
|
||||||
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
|
||||||
import com.github.polpetta.types.json.ChatContext;
|
import com.github.polpetta.types.json.ChatContext;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.pengrad.telegrambot.TelegramBot;
|
|
||||||
import com.pengrad.telegrambot.model.Message;
|
import com.pengrad.telegrambot.model.Message;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.request.BaseRequest;
|
import com.pengrad.telegrambot.request.BaseRequest;
|
||||||
|
@ -29,25 +27,19 @@ public class Telegram {
|
||||||
|
|
||||||
static final String ENDPOINT = "tg";
|
static final String ENDPOINT = "tg";
|
||||||
private final Logger log;
|
private final Logger log;
|
||||||
private final TelegramBot bot;
|
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
private final Executor completableFutureThreadPool;
|
private final Executor completableFutureThreadPool;
|
||||||
private final UUIDGenerator uuidGenerator;
|
|
||||||
private final Router router;
|
private final Router router;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Telegram(
|
public Telegram(
|
||||||
Logger log,
|
Logger log,
|
||||||
TelegramBot bot,
|
|
||||||
Gson gson,
|
Gson gson,
|
||||||
@Named("eventThreadPool") Executor completableFutureThreadPool,
|
@Named("eventThreadPool") Executor completableFutureThreadPool,
|
||||||
UUIDGenerator uuidGenerator,
|
|
||||||
Router router) {
|
Router router) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
this.bot = bot;
|
|
||||||
this.gson = gson;
|
this.gson = gson;
|
||||||
this.completableFutureThreadPool = completableFutureThreadPool;
|
this.completableFutureThreadPool = completableFutureThreadPool;
|
||||||
this.uuidGenerator = uuidGenerator;
|
|
||||||
this.router = router;
|
this.router = router;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.github.polpetta.mezzotre.telegram.command;
|
||||||
|
|
||||||
import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
|
import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
|
||||||
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
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.google.inject.Singleton;
|
||||||
import com.pengrad.telegrambot.model.Update;
|
import com.pengrad.telegrambot.model.Update;
|
||||||
import com.pengrad.telegrambot.model.request.ParseMode;
|
import com.pengrad.telegrambot.model.request.ParseMode;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.github.polpetta.mezzotre.route;
|
package com.github.polpetta.mezzotre.route;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
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.Loader;
|
||||||
import com.github.polpetta.mezzotre.helper.TestConfig;
|
import com.github.polpetta.mezzotre.helper.TestConfig;
|
||||||
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
import com.github.polpetta.mezzotre.orm.model.TgChat;
|
||||||
import com.github.polpetta.mezzotre.telegram.command.Router;
|
import com.github.polpetta.mezzotre.telegram.command.Router;
|
||||||
import com.github.polpetta.mezzotre.util.UUIDGenerator;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.pengrad.telegrambot.TelegramBot;
|
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.request.SendMessage;
|
||||||
import com.pengrad.telegrambot.response.SendResponse;
|
import com.pengrad.telegrambot.response.SendResponse;
|
||||||
import io.ebean.Database;
|
import io.ebean.Database;
|
||||||
|
import io.jooby.Context;
|
||||||
|
import io.jooby.MediaType;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
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.slf4j.LoggerFactory;
|
||||||
import org.testcontainers.containers.PostgreSQLContainer;
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
import org.testcontainers.junit.jupiter.Container;
|
import org.testcontainers.junit.jupiter.Container;
|
||||||
|
@ -57,10 +59,8 @@ class TelegramIntegrationTest {
|
||||||
telegram =
|
telegram =
|
||||||
new Telegram(
|
new Telegram(
|
||||||
LoggerFactory.getLogger(getClass()),
|
LoggerFactory.getLogger(getClass()),
|
||||||
fakeTelegramBot,
|
|
||||||
new GsonBuilder().setPrettyPrinting().create(),
|
new GsonBuilder().setPrettyPrinting().create(),
|
||||||
Executors.newSingleThreadExecutor(),
|
Executors.newSingleThreadExecutor(),
|
||||||
new UUIDGenerator(),
|
|
||||||
fakeRouter);
|
fakeRouter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,27 +78,28 @@ class TelegramIntegrationTest {
|
||||||
final Context fakeContext = mock(Context.class);
|
final Context fakeContext = mock(Context.class);
|
||||||
final Update update =
|
final Update update =
|
||||||
gson.fromJson(
|
gson.fromJson(
|
||||||
"{\n"
|
"""
|
||||||
+ "\"update_id\":10000,\n"
|
{
|
||||||
+ "\"message\":{\n"
|
"update_id":10000,
|
||||||
+ " \"date\":1441645532,\n"
|
"message":{
|
||||||
+ " \"chat\":{\n"
|
"date":1441645532,
|
||||||
+ " \"last_name\":\"Test Lastname\",\n"
|
"chat":{
|
||||||
+ " \"id\":1111111,\n"
|
"last_name":"Test Lastname",
|
||||||
+ " \"type\": \"private\",\n"
|
"id":1111111,
|
||||||
+ " \"first_name\":\"Test Firstname\",\n"
|
"type": "private",
|
||||||
+ " \"username\":\"Testusername\"\n"
|
"first_name":"Test Firstname",
|
||||||
+ " },\n"
|
"username":"Testusername"
|
||||||
+ " \"message_id\":1365,\n"
|
},
|
||||||
+ " \"from\":{\n"
|
"message_id":1365,
|
||||||
+ " \"last_name\":\"Test Lastname\",\n"
|
"from":{
|
||||||
+ " \"id\":1111111,\n"
|
"last_name":"Test Lastname",
|
||||||
+ " \"first_name\":\"Test Firstname\",\n"
|
"id":1111111,
|
||||||
+ " \"username\":\"Testusername\"\n"
|
"first_name":"Test Firstname",
|
||||||
+ " },\n"
|
"username":"Testusername"
|
||||||
+ " \"text\":\"/start\"\n"
|
},
|
||||||
+ "}\n"
|
"text":"/start"
|
||||||
+ "}",
|
}
|
||||||
|
}""",
|
||||||
Update.class);
|
Update.class);
|
||||||
final CompletableFuture<String> integerCompletableFuture = telegram.incomingUpdate(fakeContext, update);
|
final CompletableFuture<String> integerCompletableFuture = telegram.incomingUpdate(fakeContext, update);
|
||||||
verify(fakeContext, times(1)).setResponseType(MediaType.JSON);
|
verify(fakeContext, times(1)).setResponseType(MediaType.JSON);
|
||||||
|
|
Loading…
Reference in New Issue