Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Accelerator 4] Adding Accelerator Gateway Implementation #127

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@
<groupId>org.wso2.financial.services.accelerator</groupId>
<artifactId>org.wso2.financial.services.accelerator.common</artifactId>
</dependency>
<!-- Unit Test Dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -118,6 +134,11 @@
<exclude>**/*Constants.class</exclude>
<exclude>**/*Component.class</exclude>
<exclude>**/*DataHolder.class</exclude>
<exclude>**/*Cache.class</exclude>
<exclude>**/*CacheKey.class</exclude>
<exclude>**/*APIRequestContext.class</exclude>
<exclude>**/*APIResponseContext.class</exclude>
<exclude>**/*ExecutorError.class</exclude>
</excludes>
</configuration>
<executions>
Expand Down Expand Up @@ -158,8 +179,7 @@
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<!-- TODO:Adding from another PR-->
<!-- <minimum>0.8</minimum>-->
<minimum>0.8</minimum>
</limit>
</limits>
</rule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ExtensionResponseDTO preProcessRequest(RequestContextDTO requestContextDT
@Generated(message = "Ignoring since the method has covered in other tests")
public ExtensionResponseDTO postProcessRequest(RequestContextDTO requestContextDTO) {

Map<String, Object> contextProps = getPropertiesFromCache(requestContextDTO.getMsgInfo().getMessageId() +
Map<String, String> contextProps = getPropertiesFromCache(requestContextDTO.getMsgInfo().getMessageId() +
GatewayConstants.CONTEXT_PROP_CACHE_KEY);

FSAPIRequestContext fsapiRequestContext = new FSAPIRequestContext(requestContextDTO, contextProps);
Expand All @@ -91,7 +91,7 @@ public ExtensionResponseDTO postProcessRequest(RequestContextDTO requestContextD
@Generated(message = "Ignoring since the method has covered in other tests")
public ExtensionResponseDTO preProcessResponse(ResponseContextDTO responseContextDTO) {

Map<String, Object> contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() +
Map<String, String> contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() +
GatewayConstants.CONTEXT_PROP_CACHE_KEY);
FSAPIResponseContext fsapiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps);
for (FinancialServicesGatewayExecutor gatewayExecutor :
Expand All @@ -113,7 +113,7 @@ public ExtensionResponseDTO preProcessResponse(ResponseContextDTO responseContex
@Generated(message = "Ignoring since the method has covered in other tests")
public ExtensionResponseDTO postProcessResponse(ResponseContextDTO responseContextDTO) {

Map<String, Object> contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() +
Map<String, String> contextProps = getPropertiesFromCache(responseContextDTO.getMsgInfo().getMessageId() +
GatewayConstants.CONTEXT_PROP_CACHE_KEY);
FSAPIResponseContext fsapiResponseContext = new FSAPIResponseContext(responseContextDTO, contextProps);
for (FinancialServicesGatewayExecutor gatewayExecutor :
Expand Down Expand Up @@ -145,13 +145,13 @@ protected ExtensionResponseDTO getResponseDTOForRequest(FSAPIRequestContext fsap
extensionResponseDTO.setStatusCode(statusCode);
extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString());
} else if (fsapiRequestContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) &&
(boolean) (fsapiRequestContext.getContextProps().get(GatewayConstants.IS_RETURN_RESPONSE))) {
Boolean.parseBoolean(fsapiRequestContext.getContextProps().get(GatewayConstants.IS_RETURN_RESPONSE))) {
Map<String, String> headers = fsapiRequestContext.getMsgInfo().getHeaders();
headers.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE);
fsapiRequestContext.getMsgInfo().setHeaders(headers);
extensionResponseDTO.setHeaders(headers);
if (fsapiRequestContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) {
extensionResponseDTO.setStatusCode((int) (fsapiRequestContext.getContextProps()
extensionResponseDTO.setStatusCode(Integer.parseInt(fsapiRequestContext.getContextProps()
.get(GatewayConstants.MODIFIED_STATUS)));
}
extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString());
Expand Down Expand Up @@ -185,14 +185,14 @@ protected ExtensionResponseDTO getResponseDTOForResponse(FSAPIResponseContext fs
extensionResponseDTO.setStatusCode(statusCode);
extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString());
} else if (fsapiResponseContext.getContextProps().containsKey(GatewayConstants.IS_RETURN_RESPONSE) &&
(boolean) (fsapiResponseContext.getContextProps().get(GatewayConstants.IS_RETURN_RESPONSE))) {
Boolean.parseBoolean(fsapiResponseContext.getContextProps().get(GatewayConstants.IS_RETURN_RESPONSE))) {
Map<String, String> headers = fsapiResponseContext.getMsgInfo().getHeaders();
headers.put(GatewayConstants.CONTENT_TYPE_TAG, GatewayConstants.JSON_CONTENT_TYPE);
fsapiResponseContext.getMsgInfo().setHeaders(headers);
extensionResponseDTO.setHeaders(headers);
if (fsapiResponseContext.getContextProps().containsKey(GatewayConstants.MODIFIED_STATUS)) {
extensionResponseDTO.setStatusCode((int) (fsapiResponseContext.getContextProps()
.get(GatewayConstants.MODIFIED_STATUS)));
extensionResponseDTO.setStatusCode((Integer.parseInt(fsapiResponseContext.getContextProps()
.get(GatewayConstants.MODIFIED_STATUS))));
}
extensionResponseDTO.setResponseStatus(ExtensionResponseStatus.RETURN_ERROR.toString());
} else {
Expand Down Expand Up @@ -221,7 +221,7 @@ public String getType() {
* @param key unique cache key
* @param contextProps properties to store
*/
private void setPropertiesToCache(String key, Map<String, Object> contextProps) {
private void setPropertiesToCache(String key, Map<String, String> contextProps) {

GatewayDataHolder.getGatewayCache().addToCache(GatewayCacheKey.of(key), contextProps);
}
Expand All @@ -232,9 +232,9 @@ private void setPropertiesToCache(String key, Map<String, Object> contextProps)
* @param key unique cache key
* @return context properties
*/
private Map<String, Object> getPropertiesFromCache(String key) {
private Map<String, String> getPropertiesFromCache(String key) {
Object cachedObject = GatewayDataHolder.getGatewayCache().getFromCache(GatewayCacheKey.of(key));
return cachedObject == null ? new HashMap<>() : (Map<String, Object>) cachedObject;
return cachedObject == null ? new HashMap<>() : (Map<String, String>) cachedObject;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class FSAPIRequestContext extends RequestContextDTO {

private static final Log log = LogFactory.getLog(FSAPIRequestContext.class);
private final RequestContextDTO requestContextDTO;
private Map<String, Object> contextProps;
private Map<String, String> contextProps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we change this to a string? What if in the future we have a requirement to pass objects around the executor framework? Like for an example we extract the certificate in one executor and set it as a property and do some validations from another executor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree, Will keep it as <String, Object> map

private String modifiedPayload;
private String requestPayload;
private Map<String, String> addedHeaders;
Expand All @@ -57,7 +57,7 @@ public class FSAPIRequestContext extends RequestContextDTO {
private String consentId;
private OpenAPI openAPI;

public FSAPIRequestContext(RequestContextDTO requestContextDTO, Map<String, Object> contextProps) {
public FSAPIRequestContext(RequestContextDTO requestContextDTO, Map<String, String> contextProps) {

this.requestContextDTO = requestContextDTO;
this.contextProps = contextProps;
Expand Down Expand Up @@ -115,12 +115,12 @@ public void setAddedHeaders(Map<String, String> addedHeaders) {
this.addedHeaders = addedHeaders;
}

public Map<String, Object> getContextProps() {
public Map<String, String> getContextProps() {

return contextProps;
}

public void setContextProps(Map<String, Object> contextProps) {
public void setContextProps(Map<String, String> contextProps) {

this.contextProps = contextProps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class FSAPIResponseContext extends ResponseContextDTO {

private static final Log log = LogFactory.getLog(FSAPIResponseContext.class);
private ResponseContextDTO responseContextDTO;
private Map<String, Object> contextProps;
private Map<String, String> contextProps;
private String responsePayload;
private String modifiedPayload;
private Map<String, String> addedHeaders;
private boolean isError;
private ArrayList<FSExecutorError> errors;

public FSAPIResponseContext(ResponseContextDTO responseContextDTO, Map<String, Object> contextProps) {
public FSAPIResponseContext(ResponseContextDTO responseContextDTO, Map<String, String> contextProps) {

this.responseContextDTO = responseContextDTO;
this.contextProps = contextProps;
Expand Down Expand Up @@ -115,12 +115,12 @@ public void setAddedHeaders(Map<String, String> addedHeaders) {
this.addedHeaders = addedHeaders;
}

public Map<String, Object> getContextProps() {
public Map<String, String> getContextProps() {

return contextProps;
}

public void setContextProps(Map<String, Object> contextProps) {
public void setContextProps(Map<String, String> contextProps) {

this.contextProps = contextProps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static String getAPIMgtConfig(String key) {
}

/**
* Method to obatain basic auth header.
* Method to obtain basic auth header.
*
* @param username Username of Auth header
* @param password Password of Auth header
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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<Integer, String> VALID_EXECUTOR_MAP = Stream.of(
new AbstractMap.SimpleImmutableEntry<>(1, VALID_EXECUTOR_CLASS))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static final Map<String, Map<Integer, String>> FULL_VALIDATOR_MAP = Stream.of(
new AbstractMap.SimpleImmutableEntry<>("Default", VALID_EXECUTOR_MAP),
new AbstractMap.SimpleImmutableEntry<>("DCR", VALID_EXECUTOR_MAP))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
public static final String CUSTOM_PAYLOAD = "{\"custom\":\"payload\"}";
public static final String B64_PAYLOAD = "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva" +
"G4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ";
public static final String TEST_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwI" +
"iwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
public static final String XML_PAYLOAD = "<soapenv:Body " +
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<text><content>Test Content</content><date>2024-09-30</date></text>" +
"</soapenv:Body>";
}
Loading
Loading