From 3a68a2f0a665e8e0c911fbb6324edb6c3ec96a04 Mon Sep 17 00:00:00 2001
From: Sonia Zorba <sonia.zorba@inaf.it>
Date: Sun, 15 Nov 2020 11:46:26 +0100
Subject: [PATCH] Bugfix Root name

---
 .../src/main/java/it/inaf/ia2/gms/cli/CLI.java       |  8 +++++---
 .../it/inaf/ia2/gms/service/GroupNameService.java    |  4 ++--
 gms/src/main/resources/application.properties        |  1 -
 .../manager/PermissionsManagerIntegrationTest.java   |  2 +-
 .../inaf/ia2/gms/service/GroupNameServiceTest.java   | 12 +++++++++++-
 .../it/inaf/ia2/gms/service/SearchServiceTest.java   |  4 ++--
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/gms-client/gms-cli/src/main/java/it/inaf/ia2/gms/cli/CLI.java b/gms-client/gms-cli/src/main/java/it/inaf/ia2/gms/cli/CLI.java
index 118e2be..71b413b 100644
--- a/gms-client/gms-cli/src/main/java/it/inaf/ia2/gms/cli/CLI.java
+++ b/gms-client/gms-cli/src/main/java/it/inaf/ia2/gms/cli/CLI.java
@@ -4,6 +4,7 @@ import it.inaf.ia2.client.ClientException;
 import it.inaf.ia2.gms.client.GmsClient;
 import it.inaf.ia2.gms.client.model.Permission;
 import it.inaf.ia2.rap.client.RapClient;
+import it.inaf.ia2.rap.data.AccessTokenResponse;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -106,11 +107,12 @@ public class CLI {
 
         if (token != null) {
             client.setAccessToken(token);
-        } else {            
+        } else {
             RapClient rapClient = new RapClient(rapBaseUrl)
                     .setClientId(clientId)
-                    .setClientSecret(clientSecret);            
-            client.setAccessToken(rapClient.getAccessTokenFromClientCredentials());
+                    .setClientSecret(clientSecret);
+            AccessTokenResponse accessTokenResponse = rapClient.getAccessTokenFromClientCredentials();
+            client.setAccessToken(accessTokenResponse.getAccessToken());
         }
     }
 
diff --git a/gms/src/main/java/it/inaf/ia2/gms/service/GroupNameService.java b/gms/src/main/java/it/inaf/ia2/gms/service/GroupNameService.java
index be619b1..fc90618 100644
--- a/gms/src/main/java/it/inaf/ia2/gms/service/GroupNameService.java
+++ b/gms/src/main/java/it/inaf/ia2/gms/service/GroupNameService.java
@@ -47,7 +47,7 @@ public class GroupNameService {
 
         List<String> names = new ArrayList<>(groupsDAO.getGroupCompleteNamesFromId(groupIds).values());
         if (groupIds.contains("ROOT")) {
-            names.add("Root");
+            names.add(getRoot().getName());
         }
 
         Collections.sort(names);
@@ -72,7 +72,7 @@ public class GroupNameService {
         Map<String, List<String>> result = new HashMap<>();
 
         if (groupIds.contains("ROOT")) {
-            result.put("ROOT", Collections.singletonList("Root"));
+            result.put("ROOT", Collections.singletonList(getRoot().getName()));
         }
 
         for (Map.Entry<String, String> entry : groupsDAO.getGroupCompleteNamesFromId(groupIds).entrySet()) {
diff --git a/gms/src/main/resources/application.properties b/gms/src/main/resources/application.properties
index 3428af2..5eaf826 100644
--- a/gms/src/main/resources/application.properties
+++ b/gms/src/main/resources/application.properties
@@ -13,7 +13,6 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
 spring.datasource.username=gms
 spring.datasource.password=gms
 
-rap.ws-url=http://localhost/rap-ia2/ws
 support.contact.label=IA2 team
 support.contact.email=ia2@inaf.it
 
diff --git a/gms/src/test/java/it/inaf/ia2/gms/manager/PermissionsManagerIntegrationTest.java b/gms/src/test/java/it/inaf/ia2/gms/manager/PermissionsManagerIntegrationTest.java
index 93190b4..b0b7360 100644
--- a/gms/src/test/java/it/inaf/ia2/gms/manager/PermissionsManagerIntegrationTest.java
+++ b/gms/src/test/java/it/inaf/ia2/gms/manager/PermissionsManagerIntegrationTest.java
@@ -62,7 +62,7 @@ public class PermissionsManagerIntegrationTest {
         // Create root
         GroupEntity root = new GroupEntity();
         root.setId("ROOT");
-        root.setName("Root");
+        root.setName("ROOT");
         root.setPath("");
         root = groupsDAO.createGroup(root);
 
diff --git a/gms/src/test/java/it/inaf/ia2/gms/service/GroupNameServiceTest.java b/gms/src/test/java/it/inaf/ia2/gms/service/GroupNameServiceTest.java
index 2b4b74c..6b4b946 100644
--- a/gms/src/test/java/it/inaf/ia2/gms/service/GroupNameServiceTest.java
+++ b/gms/src/test/java/it/inaf/ia2/gms/service/GroupNameServiceTest.java
@@ -8,11 +8,13 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import static org.mockito.Mockito.when;
@@ -58,12 +60,20 @@ public class GroupNameServiceTest {
 
         when(groupsDAO.getGroupCompleteNamesFromId(any())).thenReturn(new HashMap<>());
 
+        GroupEntity root = new GroupEntity();
+        root.setId("ROOT");
+        root.setName("ROOT");
+        root.setPath("");
+
+        when(groupsDAO.findGroupById(eq("ROOT")))
+                .thenReturn(Optional.of(root));
+
         List<Map.Entry<String, String>> groupsIdPath = new ArrayList<>();
         groupsIdPath.add(new AbstractMap.SimpleEntry<>("ROOT", ""));
 
         Map<String, List<String>> names = groupNameService.getNamesFromIds(groupIds);
         assertEquals(1, names.size());
         assertEquals(1, names.get("ROOT").size());
-        assertEquals("Root", names.get("ROOT").get(0));
+        assertEquals("ROOT", names.get("ROOT").get(0));
     }
 }
diff --git a/gms/src/test/java/it/inaf/ia2/gms/service/SearchServiceTest.java b/gms/src/test/java/it/inaf/ia2/gms/service/SearchServiceTest.java
index 72b06ce..de6961a 100644
--- a/gms/src/test/java/it/inaf/ia2/gms/service/SearchServiceTest.java
+++ b/gms/src/test/java/it/inaf/ia2/gms/service/SearchServiceTest.java
@@ -69,7 +69,7 @@ public class SearchServiceTest {
                 List<String> names = new ArrayList<>();
                 switch (group.getId()) {
                     case "ROOT":
-                        names.add("Root");
+                        names.add("ROOT");
                         break;
                     case "group1_id":
                         names.add("Group 1");
@@ -169,7 +169,7 @@ public class SearchServiceTest {
 
         GroupEntity root = new GroupEntity();
         root.setId("ROOT");
-        root.setName("Root");
+        root.setName("ROOT");
         root.setPath("");
         when(groupsManager.getRoot()).thenReturn(root);
 
-- 
GitLab