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

fix: add injection of query parameters in returned response #24

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
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 @@ -52,7 +52,7 @@ public ExtractedResponse extract(ExtractedRequest requestData, MockResourceEntit
try {
UnmarshalledBody unmarshalledBody = extractBodyFields(requestData.getBody(), requestData.getContentType());
MockRuleEntity mockRule = getValidMockRule(mockResource, requestData, unmarshalledBody);
extractedResponse = getMockResponse(mockRule, unmarshalledBody);
extractedResponse = getMockResponse(mockRule, unmarshalledBody, requestData);
} catch (IOException | SAXException | JsonSyntaxException e) {
throw new MockerParseRequestException(e);
}
Expand Down Expand Up @@ -191,18 +191,25 @@ private boolean isContentCompliantToCondition(Object fieldValue, String conditio
}


private ExtractedResponse getMockResponse(MockRuleEntity mockRule, UnmarshalledBody unmarshalledBody) {
private ExtractedResponse getMockResponse(MockRuleEntity mockRule, UnmarshalledBody unmarshalledBody, ExtractedRequest requestData) {
MockResponseEntity mockResponse = mockRule.getResponse();
Map<String, String> dynamicParameters = executeScript(mockRule, unmarshalledBody);
List<String> parameters = mockResponse.getParameters();
String decodedBody = Utility.decodeBase64(mockResponse.getBody());
//
// injecting request body's fields in response
if (parameters != null && unmarshalledBody != null) {
for (String parameterName : parameters) {
String parameterValue = (String) unmarshalledBody.getFieldValue(parameterName);
decodedBody = injectParameterValueInDecodedBody(decodedBody, parameterName, parameterValue);
}
}
// injecting request query parameters in response
if (parameters != null && requestData.getQueryParameters() != null) {
for (String parameterName : parameters) {
String parameterValue = requestData.getQueryParameters().get(parameterName);
decodedBody = injectParameterValueInDecodedBody(decodedBody, parameterName, parameterValue);
}
}
//
for (Map.Entry<String, String> parameter : dynamicParameters.entrySet()) {
decodedBody = injectParameterValueInDecodedBody(decodedBody, "dynamic." + parameter.getKey(), parameter.getValue());
Expand Down
Loading