aboutsummaryrefslogtreecommitdiffstats
path: root/profiles/http
diff options
context:
space:
mode:
Diffstat (limited to 'profiles/http')
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java30
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java31
5 files changed, 48 insertions, 19 deletions
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
index 53a2d042..387ec3be 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
@@ -253,7 +253,7 @@ public class OnapHttpCommand extends OnapCommand {
this.resultMap.put(resultMapEntry.getKey(), value);
}
- Map<String, ArrayList<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
+ Map<String, List<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
//results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap());
for (OnapCommandResultAttribute attr : this.getResult().getRecords()) {
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
index a2e025a8..9c4185b7 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
@@ -43,7 +43,7 @@ import java.io.InputStreamReader;
public class MocoServer {
private Runner runner;
- private Map<String, Object> mocoServerConfigs = new HashMap();
+ private Map<String, Object> mocoServerConfigs = new HashMap<>();
private static Gson gson = new GsonBuilder().serializeNulls().create();
public MocoServer(String mockFile) throws OnapCommandException {
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
index df9c84fc..33f58060 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
@@ -92,7 +92,7 @@ public class OnapCommandSchemaHttpLoader {
* @throws OnapCommandException
* on error
*/
- public static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
+ public static List<String> parseHttpSchema(OnapHttpCommand cmd,
final Map<String, ?> values,
boolean validate) throws OnapCommandException {
ArrayList<String> errorList = new ArrayList<>();
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
index a592ac79..fcd25c24 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
@@ -145,9 +145,9 @@ public class OnapCommandHttpUtils {
* @throws OnapCommandResultMapProcessingFailed
* map processing failed exception
*/
- public static Map<String, ArrayList<String>> populateOutputs(Map<String, String> resultMap, HttpResult resultHttp)
+ public static Map<String, List<String>> populateOutputs(Map<String, String> resultMap, HttpResult resultHttp)
throws OnapCommandException {
- Map<String, ArrayList<String>> resultsProcessed = new HashMap<>();
+ Map<String, List<String>> resultsProcessed = new HashMap<>();
for (Entry<String, String> entry : resultMap.entrySet()) {
String key = entry.getKey();
@@ -161,10 +161,10 @@ public class OnapCommandHttpUtils {
return resultsProcessed;
}
- public static ArrayList<String> replaceLineFromOutputResults(String line, HttpResult resultHttp)
+ public static List<String> replaceLineFromOutputResults(String line, HttpResult resultHttp)
throws OnapCommandHttpHeaderNotFound, OnapCommandHttpInvalidResponseBody,
OnapCommandResultMapProcessingFailed, OnapCommandResultEmpty {
- String headerProcessedLine = "";
+ StringBuilder headerProcessedLine = new StringBuilder();
ArrayList<String> result = new ArrayList<>();
if (!line.contains("$b{") && !line.contains("$h{")) {
@@ -187,7 +187,7 @@ public class OnapCommandHttpUtils {
while (currentIdx < line.length()) {
int idxS = line.indexOf("$h{", currentIdx);
if (idxS == -1) {
- headerProcessedLine += line.substring(currentIdx);
+ headerProcessedLine.append(line.substring(currentIdx));
break;
}
int idxE = line.indexOf("}", idxS);
@@ -198,19 +198,19 @@ public class OnapCommandHttpUtils {
}
String value = resultHttp.getRespHeaders().get(headerName);
- headerProcessedLine += line.substring(currentIdx, idxS) + value;
+ headerProcessedLine.append(line.substring(currentIdx, idxS) + value);
currentIdx = idxE + 1;
}
// Process body jsonpath macros
List<Object> values = new ArrayList<>();
- String bodyProcessedPattern = "";
+ StringBuilder bodyProcessedPattern = new StringBuilder();
currentIdx = 0;
int maxRows = 1; // in normal case, only one row will be there
while (currentIdx < headerProcessedLine.length()) {
int idxS = headerProcessedLine.indexOf("$b{", currentIdx);
if (idxS == -1) {
- bodyProcessedPattern += headerProcessedLine.substring(currentIdx);
+ bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx));
break;
}
int idxE = headerProcessedLine.indexOf("}", idxS);
@@ -233,23 +233,23 @@ public class OnapCommandHttpUtils {
maxRows = arr.size();
}
}
- bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s";
+ bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx, idxS) + "%s");
values.add(value);
currentIdx = idxE + 1;
}
- if (bodyProcessedPattern.isEmpty()) {
- result.add(headerProcessedLine);
+ if (bodyProcessedPattern.toString().isEmpty()) {
+ result.add(headerProcessedLine.toString());
return result;
} else {
for (int i = 0; i < maxRows; i++) {
currentIdx = 0;
- String bodyProcessedLine = "";
+ StringBuilder bodyProcessedLine = new StringBuilder();
int positionalIdx = 0; // %s positional idx
while (currentIdx < bodyProcessedPattern.length()) {
int idxS = bodyProcessedPattern.indexOf("%s", currentIdx);
if (idxS == -1) {
- bodyProcessedLine += bodyProcessedPattern.substring(currentIdx);
+ bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx));
break;
}
int idxE = idxS + 2; // %s
@@ -265,7 +265,7 @@ public class OnapCommandHttpUtils {
}
}
- bodyProcessedLine += bodyProcessedPattern.substring(currentIdx, idxS) + valueS;
+ bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx, idxS) + valueS);
currentIdx = idxE;
positionalIdx++;
} catch (OnapCommandResultEmpty e) {
@@ -274,7 +274,7 @@ public class OnapCommandHttpUtils {
throw new OnapCommandResultMapProcessingFailed(line, e);
}
}
- result.add(bodyProcessedLine);
+ result.add(bodyProcessedLine.toString());
}
return result;
diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
index 6e03e74b..37fc8461 100644
--- a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
+++ b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
@@ -49,6 +49,10 @@ import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cli.fw.schema.OnapCommandSchemaLoader;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import java.util.List;
+import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
+import org.onap.cli.fw.error.OnapCommandResultEmpty;
+import static org.junit.Assert.assertFalse;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
@@ -116,7 +120,7 @@ public class OnapCommandUtilsTest {
params.put("body", "$b{$.serviceName}");
params.put("key", "value");
- Map<String, ArrayList<String>> input1 = OnapCommandHttpUtils.populateOutputs(params, output);
+ Map<String, List<String>> input1 = OnapCommandHttpUtils.populateOutputs(params, output);
assertEquals("{head=[value1], body=[test], key=[value]}", input1.toString());
params.put("body", "$b{{$.serviceName}");
@@ -135,6 +139,31 @@ public class OnapCommandUtilsTest {
input1 = OnapCommandHttpUtils.populateOutputs(params, output);
}
+ @Test
+ public void replaceLineFromOutputResultsTest() throws OnapCommandHttpHeaderNotFound, OnapCommandHttpInvalidResponseBody, OnapCommandResultMapProcessingFailed, OnapCommandResultEmpty {
+ HttpResult output = new HttpResult();
+
+ Map<String, String> mapHead = new HashMap<>();
+ mapHead.put("head1", "value1");
+ output.setRespHeaders(mapHead);
+ output.setStatus(0);
+ List<String> actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("", output);
+ assertTrue(actualResult.get(0).isEmpty());
+ output.setBody("");
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}$b{$.serviceName}", output);
+ assertTrue(actualResult.isEmpty());
+// assertTrue(actualResult.size() > 0);
+ output.setBody(
+ "{\"serviceName\":\"test\",\"version\":\"v1\",\"url\":\"/api/test/v1\",\"protocol\":\"REST\","
+ + "\"visualRange\":\"1\",\"lb_policy\":\"hash\",\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"8012\","
+ + "\"ttl\":0,\"nodeId\":\"test_127.0.0.1_8012\",\"expiration\":\"2017-02-10T05:33:25Z\","
+ + "\"created_at\":\"2017-02-10T05:33:25Z\",\"updated_at\":\"2017-02-10T05:33:25Z\"}],"
+ + "\"status\":\"1\"}");
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}${$.serviceName}", output);
+ assertTrue(actualResult.size()>0);
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}$b{$.serviceName}", output);
+ assertFalse(actualResult.get(0).isEmpty());
+ }
@OnapCommandSchema(schema = "sample-test-schema-http.yaml")
class OnapHttpCommandSample extends OnapHttpCommand {