- https://jira.onap.org/browse/VNFSDK-650
## [1.6.1]
+
+### Fix
+- Fix JSON parsing error returned from GET request
+ - https://jira.onap.org/browse/VNFSDK-697
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
.orElse(createNoOutputFileErrorMessageInJsonFormat());
}
- private JsonArray loadOutputJsonFromFile(File file) {
- JsonArray outputJson;
+ private JsonElement loadOutputJsonFromFile(File file) {
+ JsonElement outputJson;
try {
String executionResult = Files.readString(file.toPath());
- outputJson = gson.fromJson(executionResult, JsonArray.class);
+ outputJson = gson.fromJson(executionResult, JsonElement.class);
} catch (IOException | JsonParseException e) {
logger.error(e.getMessage(),e);
String errorMessage = "" +
- "[{ \"error\": \"fail to load execution result\",\"reason\":\"" + e.getMessage() + "\"}]";
- outputJson = gson.fromJson(errorMessage, JsonArray.class);
+ "{ \"error\": \"fail to load execution result\",\"reason\":\"" + e.getMessage() + "\"}";
+ outputJson = gson.fromJson(errorMessage, JsonObject.class);
}
return outputJson;
}
- private JsonArray createNoOutputFileErrorMessageInJsonFormat() {
- return gson.fromJson("[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+ private JsonElement createNoOutputFileErrorMessageInJsonFormat() {
+ return gson.fromJson("{ \"error\": \"unable to find execution results\"}", JsonObject.class);
}
}
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
String testProduct = "VTP Scenario 2";
String testCommand = "s1.ts1.testcase-2";
String testSuiteName = "testsuite-2";
- String testRequestId = "test-02-request-id";
+ String testRequestId = "test-wrong-request-id";
String testExecutionId = testRequestId + "-execution-id";
String testProfile = "open-cli-schema";
String expectedStatus = "FAIL";
JsonElement expectedResult = new Gson().fromJson("" +
- "[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+ "{ \"error\": \"unable to find execution results\"}", JsonObject.class);
prepareMockRpcMethods(
testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
String testProfile = "open-cli-schema";
String expectedStatus = "FAIL";
JsonElement expectedResult = new Gson().fromJson("" +
- "[{ " +
+ "{ " +
"\"error\": \"fail to load execution result\"," +
- "\"reason\":\"Expected a com.google.gson.JsonArray but was com.google.gson.JsonPrimitive\"" +
- "}]",
- JsonArray.class
+ "\"reason\":\"com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $\"" +
+ "}",
+ JsonObject.class
);
prepareMockRpcMethods(
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
private static final String TEST_PATH_TO_EXECUTION = "src/test/resources/executions";
@Test
- public void whenGetExecutionOutputsFromFileIsCalledWithPathToCorrectFileThenContentShouldBeLoadedAsJson() {
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToCorrectFileThenContentShouldBeLoadedAsJsonArray() {
// given
VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
}
@Test
- public void whenGetExecutionOutputsFromFileIsCalledWithPathToNonExistingFileThenProperMessageShouldBeReturned() {
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToCorrectFileThenContentShouldBeLoadedAsJsonObject() {
// given
VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
String pathToCorrectFile = "test-02-request-id-execution-id";
+ JsonElement expectedResult = new Gson().fromJson("" +
+ "{" +
+ "\"test_1\": \"error01\"," +
+ "\"test_2\": \"error02\" " +
+ "}", JsonObject.class);
+
+ // when
+ JsonElement executionOutputsFromFile =
+ vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
+
+ // then
+ assertEquals(executionOutputsFromFile, expectedResult);
+ }
+
+ @Test
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToNonExistingFileThenProperMessageShouldBeReturned() {
+ // given
+ VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
+ new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
+ String pathToCorrectFile = "test-wrong-request-id-execution-id";
JsonElement expectedErrorMessage = new Gson().fromJson("" +
- "[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+ "{ \"error\": \"unable to find execution results\"}", JsonObject.class);
// when
JsonElement executionOutputsFromFile =
vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
// then
- assertEquals(executionOutputsFromFile, expectedErrorMessage);
+ assertEquals(expectedErrorMessage, executionOutputsFromFile);
}
@Test
new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
String pathToCorrectFile = "test-incorrect-request-id-execution-id-data";
JsonElement expectedErrorMessage = new Gson().fromJson("" +
- "[{ " +
+ "{ " +
"\"error\": \"fail to load execution result\"," +
- "\"reason\":\"Expected a com.google.gson.JsonArray but was com.google.gson.JsonPrimitive\"" +
- "}]",
- JsonArray.class
+ "\"reason\":\"com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $\"" +
+ "}",
+ JsonObject.class
);
// when
vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
// then
- assertEquals(executionOutputsFromFile, expectedErrorMessage);
+ assertEquals(expectedErrorMessage, executionOutputsFromFile);
}
}
--- /dev/null
+{
+ "test_1": "error01",
+ "test_2": "error02"
+}