From 9436d4927dc5035c83620bdd1dd34600370dce56 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 1 Jul 2024 04:10:37 +0300 Subject: JPA: fix relations, add new fields, add basic tests --- .../java/com/juick/server/tests/ServerTests.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/test/java/com/juick/server') diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index a942323c..a9f767f7 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -30,6 +30,10 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.github.scribejava.apis.AppleClientSecretGenerator; import com.jayway.jsonpath.JsonPath; import com.juick.*; +import com.juick.data.MessagesRepository; +import com.juick.data.UsersRepository; +import com.juick.data.entities.MessageEntity; +import com.juick.data.entities.ReplyEntity; import com.juick.model.Tag; import com.juick.model.*; import com.juick.server.MockNotificationListener; @@ -196,6 +200,10 @@ public class ServerTests { @Inject private ProfileUriBuilder profileUriBuilder; @Inject + private MessagesRepository messagesRepository; + @Inject + private UsersRepository usersRepository; + @Inject private WebApp webApp; @Value("${ap_base_uri:http://localhost:8080/}") private String baseUri; @@ -2717,4 +2725,26 @@ public class ServerTests { var truncated = StringUtils.abbreviate(text, "…", 47); assertThat(truncated, is(expected)); } + @Test + @Transactional + public void jpaMessageTests() { + var user = usersRepository.findByName(ugnichName); + var message = new MessageEntity(); + message.setUser(user); + message.setText("Hello, JPA!"); + message.setTimestamp(Instant.now()); + message = messagesRepository.save(message); + var msg = messagesService.getMessage(message.getId()); + assertThat(msg.get().getText(), is(notNullValue())); + assertThat(msg.get().getText(), is (message.getText())); + } + @Test + @Transactional + public void jpaReplyTests() { + var mid = messagesService.createMessage(ugnich.getUid(), "new message", null, Set.of()); + var rid = messagesService.createReply(mid, 0, ugnich, "reply 1", null); + var message = messagesRepository.getReferenceById(mid); + var replies = message.getReplies(); + assertThat(replies.size(), is(1)); + } } -- cgit v1.2.3