diff options
Diffstat (limited to 'validate/sample-mock-generator/src')
3 files changed, 14 insertions, 33 deletions
diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java index cbb2a26a..d1d8b08d 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.net.URL; import java.util.Map; +import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -61,8 +62,12 @@ public class MockRequest { public void setJson(String json) throws IOException { if (!json.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - this.json = objectMapper.readTree(json); + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } catch (Exception e) { + this.json = new ObjectMapper().readTree("{}"); + } } } diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java index 7e8cdca8..d7999bea 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java @@ -38,9 +38,13 @@ public class MockResponse { } public void setJson(String json) throws IOException { - if (json != null && !json.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - this.json = objectMapper.readTree(json); + if (!json.isEmpty()) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } catch (Exception e) { + this.json = new ObjectMapper().readTree("{}"); + } } } } diff --git a/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java b/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java index 3b79057f..0e0c0f59 100644 --- a/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java +++ b/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java @@ -34,32 +34,4 @@ public class MockJsonGeneratorTest { MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); } - - @Test(expected=IOException.class) - public void mocoGenerateFailedInvalidBodyTest() throws IOException { - MockRequest mockRequest = new MockRequest(); - mockRequest.setJson("{\"value\" : \"234sdf-345\""); - mockRequest.setMethod("get"); - mockRequest.setUri("http://1.1.1.1:80/getResource"); - - MockResponse mockResponse = new MockResponse(); - mockResponse.setStatus(200); - mockResponse.setJson("{\"value\" : \"234sdf-345\""); - - MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); - } - - @Test(expected=IOException.class) - public void mocoGenerateFailedInvalidUrlTest() throws IOException { - MockRequest mockRequest = new MockRequest(); - mockRequest.setJson("{\"value\" : \"234sdf-345\""); - mockRequest.setMethod("get"); - mockRequest.setUri("http://1.1.1.1:80:invalid"); - - MockResponse mockResponse = new MockResponse(); - mockResponse.setStatus(200); - mockResponse.setJson("{\"value\" : \"234sdf-345\""); - - MockJsonGenerator.generateMocking(mockRequest, mockResponse, "target/test"); - } } |