+* WSO2 LLC. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +*
+* http://www.apache.org/licenses/LICENSE-2.0 +*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.wso2.financial.services.accelerator.gateway;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Constants for Gateway test cases.
+ */
+public class GatewayTestConstants {
+
+ public static final String VALID_EXECUTOR_CLASS =
+ "org.wso2.financial.services.accelerator.gateway.executor.core.MockOBExecutor";
+ public static final Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import io.swagger.v3.oas.models.OpenAPI;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.financial.services.accelerator.common.util.FinancialServicesUtils;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test for default request router.
+ */
+public class DefaultRequestRouterTest {
+
+ DefaultRequestRouter defaultRequestRouter;
+ OpenAPI openAPI;
+
+ @BeforeClass
+ public void beforeClass() {
+
+ defaultRequestRouter = new DefaultRequestRouter();
+ defaultRequestRouter.setExecutorMap(initExecutors());
+ openAPI = new OpenAPI();
+ openAPI.setExtensions(new HashMap<>());
+ }
+
+ @Test(priority = 1)
+ public void testDCRRequestsForRouter() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall/register");
+ Mockito.when(obapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Mockito.when(obapiRequestContext.getOpenAPI()).thenReturn(openAPI);
+ Mockito.when(obapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForRequest(obapiRequestContext));
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForResponse(obapiResponseContext));
+
+ }
+
+ @Test(priority = 1)
+ public void testAccountRequestsForRouter() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall");
+ Mockito.when(obapiRequestContext.getOpenAPI()).thenReturn(openAPI);
+ Mockito.when(obapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Mockito.when(obapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForRequest(obapiRequestContext));
+ Assert.assertNotNull(defaultRequestRouter.getExecutorsForResponse(obapiResponseContext));
+ }
+
+ @Test(priority = 2)
+ public void testNonRegulatoryAPIcall() {
+
+ FSAPIRequestContext obapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ FSAPIResponseContext obapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setResource("/anyAPIcall");
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.mockito.Mockito;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseDTO;
+import org.wso2.carbon.apimgt.common.gateway.dto.ExtensionResponseStatus;
+import org.wso2.carbon.apimgt.common.gateway.dto.MsgInfoDTO;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+import org.wso2.financial.services.accelerator.gateway.util.GatewayConstants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test for open Banking extension implementation.
+ */
+public class FSExtensionImplTest {
+
+ private static FSAPIRequestContext fsapiRequestContext;
+ private static FSAPIResponseContext fsapiResponseContext;
+ private static final FSExtensionListenerImpl fsExtensionListener = new FSExtensionListenerImpl();
+
+ @BeforeClass
+ public static void beforeClass() {
+
+ }
+
+ @Test(priority = 1)
+ public void testMinimumFlow() {
+
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setHeaders(new HashMap<>());
+
+ fsapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ Mockito.when(fsapiRequestContext.isError()).thenReturn(false);
+ Mockito.when(fsapiRequestContext.getModifiedPayload()).thenReturn(null);
+ Mockito.when(fsapiRequestContext.getAddedHeaders()).thenReturn(new HashMap<>());
+ Mockito.when(fsapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+
+ fsapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ Mockito.when(fsapiResponseContext.isError()).thenReturn(false);
+ Mockito.when(fsapiResponseContext.getModifiedPayload()).thenReturn(null);
+ Mockito.when(fsapiResponseContext.getAddedHeaders()).thenReturn(new HashMap<>());
+ Mockito.when(fsapiResponseContext.getMsgInfo()).thenReturn(msgInfoDTO);
+
+ ExtensionResponseDTO responseDTOForRequest = fsExtensionListener.getResponseDTOForRequest(fsapiRequestContext);
+ Assert.assertEquals(responseDTOForRequest.getResponseStatus(), ExtensionResponseStatus.CONTINUE.toString());
+ Assert.assertNull(responseDTOForRequest.getHeaders());
+ Assert.assertNull(responseDTOForRequest.getPayload());
+ Assert.assertNull(responseDTOForRequest.getCustomProperty());
+ Assert.assertEquals(responseDTOForRequest.getStatusCode(), 0);
+
+ ExtensionResponseDTO responseDTOForResponse =
+ fsExtensionListener.getResponseDTOForResponse(fsapiResponseContext);
+
+ Assert.assertEquals(responseDTOForResponse.getResponseStatus(), ExtensionResponseStatus.CONTINUE.toString());
+ Assert.assertNull(responseDTOForResponse.getHeaders());
+ Assert.assertNull(responseDTOForResponse.getPayload());
+ Assert.assertNull(responseDTOForResponse.getCustomProperty());
+ Assert.assertEquals(responseDTOForResponse.getStatusCode(), 0);
+
+ }
+
+ @Test(priority = 1)
+ public void testAddedHeaders() {
+
+ fsapiRequestContext = Mockito.mock(FSAPIRequestContext.class);
+ fsapiResponseContext = Mockito.mock(FSAPIResponseContext.class);
+ Mockito.when(fsapiRequestContext.isError()).thenReturn(false);
+ Mockito.when(fsapiRequestContext.getModifiedPayload()).thenReturn(null);
+ MsgInfoDTO msgInfoDTO = new MsgInfoDTO();
+ msgInfoDTO.setHeaders(new HashMap<>());
+ Mockito.when(fsapiRequestContext.getMsgInfo()).thenReturn(msgInfoDTO);
+ Map
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.executor.core;
+
+
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIRequestContext;
+import org.wso2.financial.services.accelerator.gateway.executor.model.FSAPIResponseContext;
+
+/**
+ * Mock Open banking executor for testing.
+ */
+public class MockOBExecutor implements FinancialServicesGatewayExecutor {
+
+ @Override
+ public void preProcessRequest(FSAPIRequestContext fsapiRequestContext) {
+
+ fsapiRequestContext.setModifiedPayload("{}");
+ }
+
+ /**
+ * Method to handle post request.
+ *
+ * @param fsapiRequestContext FS request context object
+ */
+ @Override
+ public void postProcessRequest(FSAPIRequestContext fsapiRequestContext) {
+
+ }
+
+
+ /**
+ * Method to handle pre response.
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ @Override
+ public void preProcessResponse(FSAPIResponseContext fsapiResponseContext) {
+
+ }
+
+ /**
+ * Method to handle post response.
+ *
+ * @param fsapiResponseContext FS response context object
+ */
+ @Override
+ public void postProcessResponse(FSAPIResponseContext fsapiResponseContext) {
+
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java
new file mode 100644
index 00000000..bf07c177
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/java/org/wso2/financial/services/accelerator/gateway/util/GatewayUtilsTest.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * WSO2 LLC. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.wso2.financial.services.accelerator.gateway.util;
+
+import org.json.JSONObject;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import org.wso2.financial.services.accelerator.gateway.GatewayTestConstants;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * Test class for Gateway utility methods.
+ */
+public class GatewayUtilsTest {
+
+ @Test(priority = 1)
+ public void testIsValidJWTToken() {
+
+ Assert.assertTrue(GatewayUtils.isValidJWTToken(GatewayTestConstants.TEST_JWT));
+ }
+
+ @Test(priority = 2)
+ public void testB64Encode() throws UnsupportedEncodingException {
+
+ JSONObject payload = GatewayUtils.decodeBase64(GatewayTestConstants.B64_PAYLOAD);
+ Assert.assertEquals(payload.getString("sub"), "1234567890");
+ Assert.assertEquals(payload.getString("name"), "John Doe");
+ Assert.assertEquals(payload.getInt("iat"), 1516239022);
+ }
+
+ @Test(priority = 3)
+ public void testBasicAuthHeader() {
+
+ Assert.assertEquals(GatewayUtils.getBasicAuthHeader("admin", "admin"),
+ "Basic YWRtaW46YWRtaW4=");
+ }
+
+ @Test(priority = 4)
+ public void testGetTextPayload() {
+
+ Assert.assertEquals(GatewayUtils.getTextPayload(GatewayTestConstants.XML_PAYLOAD), "Test Content");
+ }
+
+ @Test (priority = 5)
+ public void testIsEligibleRequest() {
+
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleRequest(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ }
+
+ @Test (priority = 6)
+ public void testIsEligibleResponse() {
+
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.POST_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.PUT_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.JSON_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.APPLICATION_XML_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ Assert.assertTrue(GatewayUtils.isEligibleResponse(GatewayConstants.TEXT_XML_CONTENT_TYPE,
+ GatewayConstants.GET_HTTP_METHOD));
+ }
+
+ @Test(priority = 7)
+ public void testJWTPayloadLoad() {
+
+ Assert.assertEquals(GatewayUtils.getPayloadFromJWT(GatewayTestConstants.TEST_JWT),
+ GatewayTestConstants.B64_PAYLOAD);
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml
index 5749fe3c..8e4cd5f5 100644
--- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.gateway/src/test/resources/testng.xml
@@ -19,5 +19,10 @@