From b0d8aa12fe8f88059f7fcce741913194d72d0d69 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Mon, 23 Oct 2017 14:03:11 +0000 Subject: Code refactoring to remove test code generation Refactor code to remove test code generation code from framework codebase. Issue-ID: CLI-55 Change-Id: I4b45ef50143317586c39cf118a1717be150707da Signed-off-by: subhash kumar singh --- .../org/onap/cli/http/mock/MockJsonGenerator.java | 42 +++++++++++++ .../java/org/onap/cli/http/mock/MockObject.java | 40 +++++++++++++ .../java/org/onap/cli/http/mock/MockRequest.java | 69 ++++++++++++++++++++++ .../java/org/onap/cli/http/mock/MockResponse.java | 46 +++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java create mode 100644 validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java create mode 100644 validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java create mode 100644 validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java (limited to 'validate/sample-mock-generator/src/main') diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java new file mode 100644 index 00000000..c3006e32 --- /dev/null +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java @@ -0,0 +1,42 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.cli.http.mock; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; + +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +public class MockJsonGenerator { + public static void generateMocking(MockRequest mockRequest, MockResponse mockResponse, + String jsonFilePath) throws IOException { + + MockObject mockObject = new MockObject(); + mockObject.setRequest(mockRequest); + mockObject.setResponse(mockResponse); + + ObjectMapper mapper = new ObjectMapper(); + ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); + String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); + writer.writeValue(new File(jsonFilePath + "-" + timeStamp + "-moco.json"), + Arrays.asList(mockObject)); + } +} diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java new file mode 100644 index 00000000..2d02e85c --- /dev/null +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.cli.http.mock; + +public class MockObject { + private MockRequest request; + private MockResponse response; + + public MockRequest getRequest() { + return request; + } + + public void setRequest(MockRequest request) { + this.request = request; + } + + public MockResponse getResponse() { + return response; + } + + public void setResponse(MockResponse response) { + this.response = response; + } + + +} 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 new file mode 100644 index 00000000..cbb2a26a --- /dev/null +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.cli.http.mock; + +import java.io.IOException; +import java.net.URL; +import java.util.Map; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class MockRequest { + private String method; + private String uri; + private Map headers; + private JsonNode json; + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public String getUri() { + return uri; + } + + public void setUri(String url) throws IOException { + URL urlt; + urlt = new URL(url); + this.uri = urlt.getPath(); + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public JsonNode getJson() { + return json; + } + + public void setJson(String json) throws IOException { + if (!json.isEmpty()) { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } + + } +} 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 new file mode 100644 index 00000000..2b8fa826 --- /dev/null +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java @@ -0,0 +1,46 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.cli.http.mock; + +import java.io.IOException; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class MockResponse { + private int status; + private JsonNode json; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public JsonNode getJson() { + return json; + } + + public void setJson(String json) throws IOException { + if (!json.isEmpty()) { + ObjectMapper objectMapper = new ObjectMapper(); + this.json = objectMapper.readTree(json); + } + } +} -- cgit 1.2.3-korg