From e710ed6237477f725002823b203842e25705a759 Mon Sep 17 00:00:00 2001 From: marounkoussaifi Date: Tue, 13 Apr 2021 17:16:31 +0200 Subject: [PATCH 1/2] Fix RMConnectionHelper Tests --- .../morphemic/service/RMConnectionHelper.java | 6 ++++-- .../morphemic/service/RMConnectionHelperTest.java | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/service/RMConnectionHelper.java b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/service/RMConnectionHelper.java index 29c7cf38..c667f106 100644 --- a/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/service/RMConnectionHelper.java +++ b/scheduling-abstraction-layer/src/main/java/org/activeeon/morphemic/service/RMConnectionHelper.java @@ -33,10 +33,12 @@ public class RMConnectionHelper { * @return The initialized RM Interface to be used for sending request to the platform */ public static RMRestInterface init(String paURL) { - if(paURL.contains("trydev2")){ + if(paURL.contains("trydev2.activeeon")){ sessionPreferencesId = "RM_sessionId_trydev2"; - }else{ + }else if(paURL.contains("trydev.activeeon")){ sessionPreferencesId = "RM_sessionId"; + }else{ + sessionPreferencesId = "TESTING_PREF"; } // Initialize the client rmRestInterface = new RMRestClient(paURL + RESOURCE_MANAGER_REST_PATH, null).getRm(); diff --git a/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java b/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java index 65329284..1a5c343c 100644 --- a/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java +++ b/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java @@ -14,6 +14,7 @@ import org.ow2.proactive_grid_cloud_portal.common.RMRestInterface; import javax.security.auth.login.LoginException; import java.security.KeyException; +import java.util.prefs.Preferences; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -58,10 +59,8 @@ class RMConnectionHelperTest { // Inject the current mocked RM Interface to the RMConnectionHelper class RMConnectionHelper.setRmRestInterface(rmRestInterface); - // Initialize a testing user preference variable - // It is used to store the session - String DUMMY_PREFERENCE_ID = "TESTING_PREF"; - RMConnectionHelper.setSessionPreferencesId(DUMMY_PREFERENCE_ID); + Preferences userPreferences = Preferences.userRoot().node("USER_PREFERENCES"); + userPreferences.remove("TESTING_PREF"); // Temporary disable all Logging from the RMConnectionHelper class // It is enabled after the tests are completed @@ -79,7 +78,7 @@ class RMConnectionHelperTest { RMRestInterface initRMRestInterface = RMConnectionHelper.init(DUMMY_CONNECTION_URL); String DUMMY_RM_INTERFACE_MESSAGE = "org.ow2.proactive_grid_cloud_portal.common.RMRestInterface"; assertTrue(initRMRestInterface.toString().contains(DUMMY_RM_INTERFACE_MESSAGE)); - assertEquals(RMConnectionHelper.getSessionId(), ""); + assertEquals("", RMConnectionHelper.getSessionId()); } /** @@ -94,6 +93,7 @@ class RMConnectionHelperTest { */ @Test void connect() throws LoginException, KeyException, RMException { + RMConnectionHelper.setSessionPreferencesId("TESTING_PREF"); RMConnectionHelper.connect(DUMMY_USERNAME,DUMMY_PASSWORD); assertEquals(DUMMY_SESSION_ID,RMConnectionHelper.getSessionId()); } @@ -104,6 +104,7 @@ class RMConnectionHelperTest { */ @Test void disconnect() { + RMConnectionHelper.setSessionPreferencesId("TESTING_PREF"); RMConnectionHelper.disconnect(); assertEquals("", RMConnectionHelper.getSessionId()); } -- GitLab From cab3b93c36ee09bca3dff405a8a2e9218ca68a07 Mon Sep 17 00:00:00 2001 From: marounkoussaifi Date: Tue, 13 Apr 2021 17:28:22 +0200 Subject: [PATCH 2/2] Fix reviewer's comments --- .../activeeon/morphemic/service/RMConnectionHelperTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java b/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java index 1a5c343c..57cea96e 100644 --- a/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java +++ b/scheduling-abstraction-layer/src/test/java/org/activeeon/morphemic/service/RMConnectionHelperTest.java @@ -28,6 +28,8 @@ class RMConnectionHelperTest { private final String DUMMY_SESSION_ID = "SESSION_ID"; + private final Preferences userPreferences = Preferences.userRoot().node("USER_PREFERENCES"); + @Mock RMRestInterface rmRestInterface; @@ -59,7 +61,6 @@ class RMConnectionHelperTest { // Inject the current mocked RM Interface to the RMConnectionHelper class RMConnectionHelper.setRmRestInterface(rmRestInterface); - Preferences userPreferences = Preferences.userRoot().node("USER_PREFERENCES"); userPreferences.remove("TESTING_PREF"); // Temporary disable all Logging from the RMConnectionHelper class @@ -125,5 +126,6 @@ class RMConnectionHelperTest { @AfterEach void enableLogging() { Logger.getLogger(RMConnectionHelper.class).setLevel(Level.ALL); + userPreferences.remove("TESTING_PREF"); } } \ No newline at end of file -- GitLab