aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-08-12 14:51:28 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-08-12 15:02:57 +0300
commit4a4dcc5185f8ba5a28c7f9fef509f32c0c2389e6 (patch)
tree23e55ee7e1ad9b91bcc3ef1dbe1fb7b183f8b2b6 /vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java
parent661a24fd57de02869a9771761e0fcba7eb77d121 (diff)
vid-automation selenium tests
Change-Id: I6c1b0a0cf3bbfa4314c81f0cc72507db805ec632 Issue-ID: VID-281 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java')
-rw-r--r--vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java b/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java
new file mode 100644
index 000000000..e175b88b1
--- /dev/null
+++ b/vid-automation/src/main/java/vid/automation/test/services/DropTestApiField.java
@@ -0,0 +1,64 @@
+package vid.automation.test.services;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import vid.automation.test.infra.Features;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.function.UnaryOperator;
+
+public class DropTestApiField {
+
+ public static UnaryOperator<String> dropTestApiFieldFromString() {
+ if (Features.FLAG_ADD_MSO_TESTAPI_FIELD.isActive()) {
+ // do nothing
+ return in -> in;
+ } else {
+ final ObjectMapper objectMapper = new ObjectMapper();
+ return in -> {
+ if (!in.contains("testApi")) {
+ // short circuit
+ return in;
+ }
+
+ try {
+ final JsonNode tree = objectMapper.readTree(in);
+ final JsonNode node = tree.path("simulatorRequest");
+ if (removePath(node, "body", "requestDetails", "requestParameters", "testApi") != null) {
+ // tree modified, write back to string
+ return objectMapper.writeValueAsString(tree);
+ } else {
+ // else...
+ return in;
+ }
+ } catch (IOException e) {
+ return in;
+ }
+ };
+ }
+ }
+
+ private static JsonNode removePath(JsonNode tree, String... nodes) {
+ // remove the nodes; remove also the parent, if an empty object was left
+ // returns the removed node
+ // returns null if no modification to tree
+ if (nodes.length > 1) {
+ final JsonNode node = tree.path(nodes[0]);
+ final JsonNode removed = removePath(node, Arrays.copyOfRange(nodes, 1, nodes.length));
+ if (removed != null && node.size() == 0) {
+ return removePath(tree, nodes[0]);
+ } else {
+ return removed; // non-null if node.size() != 0
+ }
+ } else {
+ if (tree instanceof ObjectNode) {
+ return ((ObjectNode) tree).remove(nodes[0]);
+ } else {
+ return null;
+ }
+ }
+ }
+
+}