aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-10-23 14:03:11 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2017-10-26 09:27:02 +0000
commitb0d8aa12fe8f88059f7fcce741913194d72d0d69 (patch)
tree309becc99aaa133a9945f84213e21c81f5af7099 /framework/src/main
parentf3d888a58d5775f015b8c2b1864cde2856dd0376 (diff)
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 <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework/src/main')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java30
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java8
-rw-r--r--framework/src/main/java/org/onap/cli/fw/http/mock/MockJsonGenerator.java61
-rw-r--r--framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java40
-rw-r--r--framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java83
-rw-r--r--framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java56
-rw-r--r--framework/src/main/resources/onap.properties4
8 files changed, 35 insertions, 251 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
index a5c79f7c..1e202a54 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java
@@ -16,6 +16,7 @@
package org.onap.cli.fw.cmd;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,11 +27,14 @@ import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandExecutionFailed;
+import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
import org.onap.cli.fw.http.HttpInput;
import org.onap.cli.fw.http.HttpResult;
-import org.onap.cli.fw.http.mock.MockJsonGenerator;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.http.mock.MockJsonGenerator;
+import org.onap.cli.http.mock.MockRequest;
+import org.onap.cli.http.mock.MockResponse;
/**
* Onap Command.
@@ -95,9 +99,29 @@ public class OnapHttpCommand extends OnapCommand {
for (OnapCommandResultAttribute attr : this.getResult().getRecords()) {
attr.setValues(results.get(attr.getName()));
}
+ generateJsonMock(httpInput, output, this.getName());
+ }
- if (OnapCommandConfg.isMocoGenerateEnabled()) {
- MockJsonGenerator.generateMocking(httpInput, output, this.getName());
+ private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String fileName)
+ throws OnapCommandFailedMocoGenerate {
+
+ if (OnapCommandConfg.isSampleGenerateEnabled()) {
+ try {
+ MockRequest mockRequest = new MockRequest();
+ mockRequest.setMethod(httpInput.getMethod());
+ mockRequest.setUri(httpInput.getUri());
+ mockRequest.setHeaders(httpInput.getReqHeaders());
+ mockRequest.setJson(httpInput.getBody());
+
+ MockResponse mockResponse = new MockResponse();
+ mockResponse.setStatus(httpResult.getStatus());
+ mockResponse.setJson(httpResult.getBody());
+
+ MockJsonGenerator.generateMocking(mockRequest, mockResponse, OnapCommandConfg.getSampleGenerateTargetFolder()
+ + "/" + fileName);
+ } catch (IOException error) {
+ throw new OnapCommandFailedMocoGenerate(fileName, error);
+ }
}
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index f8bd928a..7dfc0d46 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -198,8 +198,8 @@ public class Constants {
public static final String DISCOVER_ALWAYS = "discover_always";
- public static final String MOCO_ENABLED = "cli.moco.enable";
- public static final String MOCO_TARGET_FOLDER = "cli.moco.target";
+ public static final String SAMPLE_GEN_ENABLED = "cli.sample.gen.enable";
+ public static final String SAMPLE_GEN_TARGET_FOLDER = "cli.sample.gen.target";
private Constants() {
}
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
index 6c302b22..bb0e2c06 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
@@ -174,11 +174,11 @@ public final class OnapCommandConfg {
return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR
}
- public static String getMocoTargetFolder() {
- return prps.getProperty(Constants.MOCO_TARGET_FOLDER, ".");
+ public static String getSampleGenerateTargetFolder() {
+ return prps.getProperty(Constants.SAMPLE_GEN_TARGET_FOLDER, ".");
}
- public static boolean isMocoGenerateEnabled() {
- return "true".equals(prps.getProperty(Constants.MOCO_ENABLED));
+ public static boolean isSampleGenerateEnabled() {
+ return "true".equals(prps.getProperty(Constants.SAMPLE_GEN_ENABLED));
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/http/mock/MockJsonGenerator.java b/framework/src/main/java/org/onap/cli/fw/http/mock/MockJsonGenerator.java
deleted file mode 100644
index 91586d56..00000000
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockJsonGenerator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.fw.http.mock;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-
-import org.onap.cli.fw.conf.OnapCommandConfg;
-import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
-import org.onap.cli.fw.http.HttpInput;
-import org.onap.cli.fw.http.HttpResult;
-
-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(HttpInput httpInput, HttpResult httpResult,
- String jsonFileName) throws OnapCommandFailedMocoGenerate {
-
- MockRequest mockRequest = new MockRequest();
- mockRequest.setMethod(httpInput.getMethod());
- mockRequest.setUri(httpInput.getUri());
- mockRequest.setHeaders(httpInput.getReqHeaders());
- mockRequest.setJson(httpInput.getBody());
-
- MockResponse mockResponse = new MockResponse();
- mockResponse.setStatus(httpResult.getStatus());
- mockResponse.setJson(httpResult.getBody());
-
- MockObject mockObject = new MockObject();
- mockObject.setRequest(mockRequest);
- mockObject.setResponse(mockResponse);
-
- ObjectMapper mapper = new ObjectMapper();
- ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
- try {
- String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
- writer.writeValue(new File(OnapCommandConfg.getMocoTargetFolder() + "/" + jsonFileName + "-" + timeStamp + "-moco.json"),
- Arrays.asList(mockObject));
- } catch (IOException error ) {
- throw new OnapCommandFailedMocoGenerate(jsonFileName, error);
- }
- }
-}
diff --git a/framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java b/framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java
deleted file mode 100644
index 36d34d30..00000000
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.fw.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/framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java b/framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java
deleted file mode 100644
index e9188645..00000000
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.fw.http.mock;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Map;
-
-import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-
-public class MockRequest {
- private String method;
- private String uri;
- private Map<String, String> 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 OnapCommandFailedMocoGenerate {
- URL urlt;
- try {
- urlt = new URL(url);
- } catch (MalformedURLException error) {
- throw new OnapCommandFailedMocoGenerate(null, error);
- }
- this.uri = urlt.getPath();
- }
-
- public Map<String, String> getHeaders() {
- return headers;
- }
-
- public void setHeaders(Map<String, String> headers) {
- this.headers = headers;
- }
-
- public JsonNode getJson() {
- return json;
- }
-
- public void setJson(String json) throws OnapCommandFailedMocoGenerate {
- if (json.isEmpty()) {
- this.json = JsonNodeFactory.instance.objectNode();
- return;
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- try {
- this.json = objectMapper.readTree(json);
- }catch (IOException error) {
- throw new OnapCommandFailedMocoGenerate(null, error);
- }
- }
-}
diff --git a/framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java b/framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java
deleted file mode 100644
index 9950d87d..00000000
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.fw.http.mock;
-
-import java.io.IOException;
-
-import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-
-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 OnapCommandFailedMocoGenerate {
- if (json.isEmpty()) {
- this.json = JsonNodeFactory.instance.objectNode();
- return;
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- try {
- this.json = objectMapper.readTree(json);
- } catch (IOException error) {
- throw new OnapCommandFailedMocoGenerate(null, error);
- }
- }
-}
diff --git a/framework/src/main/resources/onap.properties b/framework/src/main/resources/onap.properties
index 26955674..19182ae3 100644
--- a/framework/src/main/resources/onap.properties
+++ b/framework/src/main/resources/onap.properties
@@ -57,6 +57,6 @@ cli.schema.mode_values=direct,catalog
cli.product.version=cli-1.0
# moco properties
-cli.moco.enable=false
-cli.moco.target=.
+cli.sample.gen.enable=false
+cli.sample.gen.target=.