Skip to content
Snippets Groups Projects
Commit 8efc1978 authored by Martin Staehr's avatar Martin Staehr
Browse files

#63 feat: implement getChatRoomName

parent b83270cf
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ public class CommunicationDummyService implements ICommunication {
@Override
public List<ChatMessage> getChatHistory(String roomId) {
//TODO : not needed at the moment, possibly remove
ArrayList<ChatMessage> chatMessages = new ArrayList<>();
int maxValue = 6;
for (int i = 1; i <= maxValue; i++) {
......@@ -139,7 +140,26 @@ public class CommunicationDummyService implements ICommunication {
@Override
public String getChatRoomName(String roomId) {
return Strings.EMPTY;
Map<String, String> headerMap = new RocketChatHeaderMapBuilder().withRocketChatAdminAuth().build();
HttpResponse<Map> response =
unirestService
.get(ROCKET_CHAT_API_LINK + "groups.info")
.headers(headerMap)
.queryString("roomId", roomId).asObject(Map.class);
if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode()
|| response.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
return Strings.EMPTY;
}
Map responseMap = response.getBody();
if (responseMap.containsKey("error")) {
return Strings.EMPTY;
}
Map groupMap = (Map) responseMap.get("group");
return groupMap.get("name").toString();
}
@Override
......
......@@ -3,6 +3,8 @@ package unipotsdam.gf.modules.communication.util;
import java.util.HashMap;
import java.util.Map;
import static unipotsdam.gf.config.GFRocketChatConfig.ADMIN_USER;
public class RocketChatHeaderMapBuilder {
private Map<String, String> headerMap;
......@@ -21,6 +23,11 @@ public class RocketChatHeaderMapBuilder {
return this;
}
public RocketChatHeaderMapBuilder withRocketChatAdminAuth() {
RocketChatHeaderMapBuilder rocketChatHeaderMapBuilder = withAuthTokenHeader(ADMIN_USER.getRocketChatPersonalAccessToken());
return rocketChatHeaderMapBuilder.withRocketChatUserId(ADMIN_USER.getRocketChatUserId());
}
public Map<String, String> build() {
return headerMap;
}
......
......@@ -7,6 +7,7 @@ import unipotsdam.gf.core.management.user.User;
import unipotsdam.gf.core.management.user.UserDAO;
import unipotsdam.gf.interfaces.ICommunication;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
......@@ -47,11 +48,24 @@ public class CommunicationDummyServiceTest {
@Test
public void createEmptyChatRoom() {
String chatRoom = iCommunication.createEmptyChatRoom("Test", false);
assertFalse(chatRoom.isEmpty());
assertNotNull(chatRoom);
assertFalse(chatRoom.isEmpty());
String chatRoomReadOnly = iCommunication.createEmptyChatRoom("Test2", true);
assertFalse(chatRoomReadOnly.isEmpty());
assertNotNull(chatRoomReadOnly);
assertFalse(chatRoomReadOnly.isEmpty());
}
@Test
public void getChatRoomName() {
String expectedChatRoomName = "ChatRoomName";
String chatRoomId = iCommunication.createEmptyChatRoom(expectedChatRoomName, false);
assertNotNull(chatRoomId);
assertFalse(chatRoomId.isEmpty());
String actualChatRoomName = iCommunication.getChatRoomName(chatRoomId);
assertEquals(expectedChatRoomName, actualChatRoomName);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment