summaryrefslogtreecommitdiffstats
path: root/blueprint-generator/src
diff options
context:
space:
mode:
Diffstat (limited to 'blueprint-generator/src')
-rw-r--r--blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java40
-rw-r--r--blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java60
-rw-r--r--blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java119
-rw-r--r--blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java42
-rw-r--r--blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java85
-rw-r--r--blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java42
6 files changed, 168 insertions, 220 deletions
diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java
new file mode 100644
index 0000000..4775825
--- /dev/null
+++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/App.java
@@ -0,0 +1,40 @@
+/**============LICENSE_START=======================================================
+ org.onap.dcae
+ ================================================================================
+ Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ 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.
+ ============LICENSE_END=========================================================
+
+ */
+
+
+package org.onap.blueprintgenerator.core;
+
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+
+@Command(subcommands = {
+ BlueprintCommand.class,
+ PolicyCommand.class
+})
+public class App implements Runnable {
+ public static void main(String...args) {
+ CommandLine.run(new App(), args);
+ }
+
+ @Override
+ public void run() {
+ CommandLine.usage(this, System.out);
+ }
+}
diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java
new file mode 100644
index 0000000..7627930
--- /dev/null
+++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintCommand.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.blueprintgenerator.core;
+
+import org.onap.blueprintgenerator.models.blueprint.Blueprint;
+import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+@Command(name = "blueprint", description = "Command used to generate blueprints from component spec")
+public class BlueprintCommand implements Runnable {
+ private static final char STANDARD_BLUEPRINT = 'o';
+ private static final char DMAAP_BLUEPRINT = 'd';
+
+ @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true)
+ private String componentSpecPath;
+
+ @Option(names = {"-p", "--blueprint-path"}, description = "Path to directory that blueprints are output to", required = true)
+ private String blueprintOutputPath;
+
+ @Option(names = {"-n", "--blueprint-name"}, description = "Name of the blueprint", defaultValue = "")
+ private String blueprintName;
+
+ @Option(names = {"-t", "--imports"}, description = "Path to the import file", defaultValue = "")
+ private String importsPath;
+
+ @Option(names={"-o", "--service-name-override"}, description="Value used to override the service name", defaultValue = "")
+ private String serviceNameOverride;
+
+ @Option(names={"-d", "--dmaap-plugin"}, description = "Flag used to indicate blueprint uses the DMaaP plugin.")
+ private boolean dmaapPlugin;
+
+ @Override
+ public void run() {
+ ComponentSpec inboundComponentSpec = new ComponentSpec();
+ inboundComponentSpec.createComponentSpecFromFile(componentSpecPath);
+ System.out.println(dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT);
+ Blueprint generatedBlueprint = new Blueprint().createBlueprint(inboundComponentSpec, this.blueprintName,
+ dmaapPlugin ? DMAAP_BLUEPRINT : STANDARD_BLUEPRINT, importsPath, serviceNameOverride);
+ generatedBlueprint.blueprintToYaml(blueprintOutputPath, this.blueprintName, inboundComponentSpec);
+ }
+}
diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java
deleted file mode 100644
index b2e6996..0000000
--- a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/BlueprintGenerator.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**============LICENSE_START=======================================================
- org.onap.dcae
- ================================================================================
- Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
- ================================================================================
- 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.
- ============LICENSE_END=========================================================
-
- */
-
-package org.onap.blueprintgenerator.core;
-
-
-
-import org.apache.commons.cli.BasicParser;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Options;
-import org.onap.blueprintgenerator.models.blueprint.Blueprint;
-import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
-
-
-
-@SuppressWarnings("deprecation")
-public class BlueprintGenerator {
-
- private static String componentSpecPath = "";
-
- private static String bluePrintName = "";
-
- private static String outputPath = "";
-
- private static char bpType = 'o';
-
- private static String importPath = "";
-
- private static String override = "";
-
-
- public static void main(String[] args) throws Exception {
-
- printInstructions();
-
- parseInputs(args);
-
- //create the component Spec we are going to be working with
- ComponentSpec cs = new ComponentSpec();
- cs.createComponentSpecFromFile(componentSpecPath);
-
- //create the blueprint and convert it to a yaml file
- Blueprint bp = new Blueprint();
- bp = bp.createBlueprint(cs, bluePrintName, bpType, importPath, override);
- bp.blueprintToYaml(outputPath, bluePrintName, cs);
- }
-
-
- public static void printInstructions() {
- System.out.println("OPTIONS:");
- System.out.println("-i: The path to the JSON spec file (required)");
- System.out.println("-n: Name of the blueprint (optional)");
- System.out.println("-p: The path to the final blueprint (required)");
- System.out.println("-t: The path to the yaml import file (optional)");
- System.out.println("-d: With this flag present the blueprint will be created with the dmaap plugin enables");
- System.out.println("-o: The value you want for service_component_name_override (optional)");
- }
-
- public static void parseInputs(String[] args) throws Exception {
- //convert the arguments array to a string to make it easier
- String commands = "";
- for(String s: args) {
- if(commands.length() == 0) {
- commands = s;
- }
- else {
- commands = commands + " " + s;
- }
- }
-
- //check if it has the required inputs
- if(!commands.contains("-p") || !commands.contains("-i")) {
- System.out.println("did not enter the required inputs");
- }
- else {
- BasicParser parser = new BasicParser();
- Options options = new Options();
- options.addOption("i", "Spec", true, "ComponentSpec import file");
- options.addOption("p", "Path", true, "Path to the final blueprint");
- options.addOption("n", "Name", true, "Name of the blueprint");
- options.addOption("t", "imports", true, "Path to the import file");
- options.addOption("d", "Dmaap", false, "Enable the dmaap plugin");
- options.addOption("o", "Override", true, "service component name override");
-
- CommandLine commandLine = parser.parse(options, args);
- componentSpecPath = commandLine.getOptionValue("i");
- outputPath = commandLine.getOptionValue("p");
- override = commandLine.getOptionValue("o");
- if(!(commandLine.getOptionValue("n") == null)){
- bluePrintName = commandLine.getOptionValue("n");
- }
- if(!(commandLine.getOptionValue("t") == null)) {
- importPath = commandLine.getOptionValue("t");
- }
- if(commands.contains("-d")) {
- bpType = 'd';
- }
- }
-
- }
-}
-
diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java
new file mode 100644
index 0000000..81a7911
--- /dev/null
+++ b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCommand.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.blueprintgenerator.core;
+
+import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
+import org.onap.blueprintgenerator.models.policymodel.PolicyModel;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+@Command(name = "policy", description = "Command used to generate policy model from component spec")
+public class PolicyCommand implements Runnable{
+ @Option(names = {"-i", "--component-spec"}, description = "Path to component spec file", required = true)
+ private String componentSpecPath;
+
+ @Option(names = {"-p", "--model-path"}, description = "Path to directory that models are output to", required = true)
+ private String modelOutputPath;
+
+ @Override
+ public void run() {
+ ComponentSpec inboundComponentSpec = new ComponentSpec();
+ inboundComponentSpec.createComponentSpecFromFile(componentSpecPath);
+ new PolicyModel().createPolicyModels(inboundComponentSpec, this.modelOutputPath);
+ }
+}
diff --git a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java b/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java
deleted file mode 100644
index 3210a2f..0000000
--- a/blueprint-generator/src/main/java/org/onap/blueprintgenerator/core/PolicyCreate.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**============LICENSE_START=======================================================
- org.onap.dcae
- ================================================================================
- Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
- ================================================================================
- 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.
- ============LICENSE_END=========================================================
-
-*/
-
-package org.onap.blueprintgenerator.core;
-
-import java.util.ArrayList;
-
-import org.apache.commons.cli.BasicParser;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Options;
-import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
-import org.onap.blueprintgenerator.models.policymodel.PolicyModel;
-
-public class PolicyCreate {
-
- private static String componentSpecPath = "";
-
- private static String outputPath = "";
-
-
-
- public static void main(String[] args) throws Exception {
- printInstructions();
- parseInputs(args);
-
- ComponentSpec cs = new ComponentSpec();
- cs.createComponentSpecFromFile(componentSpecPath);
-
- PolicyModel p = new PolicyModel();
- ArrayList<PolicyModel> models = p.createPolicyModels(cs, outputPath);
- }
-
- public static void printInstructions() {
- System.out.println("OPTIONS:");
- System.out.println("-i: The path to the JSON spec file (required)");
- System.out.println("-p: The output path for all of the models (required)");
- }
-
- public static void parseInputs(String[] args) throws Exception {
- //convert the arguments array to a string to make it easier
- String commands = "";
- for(String s: args) {
- if(commands.length() == 0) {
- commands = s;
- }
- else {
- commands = commands + " " + s;
- }
- }
-
- //check if it has the required inputs
- if(!commands.contains("-p") || !commands.contains("-i")) {
- System.out.println("did not enter the required inputs");
- System.exit(0);
- }
- else {
- BasicParser parser = new BasicParser();
- Options options = new Options();
- options.addOption("i", "Spec", true, "ComponentSpec import file");
- options.addOption("p", "Path", true, "Path to the final blueprint");
-
- CommandLine commandLine = parser.parse(options, args);
- componentSpecPath = commandLine.getOptionValue("i");
- outputPath = commandLine.getOptionValue("p");
-
- }
- }
-}
diff --git a/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java b/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
index 3eeffec..404b899 100644
--- a/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
+++ b/blueprint-generator/src/test/java/org/onap/blueprintgenerator/core/BlueprintGeneratorTest.java
@@ -21,23 +21,21 @@
package org.onap.blueprintgenerator.core;
import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.TreeMap;
import org.junit.Test;
-import org.onap.blueprintgenerator.core.BlueprintGenerator;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import org.onap.blueprintgenerator.models.blueprint.Blueprint;
-import org.onap.blueprintgenerator.models.blueprint.ConcatObj;
-import org.onap.blueprintgenerator.models.blueprint.DmaapObj;
import org.onap.blueprintgenerator.models.blueprint.GetInput;
-import org.onap.blueprintgenerator.models.blueprint.Interfaces;
-import org.onap.blueprintgenerator.models.blueprint.Start;
-import org.onap.blueprintgenerator.models.blueprint.StartInputs;
import org.onap.blueprintgenerator.models.componentspec.Artifacts;
import org.onap.blueprintgenerator.models.componentspec.Auxilary;
import org.onap.blueprintgenerator.models.componentspec.CallsObj;
@@ -60,8 +58,7 @@ import org.onap.blueprintgenerator.models.policymodel.PolicyModel;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
-
-import junit.framework.Assert;
+import picocli.CommandLine;
// TODO: Auto-generated Javadoc
@@ -413,13 +410,26 @@ public class BlueprintGeneratorTest {
}
assertEquals(true, d);
}
+
+ @Test
+ public void testPrintInstructionsBlueprintCommand() {
+ BlueprintCommand objUnderTest = new BlueprintCommand();
+ CommandLine cli = new CommandLine(objUnderTest);
+ PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class);
+ ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+ cli.usage(mockStdOutWriter);
+ verify(mockStdOutWriter, times(1)).print(any(Object.class));
+
+ }
+
@Test
- public void testPrintInstructions() {
- //check if the instructions are pritns correctly and if the print statement comes out then its correct
- BlueprintGenerator bp = new BlueprintGenerator();
- bp.printInstructions();
- boolean t = true;
- assertEquals(true, t);
+ public void testPrintInstructionsPolicyCommand() {
+ PolicyCommand objUnderTest = new PolicyCommand();
+ CommandLine cli = new CommandLine(objUnderTest);
+ PrintStream mockStdOutWriter = Mockito.mock(PrintStream.class);
+ ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
+ cli.usage(mockStdOutWriter);
+ verify(mockStdOutWriter, times(1)).print(any(Object.class));
}
@Test