From 970202cd6e322a5def7784710a452f86ce1e0a67 Mon Sep 17 00:00:00 2001 From: Aashir Siddiqui Date: Tue, 13 Aug 2024 10:09:26 +0100 Subject: [PATCH] Added mock env Signed-off-by: Aashir Siddiqui --- .../framework/api/users/mocks/MockUsersServlet.java | 5 +++++ .../galasa/framework/api/users/routes/UsersRouteTest.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/mocks/MockUsersServlet.java b/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/mocks/MockUsersServlet.java index 9fc84f7ad..bf567f397 100644 --- a/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/mocks/MockUsersServlet.java +++ b/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/mocks/MockUsersServlet.java @@ -5,11 +5,16 @@ */ package dev.galasa.framework.api.users.mocks; +import dev.galasa.framework.api.common.Environment; import dev.galasa.framework.api.users.UsersServlet; import dev.galasa.framework.spi.IFramework; public class MockUsersServlet extends UsersServlet{ + public void setEnvironment(Environment env) { + this.env = env; + } + @Override public void setFramework(IFramework framework) { super.setFramework(framework); diff --git a/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/routes/UsersRouteTest.java b/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/routes/UsersRouteTest.java index 79ef468eb..1bf7afe5a 100644 --- a/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/routes/UsersRouteTest.java +++ b/galasa-parent/dev.galasa.framework.api.users/src/test/java/dev/galasa/framework/api/users/routes/UsersRouteTest.java @@ -14,9 +14,12 @@ import org.junit.Test; import dev.galasa.framework.api.common.BaseServletTest; +import dev.galasa.framework.api.common.EnvironmentVariables; +import dev.galasa.framework.api.common.mocks.MockEnvironment; import dev.galasa.framework.api.common.mocks.MockHttpServletRequest; import dev.galasa.framework.api.common.mocks.MockHttpServletResponse; import dev.galasa.framework.api.users.UsersServlet; +import dev.galasa.framework.api.users.mocks.MockUsersServlet; public class UsersRouteTest extends BaseServletTest { @@ -53,7 +56,10 @@ public void testUsersGetRequestWithMissingNameParamReturnsBadRequest() throws Ex @Test public void testUsersGetRequestReturnsArrayOfUsersReturns_OK() throws Exception { // Given... - UsersServlet servlet = new UsersServlet(); + MockUsersServlet servlet = new MockUsersServlet(); + MockEnvironment env = new MockEnvironment(); + env.setenv(EnvironmentVariables.GALASA_USERNAME_CLAIMS, "preferred_username"); + servlet.setEnvironment(env); String requestorLoginId = "me";