chore: fix localization tests, add annotations

devel
Davide Polonio 2023-03-26 22:29:05 +02:00
parent 8575622c8a
commit 2391bc537f
3 changed files with 72 additions and 60 deletions

View File

@ -117,6 +117,12 @@
<version>${javax.validation.version}</version> <version>${javax.validation.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Flyway Module--> <!-- Flyway Module-->
<dependency> <dependency>
<groupId>io.jooby</groupId> <groupId>io.jooby</groupId>

View File

@ -1,8 +1,5 @@
package com.github.polpetta.mezzotre.telegram.command; package com.github.polpetta.mezzotre.telegram.command;
import static org.junit.jupiter.api.Assertions.*;
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.i18n.LocalizedMessageFactory; import com.github.polpetta.mezzotre.i18n.LocalizedMessageFactory;
@ -14,9 +11,6 @@ import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.BaseRequest; import com.pengrad.telegrambot.request.BaseRequest;
import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.request.SendMessage;
import io.ebean.Database; import io.ebean.Database;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
@ -30,6 +24,12 @@ import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import static org.junit.jupiter.api.Assertions.*;
@Tag("slow") @Tag("slow")
@Tag("database") @Tag("database")
@Tag("velocity") @Tag("velocity")
@ -71,31 +71,33 @@ class StartIntegrationTest {
@Test @Test
void shouldUpdateContextInTheDatabase() throws Exception { void shouldUpdateContextInTheDatabase() throws Exception {
final TgChat tgChat = new TgChat(1111111L, new ChatContext()); final TgChat tgChat = new TgChat(1111111L, new ChatContext());
tgChat.setLocale("en-US");
tgChat.save(); tgChat.save();
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<Optional<BaseRequest<?, ?>>> gotFuture = start.process(tgChat, update); final CompletableFuture<Optional<BaseRequest<?, ?>>> gotFuture = start.process(tgChat, update);

View File

@ -1,8 +1,5 @@
package com.github.polpetta.mezzotre.telegram.command; package com.github.polpetta.mezzotre.telegram.command;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
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.types.json.ChatContext; import com.github.polpetta.types.json.ChatContext;
@ -10,18 +7,24 @@ import com.google.gson.Gson;
import com.pengrad.telegrambot.model.Update; import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.BaseRequest; import com.pengrad.telegrambot.request.BaseRequest;
import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.request.SendMessage;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.slf4j.Logger;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants; import static org.junit.jupiter.api.Assertions.*;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.slf4j.Logger;
@Tag("velocity") @Tag("velocity")
@Execution(ExecutionMode.CONCURRENT) @Execution(ExecutionMode.CONCURRENT)
@ -52,33 +55,34 @@ class StartTest {
@Test @Test
void shouldReceiveHelloIntroduction() throws Exception { void shouldReceiveHelloIntroduction() throws Exception {
final TgChat fakeChat = mock(TgChat.class); final TgChat fakeChat = mock(TgChat.class);
when(fakeChat.getLocale()).thenReturn("en"); when(fakeChat.getLocale()).thenReturn("en-US");
when(fakeChat.getChatContext()).thenReturn(new ChatContext()); when(fakeChat.getChatContext()).thenReturn(new ChatContext());
when(fakeChat.getId()).thenReturn(1111111L); when(fakeChat.getId()).thenReturn(1111111L);
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<Optional<BaseRequest<?, ?>>> gotFuture = final CompletableFuture<Optional<BaseRequest<?, ?>>> gotFuture =