aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/pom.xml5
-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/resources/onap.properties4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/http/mock/MockJsonGeneratorTest.java66
-rw-r--r--main/pom.xml5
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java19
-rw-r--r--pom.xml4
-rw-r--r--validate/pom.xml41
-rw-r--r--validate/sample-mock-generator/pom.xml48
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java42
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java (renamed from framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java)2
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java (renamed from framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java)28
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java (renamed from framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java)18
-rw-r--r--validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java65
-rw-r--r--validate/sample-yaml-generator/pom.xml43
-rw-r--r--validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java82
-rw-r--r--validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java32
-rw-r--r--validate/validation/pom.xml (renamed from validation/pom.xml)0
-rw-r--r--validate/validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java (renamed from validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java)0
-rw-r--r--validate/validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java (renamed from validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java)0
-rw-r--r--validate/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java (renamed from validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java)0
-rw-r--r--validate/validation/src/test/resources/customer-create-sample-1.1-moco.json (renamed from validation/src/test/resources/customer-create-sample-1.1-moco.json)0
-rw-r--r--validate/validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml (renamed from validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml)0
26 files changed, 431 insertions, 176 deletions
diff --git a/framework/pom.xml b/framework/pom.xml
index 87e6bc2f..a1b81e93 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -77,6 +77,11 @@
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>cli-sample-mock-generator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
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/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=.
diff --git a/framework/src/test/java/org/onap/cli/fw/http/mock/MockJsonGeneratorTest.java b/framework/src/test/java/org/onap/cli/fw/http/mock/MockJsonGeneratorTest.java
deleted file mode 100644
index 2d996407..00000000
--- a/framework/src/test/java/org/onap/cli/fw/http/mock/MockJsonGeneratorTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016-17 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 org.junit.Test;
-import org.onap.cli.fw.error.OnapCommandFailedMocoGenerate;
-import org.onap.cli.fw.http.HttpInput;
-import org.onap.cli.fw.http.HttpResult;
-
-public class MockJsonGeneratorTest {
-
- @Test
- public void mocoGenerateTest() throws OnapCommandFailedMocoGenerate {
- HttpInput httpInput = new HttpInput();
- httpInput.setBody("{\"value\" : \"234sdf-345\"}");
- httpInput.setMethod("get");
- httpInput.setUri("http://1.1.1.1:80/getResource");
-
- HttpResult httpResult = new HttpResult();
- httpResult.setStatus(200);
- httpResult.setBody("{\"value\" : \"234sdf-345\"}");
-
- MockJsonGenerator.generateMocking(httpInput, httpResult, "test");
- }
-
- @Test(expected=OnapCommandFailedMocoGenerate.class)
- public void mocoGenerateFailedInvalidBodyTest() throws OnapCommandFailedMocoGenerate {
- HttpInput httpInput = new HttpInput();
- httpInput.setBody("{\"value\" : \"234sdf-345\"");
- httpInput.setMethod("get");
- httpInput.setUri("http://1.1.1.1:80/getResource");
-
- HttpResult httpResult = new HttpResult();
- httpResult.setStatus(200);
- httpResult.setBody("{\"value\" : \"234sdf-345\"");
-
- MockJsonGenerator.generateMocking(httpInput, httpResult, "test");
- }
-
- @Test(expected=OnapCommandFailedMocoGenerate.class)
- public void mocoGenerateFailedInvalidUrlTest() throws OnapCommandFailedMocoGenerate {
- HttpInput httpInput = new HttpInput();
- httpInput.setBody("{\"value\" : \"234sdf-345\"");
- httpInput.setMethod("get");
- httpInput.setUri("http://1.1.1.1:80:invalid");
-
- HttpResult httpResult = new HttpResult();
- httpResult.setStatus(200);
- httpResult.setBody("{\"value\" : \"234sdf-345\"");
-
- MockJsonGenerator.generateMocking(httpInput, httpResult, "test");
- }
-}
diff --git a/main/pom.xml b/main/pom.xml
index 451c55df..43a7000d 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -32,6 +32,11 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>cli-sample-yaml-generator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java
index 35df0e37..0ed27ea1 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -25,8 +25,10 @@ import org.apache.commons.io.IOUtils;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandRegistrar;
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.OnapCommandHelpFailed;
+import org.onap.cli.fw.error.OnapCommandInvalidSample;
import org.onap.cli.fw.error.OnapCommandWarning;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.output.OnapCommandResult;
@@ -37,6 +39,7 @@ import org.onap.cli.fw.output.ResultType;
import org.onap.cli.main.conf.OnapCliConstants;
import org.onap.cli.main.interactive.StringCompleter;
import org.onap.cli.main.utils.OnapCliUtils;
+import org.onap.cli.sample.yaml.SampleYamlGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -355,9 +358,12 @@ public class OnapCli {
OnapCliUtils.populateParams(cmd.getParameters(), args);
OnapCommandResult result = cmd.execute();
+
this.print(result.getDebugInfo());
this.print(result.print());
this.exitSuccessfully();
+
+ generateSmapleYaml(result);
} catch (Exception e) {
this.print(cmd.getResult().getDebugInfo());
if (e instanceof OnapCommandWarning) {
@@ -370,6 +376,19 @@ public class OnapCli {
}
}
+ private void generateSmapleYaml(OnapCommandResult result) throws OnapCommandException {
+ if (OnapCommandConfg.isSampleGenerateEnabled() && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) {
+ try {
+ SampleYamlGenerator.generateSampleYaml(args, result.print(),
+ OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(),
+ OnapCommandConfg.getSampleGenerateTargetFolder(),
+ result.isDebug());
+ } catch (IOException error) {
+ throw new OnapCommandInvalidSample(args.get(0), error);
+ }
+ }
+ }
+
/**
* Handles all client input.
*/
diff --git a/pom.xml b/pom.xml
index a4fd6216..18241f91 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,7 +39,7 @@
<module>plugins</module>
<module>main</module>
<module>deployment</module>
- <module>validation</module>
+ <module>validate</module>
</modules>
<distributionManagement>
@@ -92,4 +92,4 @@
</plugin>
</plugins>
</build>
-</project> \ No newline at end of file
+</project>
diff --git a/validate/pom.xml b/validate/pom.xml
new file mode 100644
index 00000000..2d75b23d
--- /dev/null
+++ b/validate/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>cli</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cli-validate</artifactId>
+ <name>cli/validate</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>sample-mock-generator</module>
+ <module>sample-yaml-generator</module>
+ <module>validation</module>
+ </modules>
+
+
+</project>
diff --git a/validate/sample-mock-generator/pom.xml b/validate/sample-mock-generator/pom.xml
new file mode 100644
index 00000000..c9263aff
--- /dev/null
+++ b/validate/sample-mock-generator/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>cli</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cli-sample-mock-generator</artifactId>
+ <name>cli/validate/sample-mock-generator</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.6.3</version>
+ </dependency>
+ </dependencies>
+
+</project>
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/framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java
index 36d34d30..2d02e85c 100644
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockObject.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockObject.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onap.cli.fw.http.mock;
+package org.onap.cli.http.mock;
public class MockObject {
private MockRequest request;
diff --git a/framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java
index e9188645..cbb2a26a 100644
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockRequest.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java
@@ -14,18 +14,14 @@
* limitations under the License.
*/
-package org.onap.cli.fw.http.mock;
+package org.onap.cli.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;
@@ -45,13 +41,9 @@ public class MockRequest {
return uri;
}
- public void setUri(String url) throws OnapCommandFailedMocoGenerate {
+ public void setUri(String url) throws IOException {
URL urlt;
- try {
- urlt = new URL(url);
- } catch (MalformedURLException error) {
- throw new OnapCommandFailedMocoGenerate(null, error);
- }
+ urlt = new URL(url);
this.uri = urlt.getPath();
}
@@ -67,17 +59,11 @@ public class MockRequest {
return json;
}
- public void setJson(String json) throws OnapCommandFailedMocoGenerate {
- if (json.isEmpty()) {
- this.json = JsonNodeFactory.instance.objectNode();
- return;
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- try {
+ public void setJson(String json) throws IOException {
+ if (!json.isEmpty()) {
+ ObjectMapper objectMapper = new ObjectMapper();
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/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
index 9950d87d..2b8fa826 100644
--- a/framework/src/main/java/org/onap/cli/fw/http/mock/MockResponse.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
@@ -14,15 +14,12 @@
* limitations under the License.
*/
-package org.onap.cli.fw.http.mock;
+package org.onap.cli.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;
@@ -40,17 +37,10 @@ public class MockResponse {
return json;
}
- public void setJson(String json) throws OnapCommandFailedMocoGenerate {
- if (json.isEmpty()) {
- this.json = JsonNodeFactory.instance.objectNode();
- return;
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- try {
+ public void setJson(String json) throws IOException {
+ if (!json.isEmpty()) {
+ ObjectMapper objectMapper = new ObjectMapper();
this.json = objectMapper.readTree(json);
- } catch (IOException error) {
- throw new OnapCommandFailedMocoGenerate(null, error);
}
}
}
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
new file mode 100644
index 00000000..3b79057f
--- /dev/null
+++ b/validate/sample-mock-generator/src/test/java/org/onap/cli/http/mock/MockJsonGeneratorTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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 org.junit.Test;
+
+public class MockJsonGeneratorTest {
+
+ @Test
+ public void mocoGenerateTest() 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 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");
+ }
+}
diff --git a/validate/sample-yaml-generator/pom.xml b/validate/sample-yaml-generator/pom.xml
new file mode 100644
index 00000000..76ff4848
--- /dev/null
+++ b/validate/sample-yaml-generator/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.cli</groupId>
+ <artifactId>cli</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>cli-sample-yaml-generator</artifactId>
+ <name>cli/validate/sample-yaml-generator</name>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java
new file mode 100644
index 00000000..5c308154
--- /dev/null
+++ b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java
@@ -0,0 +1,82 @@
+/*
+ * 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.sample.yaml;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class SampleYamlGenerator {
+
+ static int nTab;
+
+ public static void generateSampleYaml(List<String> input, String ouput, String version,
+ String targetFolder, boolean debug) throws IOException {
+
+ String cmdName = input.get(0);
+
+ PrintWriter writer = new PrintWriter(targetFolder + "/" + cmdName + "-sample.yaml", "UTF-8");
+ writeKeyValuePair(writer, "onap_cli_sample_version", "1.0");
+ writeKeyValuePair(writer, "name", cmdName);
+ writeKeyValuePair(writer, "version", version);
+
+ writeKey(writer, "samples");
+ writeKey(writer, "sample1");
+
+ writeKeyValuePair(writer, "name", cmdName);
+ writeKeyValuePair(writer, "input", input.stream().skip(1).collect(Collectors.joining(" ")));
+ writeKeyValuePair(writer, "moco", cmdName + "-sample-yaml.yaml");
+ writeMultilineKeyValue(writer, "ouput", ouput, debug);
+
+ writeEndKey();
+ writeEndKey();
+
+ writer.flush();
+ writer.close();
+ }
+
+ private static void writeMultilineKeyValue(PrintWriter writer, String key, String value, boolean debug) {
+ writer.write(printTabs() + key + ": |\n");
+ nTab++;
+ String[] lines = value.split("\n");
+ long skipLines = debug ? 12 : 0;
+ Arrays.stream(lines).skip(skipLines ).forEach(line -> writer.write(printTabs() + line + "\n"));
+ }
+
+ private static String printTabs() {
+ StringBuffer spaces = new StringBuffer();
+ for (int i=0; i < nTab; i++) {
+ spaces.append(" ");
+ }
+ return spaces.toString();
+ }
+
+ private static void writeKeyValuePair(PrintWriter writer, String key, String value) {
+ writer.write(printTabs() +key + ": " + value + "\n");
+ }
+
+ private static void writeKey(PrintWriter writer, String key) {
+ writer.write(printTabs() + key + ":\n");
+ nTab++;
+ }
+
+ private static void writeEndKey() {
+ nTab--;
+ }
+}
diff --git a/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java
new file mode 100644
index 00000000..c98cb71b
--- /dev/null
+++ b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sample.yaml;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import org.junit.Test;
+
+public class SampleYamlGeneratorTest {
+
+ @Test
+ public void testGenerateSampleYaml() throws IOException {
+ SampleYamlGenerator.generateSampleYaml(Arrays.asList("testcmd", "-a", "argument"),
+ "+--------+\n+val +\n+argument+", "test-version-1.0", "target", false);
+ }
+
+}
diff --git a/validation/pom.xml b/validate/validation/pom.xml
index 618074f6..618074f6 100644
--- a/validation/pom.xml
+++ b/validate/validation/pom.xml
diff --git a/validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java b/validate/validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java
index 7f84704c..7f84704c 100644
--- a/validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java
+++ b/validate/validation/src/test/java/org/onap/cli/moco/OnapCommandHttpMocoServer.java
diff --git a/validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java b/validate/validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java
index 31448e4b..31448e4b 100644
--- a/validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java
+++ b/validate/validation/src/test/java/org/onap/cli/moco/OnapCommandSample.java
diff --git a/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java b/validate/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java
index 779978f9..779978f9 100644
--- a/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java
+++ b/validate/validation/src/test/java/org/onap/cli/validation/OnapCliMainTest.java
diff --git a/validation/src/test/resources/customer-create-sample-1.1-moco.json b/validate/validation/src/test/resources/customer-create-sample-1.1-moco.json
index f6e4d0b2..f6e4d0b2 100644
--- a/validation/src/test/resources/customer-create-sample-1.1-moco.json
+++ b/validate/validation/src/test/resources/customer-create-sample-1.1-moco.json
diff --git a/validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml b/validate/validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml
index 30b5b303..30b5b303 100644
--- a/validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml
+++ b/validate/validation/src/test/resources/onap-cli-sample/customer/customer-create-sample-1.1.yaml