diff --git a/app/src/main/java/io/xeres/app/database/model/gxs/GxsMessageItem.java b/app/src/main/java/io/xeres/app/database/model/gxs/GxsMessageItem.java
index c04ac2501..045437e32 100644
--- a/app/src/main/java/io/xeres/app/database/model/gxs/GxsMessageItem.java
+++ b/app/src/main/java/io/xeres/app/database/model/gxs/GxsMessageItem.java
@@ -68,7 +68,7 @@ public abstract class GxsMessageItem extends Item implements GxsMetaAndData
@AttributeOverride(name = "identifier", column = @Column(name = "author_id"))
private GxsId authorId;
- private String name; // tlv string message name (use serialize(buf, TlvType.STRING, name);
+ private String name;
@UpdateTimestamp
private Instant published; // publishts (32-bits)
@@ -129,6 +129,16 @@ public void setAuthorId(GxsId authorId)
this.authorId = authorId;
}
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
public Instant getPublished()
{
return published;
diff --git a/app/src/main/java/io/xeres/app/xrs/service/forum/item/ForumMessageItem.java b/app/src/main/java/io/xeres/app/xrs/service/forum/item/ForumMessageItem.java
index 24dc24930..e69124855 100644
--- a/app/src/main/java/io/xeres/app/xrs/service/forum/item/ForumMessageItem.java
+++ b/app/src/main/java/io/xeres/app/xrs/service/forum/item/ForumMessageItem.java
@@ -23,6 +23,8 @@
import io.xeres.app.database.model.gxs.GxsMessageItem;
import io.xeres.app.xrs.serialization.SerializationFlags;
import io.xeres.app.xrs.serialization.Serializer;
+import io.xeres.common.id.GxsId;
+import io.xeres.common.id.MessageId;
import jakarta.persistence.Entity;
import java.util.Set;
@@ -40,6 +42,13 @@ public ForumMessageItem()
// Needed for JPA
}
+ public ForumMessageItem(GxsId groupId, MessageId messageId, String name)
+ {
+ setGxsId(groupId);
+ setMessageId(messageId);
+ setName(name);
+ }
+
public String getContent()
{
return content;
diff --git a/app/src/test/java/io/xeres/app/api/controller/chat/ChatControllerTest.java b/app/src/test/java/io/xeres/app/api/controller/chat/ChatControllerTest.java
index 99edca3c4..08f243609 100644
--- a/app/src/test/java/io/xeres/app/api/controller/chat/ChatControllerTest.java
+++ b/app/src/test/java/io/xeres/app/api/controller/chat/ChatControllerTest.java
@@ -20,7 +20,7 @@
package io.xeres.app.api.controller.chat;
import io.xeres.app.api.controller.AbstractControllerTest;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.database.model.location.LocationFakes;
import io.xeres.app.xrs.service.chat.ChatRsService;
import io.xeres.app.xrs.service.chat.RoomFlags;
@@ -123,7 +123,7 @@ void ChatController_GetChatRoomContext_OK() throws Exception
var chatRoomLists = new ChatRoomLists();
chatRoomLists.addSubscribed(subscribedChatRoom);
chatRoomLists.addAvailable(availableChatRoom);
- var ownIdentity = GxsIdFakes.createOwnIdentity();
+ var ownIdentity = IdentityFakes.createOwnIdentity();
var chatRoomUser = new ChatRoomUser(ownIdentity.getName(), ownIdentity.getGxsId(), ownIdentity.getImage());
when(chatRsService.getChatRoomContext()).thenReturn(new ChatRoomContext(chatRoomLists, chatRoomUser));
diff --git a/app/src/test/java/io/xeres/app/api/controller/config/ConfigControllerTest.java b/app/src/test/java/io/xeres/app/api/controller/config/ConfigControllerTest.java
index aca003eef..b160bfc3b 100644
--- a/app/src/test/java/io/xeres/app/api/controller/config/ConfigControllerTest.java
+++ b/app/src/test/java/io/xeres/app/api/controller/config/ConfigControllerTest.java
@@ -21,7 +21,7 @@
import io.xeres.app.api.controller.AbstractControllerTest;
import io.xeres.app.database.model.connection.Connection;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.database.model.location.Location;
import io.xeres.app.net.protocol.PeerAddress;
import io.xeres.app.service.CapabilityService;
@@ -311,7 +311,7 @@ void ConfigController_GetUsername_OK() throws Exception
@Test
void ConfigController_CreateIdentity_Signed_OK() throws Exception
{
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var identityRequest = new OwnIdentityRequest(identity.getName(), false);
when(identityService.createOwnIdentity(identityRequest.name(), true)).thenReturn(identity.getId());
@@ -326,7 +326,7 @@ void ConfigController_CreateIdentity_Signed_OK() throws Exception
@Test
void ConfigController_CreateIdentity_Anonymous_OK() throws Exception
{
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var identityRequest = new OwnIdentityRequest(identity.getName(), true);
when(identityService.createOwnIdentity(identityRequest.name(), false)).thenReturn(identity.getId());
diff --git a/app/src/test/java/io/xeres/app/database/model/chat/ChatRoomFakes.java b/app/src/test/java/io/xeres/app/database/model/chat/ChatRoomFakes.java
index d1510d321..c64add841 100644
--- a/app/src/test/java/io/xeres/app/database/model/chat/ChatRoomFakes.java
+++ b/app/src/test/java/io/xeres/app/database/model/chat/ChatRoomFakes.java
@@ -19,7 +19,7 @@
package io.xeres.app.database.model.chat;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.xrs.service.identity.item.IdentityGroupItem;
import io.xeres.common.message.chat.RoomType;
import org.apache.commons.lang3.RandomStringUtils;
@@ -35,7 +35,7 @@ private ChatRoomFakes()
public static ChatRoom createChatRoomEntity()
{
- return createChatRoomEntity(ThreadLocalRandom.current().nextLong(), GxsIdFakes.createOwnIdentity(), RandomStringUtils.randomAlphabetic(8), RandomStringUtils.randomAlphabetic(8), 0);
+ return createChatRoomEntity(ThreadLocalRandom.current().nextLong(), IdentityFakes.createOwnIdentity(), RandomStringUtils.randomAlphabetic(8), RandomStringUtils.randomAlphabetic(8), 0);
}
public static ChatRoom createChatRoomEntity(IdentityGroupItem identityGroupItem)
diff --git a/app/src/test/java/io/xeres/app/database/model/gxs/ForumGroupItemFakes.java b/app/src/test/java/io/xeres/app/database/model/gxs/ForumGroupItemFakes.java
index 643aa47dd..968cf8843 100644
--- a/app/src/test/java/io/xeres/app/database/model/gxs/ForumGroupItemFakes.java
+++ b/app/src/test/java/io/xeres/app/database/model/gxs/ForumGroupItemFakes.java
@@ -22,8 +22,8 @@
import io.xeres.app.xrs.service.forum.ForumRsService;
import io.xeres.app.xrs.service.forum.item.ForumGroupItem;
import io.xeres.common.id.GxsId;
+import io.xeres.testutils.GxsIdFakes;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.RandomUtils;
import java.time.Instant;
import java.util.EnumSet;
@@ -37,7 +37,7 @@ private ForumGroupItemFakes()
public static ForumGroupItem createForumGroupItem()
{
- return createForumGroupItem(new GxsId(RandomUtils.nextBytes(16)), RandomStringUtils.randomAlphabetic(8));
+ return createForumGroupItem(GxsIdFakes.createGxsId(), RandomStringUtils.randomAlphabetic(8));
}
public static ForumGroupItem createForumGroupItem(GxsId gxsId, String name)
diff --git a/app/src/test/java/io/xeres/app/database/model/gxs/ForumMessageItemFakes.java b/app/src/test/java/io/xeres/app/database/model/gxs/ForumMessageItemFakes.java
new file mode 100644
index 000000000..cc6fc066b
--- /dev/null
+++ b/app/src/test/java/io/xeres/app/database/model/gxs/ForumMessageItemFakes.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023 by David Gerber - https://zapek.com
+ *
+ * This file is part of Xeres.
+ *
+ * Xeres is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xeres is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xeres. If not, see .
+ */
+
+package io.xeres.app.database.model.gxs;
+
+import io.xeres.app.xrs.service.forum.ForumRsService;
+import io.xeres.app.xrs.service.forum.item.ForumMessageItem;
+import io.xeres.common.id.GxsId;
+import io.xeres.common.id.MessageId;
+import io.xeres.testutils.GxsIdFakes;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.RandomUtils;
+
+import java.time.Instant;
+
+public final class ForumMessageItemFakes
+{
+ private ForumMessageItemFakes()
+ {
+ throw new UnsupportedOperationException("Utility class");
+ }
+
+ public static ForumMessageItem createForumMessageItem()
+ {
+ return createForumMessageItem(GxsIdFakes.createGxsId(), new MessageId(RandomUtils.nextBytes(20)), RandomStringUtils.randomAlphabetic(8));
+ }
+
+ private static ForumMessageItem createForumMessageItem(GxsId gxsId, MessageId messageId, String name)
+ {
+ var item = new ForumMessageItem(gxsId, messageId, name);
+ item.setPublished(Instant.now());
+ item.setService(new ForumRsService(null, null, null, null, null));
+ return item;
+ }
+}
diff --git a/app/src/test/java/io/xeres/app/database/model/gxs/IdentityGroupItemFakes.java b/app/src/test/java/io/xeres/app/database/model/gxs/IdentityGroupItemFakes.java
index f57a6a15b..88d068983 100644
--- a/app/src/test/java/io/xeres/app/database/model/gxs/IdentityGroupItemFakes.java
+++ b/app/src/test/java/io/xeres/app/database/model/gxs/IdentityGroupItemFakes.java
@@ -23,8 +23,8 @@
import io.xeres.app.xrs.service.identity.item.IdentityGroupItem;
import io.xeres.common.id.GxsId;
import io.xeres.common.id.Sha1Sum;
+import io.xeres.testutils.GxsIdFakes;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.RandomUtils;
import java.time.Instant;
import java.util.EnumSet;
@@ -38,7 +38,7 @@ private IdentityGroupItemFakes()
public static IdentityGroupItem createIdentityGroupItem()
{
- return createIdentityGroupItem(new GxsId(RandomUtils.nextBytes(16)), RandomStringUtils.randomAlphabetic(8));
+ return createIdentityGroupItem(GxsIdFakes.createGxsId(), RandomStringUtils.randomAlphabetic(8));
}
public static IdentityGroupItem createIdentityGroupItem(GxsId gxsId, String name)
diff --git a/app/src/test/java/io/xeres/app/database/model/identity/GxsIdFakes.java b/app/src/test/java/io/xeres/app/database/model/identity/IdentityFakes.java
similarity index 96%
rename from app/src/test/java/io/xeres/app/database/model/identity/GxsIdFakes.java
rename to app/src/test/java/io/xeres/app/database/model/identity/IdentityFakes.java
index 5178a854a..9be05f79d 100644
--- a/app/src/test/java/io/xeres/app/database/model/identity/GxsIdFakes.java
+++ b/app/src/test/java/io/xeres/app/database/model/identity/IdentityFakes.java
@@ -27,9 +27,9 @@
import static io.xeres.common.dto.identity.IdentityConstants.OWN_IDENTITY_ID;
-public final class GxsIdFakes
+public final class IdentityFakes
{
- private GxsIdFakes()
+ private IdentityFakes()
{
throw new UnsupportedOperationException("Utility class");
}
diff --git a/app/src/test/java/io/xeres/app/database/model/identity/IdentityMapperTest.java b/app/src/test/java/io/xeres/app/database/model/identity/IdentityMapperTest.java
index cfa4f10f2..07c1bcfd4 100644
--- a/app/src/test/java/io/xeres/app/database/model/identity/IdentityMapperTest.java
+++ b/app/src/test/java/io/xeres/app/database/model/identity/IdentityMapperTest.java
@@ -35,7 +35,7 @@ void IdentityMapper_NoInstanceOK() throws NoSuchMethodException
@Test
void IdentityMapper_toDTO_OK()
{
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var identityDTO = IdentityMapper.toDTO(identity);
assertEquals(identity.getId(), identityDTO.id());
diff --git a/app/src/test/java/io/xeres/app/database/repository/ChatRoomRepositoryTest.java b/app/src/test/java/io/xeres/app/database/repository/ChatRoomRepositoryTest.java
index 218091eda..4822f96ea 100644
--- a/app/src/test/java/io/xeres/app/database/repository/ChatRoomRepositoryTest.java
+++ b/app/src/test/java/io/xeres/app/database/repository/ChatRoomRepositoryTest.java
@@ -20,7 +20,7 @@
package io.xeres.app.database.repository;
import io.xeres.app.database.model.chat.ChatRoomFakes;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
@@ -36,7 +36,7 @@ class ChatRoomRepositoryTest
@Test
void ChatRoomRepository_CRUD_OK()
{
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var chatRoom1 = ChatRoomFakes.createChatRoomEntity(identity);
var chatRoom2 = ChatRoomFakes.createChatRoomEntity(identity);
diff --git a/app/src/test/java/io/xeres/app/service/ChatRoomServiceTest.java b/app/src/test/java/io/xeres/app/service/ChatRoomServiceTest.java
index 6a883fd1a..a30114b4b 100644
--- a/app/src/test/java/io/xeres/app/service/ChatRoomServiceTest.java
+++ b/app/src/test/java/io/xeres/app/service/ChatRoomServiceTest.java
@@ -21,7 +21,7 @@
import io.xeres.app.database.model.chat.ChatRoom;
import io.xeres.app.database.model.chat.ChatRoomFakes;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.database.repository.ChatRoomRepository;
import io.xeres.common.message.chat.RoomType;
import org.junit.jupiter.api.Test;
@@ -50,7 +50,7 @@ class ChatRoomServiceTest
@Test
void ChatRoomService_CreateChatRoom_OK()
{
- chatRoomService.createChatRoom(createSignedChatRoom(), GxsIdFakes.createOwnIdentity());
+ chatRoomService.createChatRoom(createSignedChatRoom(), IdentityFakes.createOwnIdentity());
verify(chatRoomRepository).save(any(ChatRoom.class));
}
@@ -58,7 +58,7 @@ void ChatRoomService_CreateChatRoom_OK()
void ChatRoomService_SubscribeToChatRoomAndJoin_OK()
{
var serviceChatRoom = createSignedChatRoom();
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var chatRoom = ChatRoomFakes.createChatRoomEntity(serviceChatRoom.getId(), identity, serviceChatRoom.getName(), serviceChatRoom.getTopic(), 0);
when(chatRoomRepository.findByRoomIdAndIdentityGroupItem(chatRoom.getRoomId(), identity)).thenReturn(Optional.of(chatRoom));
@@ -77,7 +77,7 @@ void ChatRoomService_SubscribeToChatRoomAndJoin_OK()
void ChatRoomService_UnsubscribeFromChatRoomAndLeave_OK()
{
var serviceChatRoom = createSignedChatRoom();
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var chatRoom = ChatRoomFakes.createChatRoomEntity(serviceChatRoom.getId(), identity, serviceChatRoom.getName(), serviceChatRoom.getTopic(), 0);
when(chatRoomRepository.findByRoomIdAndIdentityGroupItem(chatRoom.getRoomId(), identity)).thenReturn(Optional.of(chatRoom));
diff --git a/app/src/test/java/io/xeres/app/service/IdentityServiceTest.java b/app/src/test/java/io/xeres/app/service/IdentityServiceTest.java
index e27b4d987..ed8fc194f 100644
--- a/app/src/test/java/io/xeres/app/service/IdentityServiceTest.java
+++ b/app/src/test/java/io/xeres/app/service/IdentityServiceTest.java
@@ -20,7 +20,7 @@
package io.xeres.app.service;
import io.xeres.app.crypto.pgp.PGP;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.database.model.profile.ProfileFakes;
import io.xeres.app.database.repository.GxsIdentityRepository;
import io.xeres.app.xrs.service.identity.item.IdentityGroupItem;
@@ -143,7 +143,7 @@ void IdentityService_CreateOwnIdentity_Signed_OK() throws PGPException, Certific
void IdentityService_SaveIdentityImage_OK() throws IOException
{
var id = 1L;
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
var file = new MockMultipartFile("file", getClass().getResourceAsStream("/image/leguman.jpg"));
when(gxsIdentityRepository.findById(id)).thenReturn(Optional.of(identity));
@@ -187,7 +187,7 @@ void IdentityService_SaveIdentityImage_ImageTooBig_Error()
void IdentityService_DeleteIdentityImage_OK()
{
var id = 1L;
- var identity = GxsIdFakes.createOwnIdentity();
+ var identity = IdentityFakes.createOwnIdentity();
identity.setImage(new byte[1]);
when(gxsIdentityRepository.findById(id)).thenReturn(Optional.of(identity));
diff --git a/app/src/test/java/io/xeres/app/xrs/serialization/SerializerTest.java b/app/src/test/java/io/xeres/app/xrs/serialization/SerializerTest.java
index 0126d83d4..e6311f629 100644
--- a/app/src/test/java/io/xeres/app/xrs/serialization/SerializerTest.java
+++ b/app/src/test/java/io/xeres/app/xrs/serialization/SerializerTest.java
@@ -21,17 +21,21 @@
import io.netty.buffer.Unpooled;
import io.xeres.app.database.model.gxs.ForumGroupItemFakes;
+import io.xeres.app.database.model.gxs.ForumMessageItemFakes;
import io.xeres.app.database.model.gxs.IdentityGroupItemFakes;
import io.xeres.app.database.model.location.LocationFakes;
+import io.xeres.app.net.protocol.PeerAddress;
import io.xeres.app.xrs.common.Signature;
import io.xeres.app.xrs.common.SignatureSet;
import io.xeres.app.xrs.service.forum.ForumRsService;
import io.xeres.app.xrs.service.forum.item.ForumGroupItem;
+import io.xeres.app.xrs.service.forum.item.ForumMessageItem;
import io.xeres.app.xrs.service.identity.IdentityRsService;
import io.xeres.app.xrs.service.identity.item.IdentityGroupItem;
import io.xeres.common.id.GxsId;
import io.xeres.common.id.LocationId;
import io.xeres.common.id.MessageId;
+import io.xeres.testutils.GxsIdFakes;
import org.apache.commons.lang3.RandomUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -448,7 +452,7 @@ void Serializer_Serialize_TlvKeySignature()
var buf = Unpooled.buffer();
var key = new byte[1];
- var input = new Signature(new GxsId(RandomUtils.nextBytes(16)), key);
+ var input = new Signature(GxsIdFakes.createGxsId(), key);
var size = Serializer.serialize(buf, TlvType.SIGNATURE, input);
assertEquals(6 + 6 + 38 + key.length, size);
@@ -465,7 +469,7 @@ void Serializer_Serialize_TlvKeySignatureSet()
{
var buf = Unpooled.buffer();
var input = new SignatureSet();
- var gxsId = new GxsId(RandomUtils.nextBytes(16));
+ var gxsId = GxsIdFakes.createGxsId();
var signature = RandomUtils.nextBytes(20);
var keySignature = new Signature(gxsId, signature);
input.put(SignatureSet.Type.ADMIN, keySignature);
@@ -514,8 +518,8 @@ void Serializer_Serialize_TlvImage_Empty_Array()
void Serializer_Serialize_TlvSet_GxsId()
{
var buf = Unpooled.buffer();
- var gxsId1 = new GxsId(RandomUtils.nextBytes(GxsId.LENGTH));
- var gxsId2 = new GxsId(RandomUtils.nextBytes(GxsId.LENGTH));
+ var gxsId1 = GxsIdFakes.createGxsId();
+ var gxsId2 = GxsIdFakes.createGxsId();
Set input = new HashSet<>();
input.add(gxsId1);
input.add(gxsId2);
@@ -552,6 +556,24 @@ void Serializer_Serialize_TlvSet_MessageId()
buf.release();
}
+ @Test
+ void Serializer_Serialize_TlvAddress()
+ {
+ var buf = Unpooled.buffer();
+ var peerAddress = PeerAddress.fromAddress("192.168.1.1:1234");
+
+ var size = Serializer.serialize(buf, TlvType.ADDRESS, peerAddress);
+ assertEquals(TLV_HEADER_SIZE * 2 + 6, size);
+
+ var result = (PeerAddress) Serializer.deserialize(buf, TlvType.ADDRESS);
+ assertEquals(PeerAddress.Type.IPV4, result.getType());
+ assertTrue(result.isValid());
+ assertTrue(result.getAddress().isPresent());
+ assertEquals("192.168.1.1:1234", result.getAddress().get());
+
+ buf.release();
+ }
+
@Test
void Serializer_Serialize_IdentityGroupItem()
{
@@ -593,6 +615,26 @@ void Serializer_Serialize_ForumGroupItem()
buf.release();
}
+ @Test
+ void Serializer_Serialize_ForumMessageItem()
+ {
+ var buf = Unpooled.buffer();
+ var forumMessageItem = ForumMessageItemFakes.createForumMessageItem();
+
+ var size = Serializer.serializeGxsMetaAndDataItem(buf, forumMessageItem, EnumSet.noneOf(SerializationFlags.class));
+ assertEquals(162, size);
+
+ var result = new ForumMessageItem();
+ result.setService(new ForumRsService(null, null, null, null, null));
+ Serializer.deserializeGxsMetaAndDataItem(buf, result);
+ assertEquals(forumMessageItem.getGxsId(), result.getGxsId());
+ assertEquals(forumMessageItem.getMessageId(), result.getMessageId());
+ assertEquals(forumMessageItem.getName(), result.getName());
+ assertEquals(forumMessageItem.getPublished().getEpochSecond(), result.getPublished().getEpochSecond());
+
+ buf.release();
+ }
+
@Test
void Serializer_Serialize_ComplexObject()
{
diff --git a/app/src/test/java/io/xeres/app/xrs/service/chat/ChatRsServiceTest.java b/app/src/test/java/io/xeres/app/xrs/service/chat/ChatRsServiceTest.java
index 03a810919..4cccbe26d 100644
--- a/app/src/test/java/io/xeres/app/xrs/service/chat/ChatRsServiceTest.java
+++ b/app/src/test/java/io/xeres/app/xrs/service/chat/ChatRsServiceTest.java
@@ -20,7 +20,7 @@
package io.xeres.app.xrs.service.chat;
import io.xeres.app.database.DatabaseSessionManager;
-import io.xeres.app.database.model.identity.GxsIdFakes;
+import io.xeres.app.database.model.identity.IdentityFakes;
import io.xeres.app.database.model.location.LocationFakes;
import io.xeres.app.net.peer.PeerConnection;
import io.xeres.app.net.peer.PeerConnectionManager;
@@ -124,7 +124,7 @@ void ChatService_HandleChatRoomListRequestItem_OK()
var item = new ChatRoomListRequestItem();
- when(identityService.getOwnIdentity()).thenReturn(GxsIdFakes.createOwnIdentity());
+ when(identityService.getOwnIdentity()).thenReturn(IdentityFakes.createOwnIdentity());
var roomId = chatRsService.createChatRoom("test", "test topic", EnumSet.of(RoomFlags.PUBLIC), false);
chatRsService.handleItem(peerConnection, item);
diff --git a/app/src/test/java/io/xeres/app/xrs/service/gxs/TransactionTest.java b/app/src/test/java/io/xeres/app/xrs/service/gxs/TransactionTest.java
new file mode 100644
index 000000000..ca6e9e22b
--- /dev/null
+++ b/app/src/test/java/io/xeres/app/xrs/service/gxs/TransactionTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2023 by David Gerber - https://zapek.com
+ *
+ * This file is part of Xeres.
+ *
+ * Xeres is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xeres is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xeres. If not, see .
+ */
+
+package io.xeres.app.xrs.service.gxs;
+
+import io.xeres.app.xrs.service.gxs.item.GxsSyncGroupItem;
+import io.xeres.app.xrs.service.gxs.item.TransactionFlags;
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class TransactionTest
+{
+ @Test
+ void Transaction_AddItems_OK()
+ {
+ var transaction = new Transaction(1, EnumSet.noneOf(TransactionFlags.class), new ArrayList<>(), 2, null, Transaction.Direction.INCOMING);
+
+ transaction.addItem(new GxsSyncGroupItem());
+ transaction.addItem(new GxsSyncGroupItem());
+
+ assertEquals(1, transaction.getId());
+ assertFalse(transaction.hasTimeout());
+ assertTrue(transaction.hasAllItems());
+ }
+}
diff --git a/common/build.gradle b/common/build.gradle
index 43bdd7387..2bc436af7 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -55,4 +55,5 @@ dependencies {
testFixturesImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: "com.vaadin.external.google", module: "android-json"
}
+ testFixturesImplementation 'org.apache.commons:commons-lang3'
}
diff --git a/common/src/testFixtures/java/io/xeres/testutils/GxsIdFakes.java b/common/src/testFixtures/java/io/xeres/testutils/GxsIdFakes.java
new file mode 100644
index 000000000..7ff386b34
--- /dev/null
+++ b/common/src/testFixtures/java/io/xeres/testutils/GxsIdFakes.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023 by David Gerber - https://zapek.com
+ *
+ * This file is part of Xeres.
+ *
+ * Xeres is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xeres is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xeres. If not, see .
+ */
+
+package io.xeres.testutils;
+
+import io.xeres.common.id.GxsId;
+import org.apache.commons.lang3.RandomUtils;
+
+public final class GxsIdFakes
+{
+ private GxsIdFakes()
+ {
+ throw new UnsupportedOperationException("Utility class");
+ }
+
+ public static GxsId createGxsId()
+ {
+ return new GxsId(RandomUtils.nextBytes(16));
+ }
+}
diff --git a/ui/src/main/java/io/xeres/ui/support/chat/ChatAction.java b/ui/src/main/java/io/xeres/ui/support/chat/ChatAction.java
index 548433768..e3f6d163e 100644
--- a/ui/src/main/java/io/xeres/ui/support/chat/ChatAction.java
+++ b/ui/src/main/java/io/xeres/ui/support/chat/ChatAction.java
@@ -83,16 +83,24 @@ public String getGxsId()
return gxsId;
}
- public boolean hasMessageLine()
+ /**
+ * Checks if it's a presence event. Those events don't have any user content (the user cannot say anything in them).
+ * @return true if it's a presence event (join, leave or timeout).
+ */
+ public boolean isPresenceEvent()
{
return Stream.of(JOIN, LEAVE, TIMEOUT).anyMatch(v -> type == v);
}
- public String getMessageLine()
+ /**
+ * Gets a presence content, to put in a line.
+ * @return the presence content
+ */
+ public String getPresenceLine()
{
- if (!hasMessageLine())
+ if (!isPresenceEvent())
{
- throw new IllegalStateException("no message line available, type: " + type);
+ throw new IllegalStateException("no presence line available, type: " + type);
}
var reason = "";
if (type == TIMEOUT)
diff --git a/ui/src/main/java/io/xeres/ui/support/chat/ChatLine.java b/ui/src/main/java/io/xeres/ui/support/chat/ChatLine.java
index 9da46ef32..8324549fc 100644
--- a/ui/src/main/java/io/xeres/ui/support/chat/ChatLine.java
+++ b/ui/src/main/java/io/xeres/ui/support/chat/ChatLine.java
@@ -41,13 +41,13 @@ public ChatLine(Instant instant, ChatAction action, Content... contents)
{
this.instant = instant;
this.action = action;
- if (action.hasMessageLine())
+ if (action.isPresenceEvent())
{
if (log.isDebugEnabled() && contents.length > 0)
{
log.debug("Chat content for action {} is not needed", action);
}
- this.contents = List.of(new ContentText(action.getMessageLine()));
+ this.contents = List.of(new ContentText(action.getPresenceLine()));
}
else
{
diff --git a/ui/src/test/java/io/xeres/ui/support/chat/ChatActionTest.java b/ui/src/test/java/io/xeres/ui/support/chat/ChatActionTest.java
new file mode 100644
index 000000000..23c3431da
--- /dev/null
+++ b/ui/src/test/java/io/xeres/ui/support/chat/ChatActionTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2023 by David Gerber - https://zapek.com
+ *
+ * This file is part of Xeres.
+ *
+ * Xeres is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xeres is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xeres. If not, see .
+ */
+
+package io.xeres.ui.support.chat;
+
+import io.xeres.testutils.GxsIdFakes;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ChatActionTest
+{
+ @Test
+ void ChatAction_HasMessageLine_OK()
+ {
+ var gxsId = GxsIdFakes.createGxsId();
+ var action = new ChatAction(ChatAction.Type.JOIN, "Foobar", gxsId);
+
+ assertTrue(action.isPresenceEvent());
+ assertEquals("Foobar (" + gxsId + ")", action.getPresenceLine());
+ }
+
+ @Test
+ void ChatAction_HasMessageLine_None()
+ {
+ var action = new ChatAction(ChatAction.Type.SAY, "Foobar", GxsIdFakes.createGxsId());
+
+ assertFalse(action.isPresenceEvent());
+ }
+}
diff --git a/ui/src/test/java/io/xeres/ui/support/util/UiUtilsTest.java b/ui/src/test/java/io/xeres/ui/support/util/UiUtilsTest.java
new file mode 100644
index 000000000..fda4ccff5
--- /dev/null
+++ b/ui/src/test/java/io/xeres/ui/support/util/UiUtilsTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2023 by David Gerber - https://zapek.com
+ *
+ * This file is part of Xeres.
+ *
+ * Xeres is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Xeres is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xeres. If not, see .
+ */
+
+package io.xeres.ui.support.util;
+
+import io.xeres.testutils.TestUtils;
+import org.junit.jupiter.api.Test;
+
+class UiUtilsTest
+{
+ @Test
+ void UiUtils_NoInstance_OK() throws NoSuchMethodException
+ {
+ TestUtils.assertUtilityClass(UiUtils.class);
+ }
+}