for (OnapCommandResultAttribute attr : this.getResult().getRecords()) {
attr.setValues(results.get(attr.getName()));
}
- generateJsonMock(httpInput, output, this.getName());
+ generateJsonMock(httpInput, output, this.getSchemaName());
}
- private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String fileName)
+ private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String schemaName)
throws OnapCommandFailedMocoGenerate {
if (OnapCommandConfg.isSampleGenerateEnabled()) {
mockResponse.setJson(httpResult.getBody());
MockJsonGenerator.generateMocking(mockRequest, mockResponse, OnapCommandConfg.getSampleGenerateTargetFolder()
- + "/" + fileName);
+ + "/" + schemaName.replace(".yaml", "") + "-moco.json");
} catch (IOException error) {
- throw new OnapCommandFailedMocoGenerate(fileName, error);
+ throw new OnapCommandFailedMocoGenerate(schemaName, error);
}
}
}
this.print(result.print());
this.exitSuccessfully();
- generateSmapleYaml(result);
+ generateSmapleYaml(cmd);
} catch (Exception e) {
this.print(cmd.getResult().getDebugInfo());
if (e instanceof OnapCommandWarning) {
}
}
- private void generateSmapleYaml(OnapCommandResult result) throws OnapCommandException {
+ private void generateSmapleYaml(OnapCommand cmd) throws OnapCommandException {
if (OnapCommandConfg.isSampleGenerateEnabled() && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) {
try {
- SampleYamlGenerator.generateSampleYaml(args, result.print(),
+ SampleYamlGenerator.generateSampleYaml(args, cmd.getResult().print(),
OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(),
- OnapCommandConfg.getSampleGenerateTargetFolder(),
- result.isDebug());
+ OnapCommandConfg.getSampleGenerateTargetFolder() + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml",
+ cmd.getResult().isDebug());
} catch (IOException error) {
throw new OnapCommandInvalidSample(args.get(0), error);
}
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;
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"),
+ writer.writeValue(new File(jsonFilePath),
Arrays.asList(mockObject));
}
}
}
public void setJson(String json) throws IOException {
- if (!json.isEmpty()) {
+ if (json != null && !json.isEmpty()) {
ObjectMapper objectMapper = new ObjectMapper();
this.json = objectMapper.readTree(json);
}
package org.onap.cli.sample.yaml;
+import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
static int nTab;
public static void generateSampleYaml(List<String> input, String ouput, String version,
- String targetFolder, boolean debug) throws IOException {
+ String targetPath, boolean debug) throws IOException {
String cmdName = input.get(0);
- PrintWriter writer = new PrintWriter(targetFolder + "/" + cmdName + "-sample.yaml", "UTF-8");
+ PrintWriter writer = new PrintWriter(targetPath, "UTF-8");
writeKeyValuePair(writer, "onap_cli_sample_version", "1.0");
writeKeyValuePair(writer, "name", cmdName);
writeKeyValuePair(writer, "version", version);
writeKeyValuePair(writer, "name", cmdName);
writeKeyValuePair(writer, "input", input.stream().skip(1).collect(Collectors.joining(" ")));
- writeKeyValuePair(writer, "moco", cmdName + "-sample-yaml.yaml");
+ writeKeyValuePair(writer, "moco", new File(targetPath).getName().replaceAll("-sample.yaml", "-moco.json"));
writeMultilineKeyValue(writer, "ouput", ouput, debug);
writeEndKey();
@Test
public void testGenerateSampleYaml() throws IOException {
SampleYamlGenerator.generateSampleYaml(Arrays.asList("testcmd", "-a", "argument"),
- "+--------+\n+val +\n+argument+", "test-version-1.0", "target", false);
+ "+--------+\n+val +\n+argument+", "test-version-1.0", "target/test.yaml", false);
}
}