aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2024-07-01 04:10:37 +0300
committerGravatar Vitaly Takmazov2024-07-01 04:10:37 +0300
commit9436d4927dc5035c83620bdd1dd34600370dce56 (patch)
tree2443779dddd23288e0f71b852293d736cf5db942 /src/test/java/com/juick/server
parent9e2e2732d67ba0088b56804f7193e95b4ae46f22 (diff)
JPA: fix relations, add new fields, add basic tests
Diffstat (limited to 'src/test/java/com/juick/server')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java30
1 files changed, 30 insertions, 0 deletions
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));
+ }
}