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

chore: Reboot/gh647/improved conformance testing #3020

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ae862d8
feat(gateway): Improvement of existing conformance testing
matejpopda Jul 20, 2023
55e5432
refactor(gateway): Added missing comments
matejpopda Jul 20, 2023
39868f7
fix(gateway): Removed a print statement.
matejpopda Jul 20, 2023
4d389e6
feat(gateway): Better response from the conformance endpoint
matejpopda Jul 21, 2023
8aefab4
feat(gateway): Better response from the conformance endpoint
matejpopda Jul 21, 2023
d14be14
Merge remote-tracking branch 'MyFork/reboot/GH647/improvedConformance…
matejpopda Jul 21, 2023
38fcf01
refactor(gateway): Got rid of duplicate discovery client calls
matejpopda Jul 24, 2023
a53600b
docs(gateway): Changed text in gateway-log-messages.yml based on comm…
matejpopda Jul 24, 2023
21089ea
feat(gateway): Addressed the rest of comments on the PR
matejpopda Jul 25, 2023
8f69e0a
Merge branch 'v2.x.x' into reboot/GH647/improvedConformanceTesting
matejpopda Jul 25, 2023
69935c4
feat(gateway): Addressed the new comments on the PR
matejpopda Jul 27, 2023
f7150dd
Merge remote-tracking branch 'myFork/reboot/GH647/improvedConformance…
matejpopda Jul 27, 2023
c9bd0f2
fix(gateway): Fixed a method not following a naming convention
matejpopda Aug 2, 2023
0b8b730
fix(gateway): Fixed reason why build was failing
matejpopda Aug 3, 2023
6f3675e
fix(gateway): Addressed Pablo's comments on PR
matejpopda Aug 3, 2023
fb26fad
fix(gateway): Updated an integration test for conformance
matejpopda Aug 4, 2023
06b4539
fix(gateway): Updated integration tests
matejpopda Aug 7, 2023
0c3eb93
Merge branch 'zowe:v2.x.x' into reboot/GH647/improvedConformanceTesting
matejpopda Aug 7, 2023
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
@@ -0,0 +1,148 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.gateway.conformance;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.text.StrSubstitutor;
import org.zowe.apiml.message.api.ApiMessage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


/**
* Java class that is used to keep track of found conformance issues
*/
public class ConformanceProblemsContainer extends HashMap<String, ArrayList<String>> {


private final String serviceId;
private static final String responseMessageTemplate = "{\n" +
"\"messageAction\": \"${messageAction}\",\n" +
"\"messageContent\": {\n" +
" \"The service ${serviceId} is not conformant\": \n" +
" ${messageContent}\n" +
"},\n" +
"\"messageKey\": \"${messageKey}\",\n" +
"\"messageNumber\": \"${messageNumber}\",\n" +
"\"messageReason\": \"${messageReason}\",\n" +
"\"messageType\": \"${messageType}\"\n" +
"}";

ConformanceProblemsContainer(String serviceId) {
super();
this.serviceId = serviceId;
}

@Override
public ArrayList<String> put(String key, ArrayList<String> value) {

if (value == null) {
return null;
}

if (this.get(key) != null && this.get(key).size() != 0) {
this.get(key).addAll(value);
return null;
}
return super.put(key, new ArrayList<>(value));
}

public ArrayList<String> put(String key, String value) {
if (value == null || value.equals("")) {
return null;
}

return put(key, new ArrayList<>(Collections.singleton(value)));
}

@Override
public int size() {
int result = 0;
for (ArrayList<String> value : this.values()) {
if (value == null) {
continue;
}
result += value.size();
}
return result;
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();

result.append("{");

boolean firstLoop = true;

ArrayList<String> sortedKeySet = new ArrayList<>(this.keySet());
sortedKeySet.remove(null); // since it used be a set this removes all nulls
sortedKeySet.sort(null);

for (String key : sortedKeySet) {

if (this.get(key) == null || this.get(key).size() == 0) {
continue;
}


if (!firstLoop) {
result.append(",");
}


result.append("\"").append(key).append("\"");
result.append(":[");

boolean firstInnerLoop = true;
for (String i : get(key)) {
if (!firstInnerLoop) {
result.append(",");
}
try {
result.append(new ObjectMapper().writeValueAsString(i));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
firstInnerLoop = false;
}
result.append("]");

firstLoop = false;
}

result.append("}");
return result.toString();
}


public String createBadRequestAPIResponseBody(String key, ApiMessage correspondingAPIMessage) {

Map<String, String> valuesMap = new HashMap<>();

valuesMap.put("messageKey", key);
valuesMap.put("messageContent", this.toString());
valuesMap.put("serviceId", serviceId);
valuesMap.put("messageReason", correspondingAPIMessage.getMessageReason());
valuesMap.put("messageNumber", correspondingAPIMessage.getMessageNumber());
valuesMap.put("messageType", correspondingAPIMessage.getMessageType().toString());
valuesMap.put("messageAction", correspondingAPIMessage.getMessageAction());

return new StrSubstitutor(valuesMap).replace(responseMessageTemplate);

}

}
Loading
Loading