From a3c8fc0395e9518c5f0f064a033f4ab4d7040c61 Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Thu, 17 Dec 2020 14:27:01 +0100 Subject: Blueprint Generator - Refactor blueprint generation. Issue-ID: DCAEGEN2-2529 Signed-off-by: Remigiusz Janeczek Change-Id: I72959f3e6c27d301e46ede24c015ce638d8de324 --- .../service/base/BlueprintService.java | 2 +- .../BlueprintGeneratorMainApplication.java | 36 +- .../service/BlueprintCreatorService.java | 70 ++++ .../service/OnapBlueprintService.java | 115 ------ .../dmaap/DmaapBlueprintCreatorService.java | 164 ++++++++ .../service/dmaap/DmaapBlueprintService.java | 163 -------- .../service/onap/OnapBlueprintCreatorService.java | 116 ++++++ .../service/BlueprintCreatorServiceTest.java | 114 +++++ .../test/BlueprintGeneratorTestSuite.java | 2 +- .../test/BlueprintGeneratorTests.java | 23 +- .../test/OnapBlueprintCreatorServiceTest.java | 445 ++++++++++++++++++++ .../test/OnapBlueprintServiceTest.java | 458 --------------------- .../onap/blueprintgenerator/test/TlsInfoTest.java | 3 +- 13 files changed, 940 insertions(+), 771 deletions(-) create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/BlueprintCreatorService.java delete mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintCreatorService.java delete mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java create mode 100644 mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/onap/OnapBlueprintCreatorService.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/BlueprintCreatorServiceTest.java create mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintCreatorServiceTest.java delete mode 100644 mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java (limited to 'mod') diff --git a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java index 7dd05f2..c32e5b1 100644 --- a/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java +++ b/mod/bpgenerator/common/src/main/java/org/onap/blueprintgenerator/service/base/BlueprintService.java @@ -54,7 +54,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; * Yaml/String */ @Service -public abstract class BlueprintService { +public class BlueprintService { @Autowired protected FixesService fixesService; diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java index d680919..796424f 100644 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/BlueprintGeneratorMainApplication.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2020 Nokia. 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. @@ -23,14 +24,17 @@ package org.onap.blueprintgenerator; + +import static java.lang.System.exit; + import org.onap.blueprintgenerator.model.base.Blueprint; import org.onap.blueprintgenerator.model.common.Input; import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; import org.onap.blueprintgenerator.model.componentspec.base.ComponentSpec; -import org.onap.blueprintgenerator.service.OnapBlueprintService; +import org.onap.blueprintgenerator.service.BlueprintCreatorService; +import org.onap.blueprintgenerator.service.base.BlueprintService; import org.onap.blueprintgenerator.service.common.CommonUtils; import org.onap.blueprintgenerator.service.common.ComponentSpecService; -import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService; import org.onap.policycreate.service.PolicyModelService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; @@ -38,8 +42,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import static java.lang.System.exit; - /** * @author : Ravi Mantena * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP - Blueprint Generator Main @@ -68,10 +70,10 @@ public class BlueprintGeneratorMainApplication implements CommandLineRunner { private CommonUtils onapCommonUtils; @Autowired - private OnapBlueprintService onapBlueprintService; + private BlueprintCreatorService blueprintCreatorService; @Autowired - private DmaapBlueprintService dmaapBlueprintService; + private BlueprintService blueprintService; /** * Main Application to run BPGen to generate Policies/Blueprint based on Input Arguments values @@ -99,24 +101,10 @@ public class BlueprintGeneratorMainApplication implements CommandLineRunner { componentSpec.getParameters(), input.getOutputPath()); } else { Input input = onapCommonUtils.parseInputs(args); - OnapComponentSpec onapComponentSpec = - onapComponentSpecService - .createComponentSpecFromFile(input.getComponentSpecPath()); - if (input.getBpType().equals("o")) { - Blueprint blueprint = onapBlueprintService - .createBlueprint(onapComponentSpec, input); - onapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input); - System.out.println( - onapBlueprintService - .blueprintToString(onapComponentSpec, blueprint, input)); - } else if (input.getBpType().equals("d")) { - Blueprint blueprint = dmaapBlueprintService - .createBlueprint(onapComponentSpec, input); - dmaapBlueprintService.blueprintToYaml(onapComponentSpec, blueprint, input); - System.out.println( - dmaapBlueprintService - .blueprintToString(onapComponentSpec, blueprint, input)); - } + OnapComponentSpec onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + Blueprint blueprint = blueprintCreatorService.createBlueprint(onapComponentSpec, input); + blueprintService.blueprintToYaml(onapComponentSpec, blueprint, input); + System.out.println(blueprintService.blueprintToString(onapComponentSpec, blueprint, input)); } } diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/BlueprintCreatorService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/BlueprintCreatorService.java new file mode 100644 index 0000000..48c196e --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/BlueprintCreatorService.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (C) 2020 Nokia. 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.service; + +import org.onap.blueprintgenerator.model.base.Blueprint; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService; +import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author : Remigiusz Janeczek + * @date 12/17/2020 Application: ONAP - Blueprint Generator Service to create ONAP and DMAAP Blueprints + */ +@Service +public class BlueprintCreatorService { + + private final OnapBlueprintCreatorService onapBlueprintCreatorService; + + private final DmaapBlueprintCreatorService dmaapBlueprintCreatorService; + + @Autowired + public BlueprintCreatorService(OnapBlueprintCreatorService onapBlueprintCreatorService, + DmaapBlueprintCreatorService dmaapBlueprintCreatorService) { + this.onapBlueprintCreatorService = onapBlueprintCreatorService; + this.dmaapBlueprintCreatorService = dmaapBlueprintCreatorService; + } + + /** + * Creates Blueprint from given OnapComponentSpec and Input objects if the input is json file or not + * + * @param componentSpec OnapComponentSpec object + * @param input Input object, needs to have bpType defined (either as "o" (ONAP Blueprint) or "d" (DMAAP + * Blueprint) + * @return blueprint generated from componentSpec and input + */ + public Blueprint createBlueprint(OnapComponentSpec componentSpec, Input input) { + if (input.getBpType() == null) { + return null; + } + Blueprint blueprint = null; + if (input.getBpType().equals("o")) { + blueprint = onapBlueprintCreatorService.createBlueprint(componentSpec, input); + } else if (input.getBpType().equals("d")) { + blueprint = dmaapBlueprintCreatorService.createBlueprint(componentSpec, input); + } + return blueprint; + } + +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java deleted file mode 100644 index 748facf..0000000 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/OnapBlueprintService.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * * ============LICENSE_START======================================================= - * * org.onap.dcae - * * ================================================================================ - * * Copyright (c) 2020 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.service; - -import org.onap.blueprintgenerator.constants.Constants; -import org.onap.blueprintgenerator.exception.BlueprintException; -import org.onap.blueprintgenerator.model.common.Input; -import org.onap.blueprintgenerator.model.common.Node; -import org.onap.blueprintgenerator.model.common.OnapBlueprint; -import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; -import org.onap.blueprintgenerator.service.base.BlueprintService; -import org.onap.blueprintgenerator.service.common.ImportsService; -import org.onap.blueprintgenerator.service.common.NodeService; -import org.onap.blueprintgenerator.service.common.PgaasNodeService; -import org.onap.blueprintgenerator.service.common.PolicyNodeService; -import org.onap.blueprintgenerator.service.common.QuotationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.TreeMap; - -/** - * @author : Ravi Mantena - * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create ONAP Blueprint - */ -@Service -public class OnapBlueprintService extends BlueprintService { - - @Autowired - private NodeService nodeService; - - @Autowired - private PolicyNodeService policyNodeService; - - @Autowired - private PgaasNodeService pgaasNodeService; - - @Autowired - private QuotationService quotationService; - - @Autowired - protected ImportsService importsService; - - /** - * Creates Onap Blueprint - * - * @param onapComponentSpec OnapComponentSpec - * @param input Inputs - * @return - */ - public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { - try { - OnapBlueprint blueprint = new OnapBlueprint(); - blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); - - // if (!"".equals(input.getImportPath())) - if (!StringUtils.isEmpty(input.getImportPath())) { - blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); - } else { - blueprint.setImports(importsService.createImports(input.getBpType())); - } - - Map nodeTemplate = new TreeMap<>(); - String nodeName = onapComponentSpec.getSelf().getName(); - Map> inputs = new TreeMap<>(); - - Map onapNodeResponse = - nodeService - .createOnapNode(inputs, onapComponentSpec, input.getServiceNameOverride()); - inputs = (Map>) onapNodeResponse.get("inputs"); - nodeTemplate.put(nodeName, (Node) onapNodeResponse.get("onapNode")); - blueprint.setNode_templates(nodeTemplate); - - if (onapComponentSpec.getPolicyInfo() != null) { - policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); - } - - if (onapComponentSpec.getAuxilary() != null - && onapComponentSpec.getAuxilary().getDatabases() != null) { - pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); - } - - blueprint.setInputs(inputs); - - return quotationService.setQuotations(blueprint); - } catch (Exception ex) { - throw new BlueprintException( - "Unable to create ONAP Blueprint Object from given input parameters", ex); - } - } -} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintCreatorService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintCreatorService.java new file mode 100644 index 0000000..bf68f81 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintCreatorService.java @@ -0,0 +1,164 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2020 Nokia. 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.service.dmaap; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.exception.BlueprintException; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.model.componentspec.common.Publishes; +import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; +import org.onap.blueprintgenerator.service.base.BlueprintHelperService; +import org.onap.blueprintgenerator.service.base.BlueprintService; +import org.onap.blueprintgenerator.service.common.ImportsService; +import org.onap.blueprintgenerator.service.common.NodeService; +import org.onap.blueprintgenerator.service.common.PgaasNodeService; +import org.onap.blueprintgenerator.service.common.PolicyNodeService; +import org.onap.blueprintgenerator.service.common.QuotationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint + */ +@Service +public class DmaapBlueprintCreatorService { + + @Autowired + protected ImportsService importsService; + + @Autowired + private NodeService nodeService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private QuotationService quotationService; + + @Autowired + private BlueprintHelperService blueprintHelperService; + + /** + * Creates Dmaap Blueprint + * + * @param onapComponentSpec OnapComponentSpec + * @param input Inputs + * @return + */ + public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { + try { + OnapBlueprint blueprint = new OnapBlueprint(); + blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); + blueprint.setDescription(onapComponentSpec.getSelf().getDescription()); + + Map> inputs = new TreeMap<>(); + + // if (!"".equals(input.getImportPath())) + if (!StringUtils.isEmpty(input.getImportPath())) { + blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); + } else { + blueprint.setImports(importsService.createImports(input.getBpType())); + } + + Map nodeTemplate = new TreeMap(); + + Map dmaapNodeResponse = + nodeService + .createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride()); + inputs = (Map>) dmaapNodeResponse.get("inputs"); + nodeTemplate.put( + onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode")); + + if (onapComponentSpec.getStreams() != null) { + if (onapComponentSpec.getStreams().getPublishes() != null) { + for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) { + if (blueprintHelperService.isMessageRouterType(publishes.getType())) { + String topic = publishes.getConfig_key() + Constants._TOPIC; + Map topicNodeResponse = nodeService + .createTopicNode(inputs, topic); + inputs = (Map>) topicNodeResponse + .get("inputs"); + nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); + } else if (blueprintHelperService.isDataRouterType(publishes.getType())) { + String feed = publishes.getConfig_key() + Constants._FEED; + Map feedNodeResponse = nodeService + .createFeedNode(inputs, feed); + inputs = (Map>) feedNodeResponse + .get("inputs"); + nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); + } + } + } + if (onapComponentSpec.getStreams().getSubscribes() != null) { + for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) { + if (blueprintHelperService.isMessageRouterType(s.getType())) { + String topic = s.getConfig_key() + Constants._TOPIC; + Map topicNodeResponse = nodeService + .createTopicNode(inputs, topic); + inputs = (Map>) topicNodeResponse + .get("inputs"); + nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); + } else if (blueprintHelperService.isDataRouterType(s.getType())) { + String feed = s.getConfig_key() + Constants._FEED; + Map feedNodeResponse = nodeService + .createFeedNode(inputs, feed); + inputs = (Map>) feedNodeResponse + .get("inputs"); + nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); + } + } + } + } + + if (onapComponentSpec.getPolicyInfo() != null) { + policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + } + + if (onapComponentSpec.getAuxilary() != null + && onapComponentSpec.getAuxilary().getDatabases() != null) { + pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + } + + blueprint.setNode_templates(nodeTemplate); + blueprint.setInputs(inputs); + return quotationService.setQuotations(blueprint); + } catch (Exception ex) { + throw new BlueprintException( + "Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex); + } + } +} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java deleted file mode 100644 index 9da2074..0000000 --- a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/dmaap/DmaapBlueprintService.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * - * * ============LICENSE_START======================================================= - * * org.onap.dcae - * * ================================================================================ - * * Copyright (c) 2020 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.service.dmaap; - -import org.onap.blueprintgenerator.constants.Constants; -import org.onap.blueprintgenerator.exception.BlueprintException; -import org.onap.blueprintgenerator.model.common.Input; -import org.onap.blueprintgenerator.model.common.Node; -import org.onap.blueprintgenerator.model.common.OnapBlueprint; -import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; -import org.onap.blueprintgenerator.model.componentspec.common.Publishes; -import org.onap.blueprintgenerator.model.componentspec.common.Subscribes; -import org.onap.blueprintgenerator.service.base.BlueprintHelperService; -import org.onap.blueprintgenerator.service.base.BlueprintService; -import org.onap.blueprintgenerator.service.common.ImportsService; -import org.onap.blueprintgenerator.service.common.NodeService; -import org.onap.blueprintgenerator.service.common.PgaasNodeService; -import org.onap.blueprintgenerator.service.common.PolicyNodeService; -import org.onap.blueprintgenerator.service.common.QuotationService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.TreeMap; - -/** - * @author : Ravi Mantena - * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create DMAAP Blueprint - */ -@Service -public class DmaapBlueprintService extends BlueprintService { - - @Autowired - protected ImportsService importsService; - - @Autowired - private NodeService nodeService; - - @Autowired - private PolicyNodeService policyNodeService; - - @Autowired - private PgaasNodeService pgaasNodeService; - - @Autowired - private QuotationService quotationService; - - @Autowired - private BlueprintHelperService blueprintHelperService; - - /** - * Creates Dmaap Blueprint - * - * @param onapComponentSpec OnapComponentSpec - * @param input Inputs - * @return - */ - public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { - try { - OnapBlueprint blueprint = new OnapBlueprint(); - blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); - blueprint.setDescription(onapComponentSpec.getSelf().getDescription()); - - Map> inputs = new TreeMap<>(); - - // if (!"".equals(input.getImportPath())) - if (!StringUtils.isEmpty(input.getImportPath())) { - blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); - } else { - blueprint.setImports(importsService.createImports(input.getBpType())); - } - - Map nodeTemplate = new TreeMap(); - - Map dmaapNodeResponse = - nodeService - .createDmaapNode(onapComponentSpec, inputs, input.getServiceNameOverride()); - inputs = (Map>) dmaapNodeResponse.get("inputs"); - nodeTemplate.put( - onapComponentSpec.getSelf().getName(), (Node) dmaapNodeResponse.get("dmaapNode")); - - if (onapComponentSpec.getStreams() != null) { - if (onapComponentSpec.getStreams().getPublishes() != null) { - for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) { - if (blueprintHelperService.isMessageRouterType(publishes.getType())) { - String topic = publishes.getConfig_key() + Constants._TOPIC; - Map topicNodeResponse = nodeService - .createTopicNode(inputs, topic); - inputs = (Map>) topicNodeResponse - .get("inputs"); - nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); - } else if (blueprintHelperService.isDataRouterType(publishes.getType())) { - String feed = publishes.getConfig_key() + Constants._FEED; - Map feedNodeResponse = nodeService - .createFeedNode(inputs, feed); - inputs = (Map>) feedNodeResponse - .get("inputs"); - nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); - } - } - } - if (onapComponentSpec.getStreams().getSubscribes() != null) { - for (Subscribes s : onapComponentSpec.getStreams().getSubscribes()) { - if (blueprintHelperService.isMessageRouterType(s.getType())) { - String topic = s.getConfig_key() + Constants._TOPIC; - Map topicNodeResponse = nodeService - .createTopicNode(inputs, topic); - inputs = (Map>) topicNodeResponse - .get("inputs"); - nodeTemplate.put(topic, (Node) topicNodeResponse.get("topicNode")); - } else if (blueprintHelperService.isDataRouterType(s.getType())) { - String feed = s.getConfig_key() + Constants._FEED; - Map feedNodeResponse = nodeService - .createFeedNode(inputs, feed); - inputs = (Map>) feedNodeResponse - .get("inputs"); - nodeTemplate.put(feed, (Node) feedNodeResponse.get("feedNode")); - } - } - } - } - - if (onapComponentSpec.getPolicyInfo() != null) { - policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); - } - - if (onapComponentSpec.getAuxilary() != null - && onapComponentSpec.getAuxilary().getDatabases() != null) { - pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); - } - - blueprint.setNode_templates(nodeTemplate); - blueprint.setInputs(inputs); - return quotationService.setQuotations(blueprint); - } catch (Exception ex) { - throw new BlueprintException( - "Unable to create ONAP DMAAP Blueprint Object from given input parameters", ex); - } - } -} diff --git a/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/onap/OnapBlueprintCreatorService.java b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/onap/OnapBlueprintCreatorService.java new file mode 100644 index 0000000..afc02f3 --- /dev/null +++ b/mod/bpgenerator/onap/src/main/java/org/onap/blueprintgenerator/service/onap/OnapBlueprintCreatorService.java @@ -0,0 +1,116 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2020 Nokia. 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.service.onap; + +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.exception.BlueprintException; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.base.BlueprintService; +import org.onap.blueprintgenerator.service.common.ImportsService; +import org.onap.blueprintgenerator.service.common.NodeService; +import org.onap.blueprintgenerator.service.common.PgaasNodeService; +import org.onap.blueprintgenerator.service.common.PolicyNodeService; +import org.onap.blueprintgenerator.service.common.QuotationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 Application: ONAP - Blueprint Generator Service to create ONAP Blueprint + */ +@Service +public class OnapBlueprintCreatorService { + + @Autowired + private NodeService nodeService; + + @Autowired + private PolicyNodeService policyNodeService; + + @Autowired + private PgaasNodeService pgaasNodeService; + + @Autowired + private QuotationService quotationService; + + @Autowired + protected ImportsService importsService; + + /** + * Creates Onap Blueprint + * + * @param onapComponentSpec OnapComponentSpec + * @param input Inputs + * @return + */ + public OnapBlueprint createBlueprint(OnapComponentSpec onapComponentSpec, Input input) { + try { + OnapBlueprint blueprint = new OnapBlueprint(); + blueprint.setTosca_definitions_version(Constants.TOSCA_DEF_VERSION); + + // if (!"".equals(input.getImportPath())) + if (!StringUtils.isEmpty(input.getImportPath())) { + blueprint.setImports(importsService.createImportsFromFile(input.getImportPath())); + } else { + blueprint.setImports(importsService.createImports(input.getBpType())); + } + + Map nodeTemplate = new TreeMap<>(); + String nodeName = onapComponentSpec.getSelf().getName(); + Map> inputs = new TreeMap<>(); + + Map onapNodeResponse = + nodeService + .createOnapNode(inputs, onapComponentSpec, input.getServiceNameOverride()); + inputs = (Map>) onapNodeResponse.get("inputs"); + nodeTemplate.put(nodeName, (Node) onapNodeResponse.get("onapNode")); + blueprint.setNode_templates(nodeTemplate); + + if (onapComponentSpec.getPolicyInfo() != null) { + policyNodeService.addPolicyNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + } + + if (onapComponentSpec.getAuxilary() != null + && onapComponentSpec.getAuxilary().getDatabases() != null) { + pgaasNodeService.addPgaasNodesAndInputs(onapComponentSpec, nodeTemplate, inputs); + } + + blueprint.setInputs(inputs); + + return quotationService.setQuotations(blueprint); + } catch (Exception ex) { + throw new BlueprintException( + "Unable to create ONAP Blueprint Object from given input parameters", ex); + } + } +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/BlueprintCreatorServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/BlueprintCreatorServiceTest.java new file mode 100644 index 0000000..c1e46f2 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/service/BlueprintCreatorServiceTest.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START======================================================= + * org.onap.dcae + * ================================================================================ + * Copyright (C) 2020 Nokia. 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.service; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.onap.blueprintgenerator.model.base.Blueprint; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService; +import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService; + +public class BlueprintCreatorServiceTest { + + private static final String ONAP_BP_TYPE = "o"; + private static final String DMAAP_BP_TYPE = "d"; + private static final String INCORRECT_BP_TYPE = "z"; + + private OnapBlueprintCreatorService onapBlueprintCreatorService; + private DmaapBlueprintCreatorService dmaapBlueprintCreatorService; + private BlueprintCreatorService blueprintCreatorService; + + @Before + public void setup() { + onapBlueprintCreatorService = mock(OnapBlueprintCreatorService.class); + dmaapBlueprintCreatorService = mock(DmaapBlueprintCreatorService.class); + blueprintCreatorService = new BlueprintCreatorService(onapBlueprintCreatorService, + dmaapBlueprintCreatorService); + } + + @Test + public void shouldCreateOnapBlueprint() { + OnapComponentSpec cs = new OnapComponentSpec(); + Input input = new Input(); + input.setBpType(ONAP_BP_TYPE); + when(onapBlueprintCreatorService.createBlueprint(any(), any())).thenReturn(new OnapBlueprint()); + + Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input); + + verify(onapBlueprintCreatorService, times(1)).createBlueprint(cs, input); + verify(onapBlueprintCreatorService, times(1)).createBlueprint(cs, input); + verifyNoInteractions(dmaapBlueprintCreatorService); + assertNotNull(blueprint); + } + + @Test + public void shouldCreateDmaapBlueprint() { + OnapComponentSpec cs = new OnapComponentSpec(); + Input input = new Input(); + input.setBpType(DMAAP_BP_TYPE); + when(dmaapBlueprintCreatorService.createBlueprint(any(), any())).thenReturn(new OnapBlueprint()); + + Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input); + + verify(dmaapBlueprintCreatorService, times(1)).createBlueprint(cs, input); + verify(dmaapBlueprintCreatorService, times(1)).createBlueprint(cs, input); + verifyNoInteractions(onapBlueprintCreatorService); + assertNotNull(blueprint); + } + + @Test + public void shouldReturnNullWhenBpTypeNotDefined(){ + OnapComponentSpec cs = new OnapComponentSpec(); + Input input = new Input(); + + Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input); + + verifyNoInteractions(onapBlueprintCreatorService); + verifyNoInteractions(dmaapBlueprintCreatorService); + assertNull(blueprint); + } + + @Test + public void shouldReturnNullWhenBpTypeIncorrect(){ + OnapComponentSpec cs = new OnapComponentSpec(); + Input input = new Input(); + input.setBpType(INCORRECT_BP_TYPE); + + Blueprint blueprint = blueprintCreatorService.createBlueprint(cs, input); + + verifyNoInteractions(onapBlueprintCreatorService); + verifyNoInteractions(dmaapBlueprintCreatorService); + assertNull(blueprint); + } + +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java index d15be4d..5c90acd 100644 --- a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTestSuite.java @@ -33,7 +33,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ OnapComponentSpecTest.class, - OnapBlueprintServiceTest.class, + OnapBlueprintCreatorServiceTest.class, ExternalCertificateParametersFactoryServiceTest.class /*, BlueprintJarComparatorTest.class*/ }) public class BlueprintGeneratorTestSuite { diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java index 81aaa60..86d257a 100644 --- a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/BlueprintGeneratorTests.java @@ -4,6 +4,7 @@ * * org.onap.dcae * * ================================================================================ * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2020 Nokia. 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. @@ -23,14 +24,16 @@ package org.onap.blueprintgenerator.test; -import org.onap.blueprintgenerator.BlueprintGeneratorMainApplication; -import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; -import org.onap.blueprintgenerator.service.OnapBlueprintService; -import org.onap.blueprintgenerator.service.common.ComponentSpecService; -import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintService; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Ignore; import org.junit.runner.RunWith; +import org.onap.blueprintgenerator.BlueprintGeneratorMainApplication; +import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec; +import org.onap.blueprintgenerator.service.BlueprintCreatorService; +import org.onap.blueprintgenerator.service.base.BlueprintService; +import org.onap.blueprintgenerator.service.common.ComponentSpecService; +import org.onap.blueprintgenerator.service.dmaap.DmaapBlueprintCreatorService; +import org.onap.blueprintgenerator.service.onap.OnapBlueprintCreatorService; import org.onap.policycreate.service.PolicyModelService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -90,10 +93,16 @@ public class BlueprintGeneratorTests { protected ComponentSpecService onapComponentSpecService; @Autowired - protected DmaapBlueprintService dmaapBlueprintService; + protected DmaapBlueprintCreatorService dmaapBlueprintCreatorService; + + @Autowired + protected OnapBlueprintCreatorService onapBlueprintCreatorService; + + @Autowired + protected BlueprintCreatorService blueprintCreatorService; @Autowired - protected OnapBlueprintService onapBlueprintService; + protected BlueprintService blueprintService; @Autowired protected PolicyModelService policyModelService; diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintCreatorServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintCreatorServiceTest.java new file mode 100644 index 0000000..866a324 --- /dev/null +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintCreatorServiceTest.java @@ -0,0 +1,445 @@ +/* + * + * * ============LICENSE_START======================================================= + * * org.onap.dcae + * * ================================================================================ + * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. + * * Copyright (c) 2020 Nokia. 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.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.junit.jupiter.api.DisplayName; +import org.onap.blueprintgenerator.constants.Constants; +import org.onap.blueprintgenerator.model.common.Input; +import org.onap.blueprintgenerator.model.common.Node; +import org.onap.blueprintgenerator.model.common.OnapBlueprint; +import org.onap.blueprintgenerator.model.common.Properties; + +/** + * @author : Ravi Mantena + * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and + * DMAAP + */ + + +public class OnapBlueprintCreatorServiceTest extends BlueprintGeneratorTests { + + private String outputfilesPath = + Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString(); + + /** + * Test Case for Service Name Override Component Spec Input File + * + */ + @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File") + @Test + public void testServiceNameOverrideK8sBlueprint() throws IOException { + Input input = + onapTestUtils.getInput( + Paths.get("src", "test", "resources", "componentspecs", ves).toFile() + .getAbsolutePath(), + outputfilesPath, + "testServiceNameOverrideK8sBlueprint", + "", + "o", + ""); + onapComponentSpec = + onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull( + "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); + blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); + + onapTestUtils.verifyToscaDefVersion( + "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue( + "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + assertEquals( + "Service Name Override K8s Blueprint:Inputs " + + Constants.ONAP_INPUT_CPU_LIMIT + + " Default is not matching", + k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), + Constants.ONAP_DEFAULT250m); + assertEquals( + "Service Name Override K8s Blueprint:Inputs " + + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + + " Default is not matching", + k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), + Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull( + "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", + k8sBpNodeTemplates); + assertTrue( + "Service Name Override K8s Blueprint Node Templates Section Size is Empty", + k8sBpNodeTemplates.size() > 0); + + assertEquals( + "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching", + k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), + Constants.ONAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull( + "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL", + k8sBpNodeTemplateProperties); + + Map> bpInputs = onapBlueprint.getInputs(); + onapTestUtils + .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o"); + + onapTestUtils.verifyStreamsPublishes( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("Service Name Override K8s", onapComponentSpec); + onapTestUtils.verifyHealthCheck( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("Service Name Override K8s", onapComponentSpec); + onapTestUtils.verifyServicesProvides("Service Name Override K8s", onapComponentSpec); + onapTestUtils.verifyDockerConfig( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplates); + onapTestUtils.verifyVolumes( + "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + } + + /** + * Test Case for Service Name Override Component Spec Input File with Import File + * + */ + @DisplayName( + "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File") + @Test + public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException { + Input input = + onapTestUtils.getInput( + Paths.get("src", "test", "resources", "componentspecs", ves).toFile() + .getAbsolutePath(), + "", + "", + Paths.get("src", "test", "resources", "componentspecs", testImports) + .toFile() + .getAbsolutePath(), + "o", + ""); + onapComponentSpec = + onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull( + "K8s Blueprint for Service Name Override with Import File Component Spec is NULL", + onapComponentSpec); + + OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); + + onapTestUtils.verifyToscaDefVersion( + "Service Name Override with Import File K8s", onapBlueprint, + Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImportsFromFile( + "Service Name Override with Import File K8s", onapBlueprint, input.getImportPath()); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull( + "Service Name Override with Import File K8s Blueprint Inputs Section is NULL", + k8sBpInputs); + assertTrue( + "Service Name Override with Import File K8s Blueprint Inputs Section is Empty", + k8sBpInputs.size() > 0); + + assertEquals( + "Service Name Override with Import File K8s Blueprint:Inputs " + + Constants.ONAP_INPUT_CPU_LIMIT + + " Default is not matching", + k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), + Constants.ONAP_DEFAULT250m); + assertEquals( + "Service Name Override with Import File K8s Blueprint:Inputs " + + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + + " Default is not matching", + k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), + Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull( + "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", + k8sBpNodeTemplates); + assertTrue( + "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty", + k8sBpNodeTemplates.size() > 0); + + assertEquals( + "Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching", + k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), + Constants.ONAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull( + "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL", + k8sBpNodeTemplateProperties); + + Map> bpInputs = onapBlueprint.getInputs(); + onapTestUtils.verifyArtifacts( + "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o"); + + onapTestUtils.verifyStreamsPublishes( + "Service Name Override with Import File K8s", + onapComponentSpec, + k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes( + "Service Name Override with Import File K8s", + onapComponentSpec, + k8sBpNodeTemplateProperties); + onapTestUtils + .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec); + onapTestUtils.verifyHealthCheck( + "Service Name Override with Import File K8s", + onapComponentSpec, + k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls( + "Service Name Override with Import File K8s", onapComponentSpec); + onapTestUtils.verifyServicesProvides( + "Service Name Override with Import File K8s", onapComponentSpec); + onapTestUtils.verifyDockerConfig( + "Service Name Override with Import File K8s", + onapComponentSpec, + k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters( + "Service Name Override with Import File K8s", onapComponentSpec, k8sBpNodeTemplates); + onapTestUtils.verifyVolumes( + "Service Name Override with Import File K8s", + onapComponentSpec, + k8sBpNodeTemplateProperties); + } + + /** + * Test Case for K8s Blueprint with DB + * + */ + @DisplayName("Testing K8s Blueprint with DB") + @Test + public void testDMAAPK8sBlueprintWithDB() { + Input input = + onapTestUtils.getInput( + Paths.get("src", "test", "resources", "componentspecs", ves).toFile() + .getAbsolutePath(), + outputfilesPath, + "testDMAAPK8sBlueprintWithDB", + "", + "d", + ""); + onapComponentSpec = + onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); + blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + } + + /** + * Test Case for K8s Blueprint for DMAAP Component Spec Input File + * + */ + @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File") + @Test + public void testDMAAPK8sBlueprint() { + Input input = + onapTestUtils.getInput( + Paths.get("src", "test", "resources", "componentspecs", ves).toFile() + .getAbsolutePath(), + outputfilesPath, + "testDMAAPK8sBlueprint", + "", + "d", + ""); + onapComponentSpec = + onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); + blueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); + System.out.println(blueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); + + policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models"); + + onapTestUtils + .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + assertEquals( + "DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT + + " Default is not matching", + k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), + Constants.ONAP_DEFAULT250m); + assertEquals( + "DMAAP K8s Blueprint:Inputs " + + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + + " Default is not matching", + k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), + Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull( + "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", + k8sBpNodeTemplates); + assertTrue( + "DMAAP K8s Blueprint Node Templates Section Size is Empty", + k8sBpNodeTemplates.size() > 0); + + assertEquals( + "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching", + k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), + Constants.DMAAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull( + "DMAAP K8s Blueprint Node Templates:Properties Section is NULL", + k8sBpNodeTemplateProperties); + + List bpNodeTemplateRelationships = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); + assertNotNull( + "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL", + bpNodeTemplateRelationships); + + onapTestUtils.verifyStreamsPublishes( + "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes( + "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec); + onapTestUtils + .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec); + onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec); + onapTestUtils + .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates); + } + + /** + * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File + * + */ + @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File") + @Test + public void testDMAAPK8sImportFileBlueprint() throws IOException { + Input input = + onapTestUtils.getInput( + Paths.get("src", "test", "resources", "componentspecs", ves).toFile() + .getAbsolutePath(), + "", + "", + Paths.get("src", "test", "resources", "componentspecs", testImports) + .toFile() + .getAbsolutePath(), + "d", + ""); + onapComponentSpec = + onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); + assertNotNull( + "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec); + + OnapBlueprint onapBlueprint = dmaapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); + + onapTestUtils.verifyToscaDefVersion( + "DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); + onapTestUtils.verifyBpImportsFromFile( + "DMAAP with Import File K8s", onapBlueprint, input.getImportPath()); + + Map> k8sBpInputs = onapBlueprint.getInputs(); + assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs); + assertTrue( + "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); + + assertEquals( + "DMAAP with Import File K8s Blueprint:Inputs " + + Constants.ONAP_INPUT_CPU_LIMIT + + " Default is not matching", + k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), + Constants.ONAP_DEFAULT250m); + assertEquals( + "DMAAP with Import File K8s Blueprint:Inputs " + + Constants.SERVICE_COMPONENT_NAME_OVERRIDE + + " Default is not matching", + k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), + Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); + + Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); + assertNotNull( + "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", + k8sBpNodeTemplates); + assertTrue( + "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty", + k8sBpNodeTemplates.size() > 0); + + assertEquals( + "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching", + k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), + Constants.DMAAP_NODETEMPLATES_TYPE); + + Properties k8sBpNodeTemplateProperties = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); + assertNotNull( + "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL", + k8sBpNodeTemplateProperties); + + List bpNodeTemplateRelationships = + ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); + assertNotNull( + "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL", + bpNodeTemplateRelationships); + + onapTestUtils.verifyStreamsPublishes( + "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyStreamsSubscribes( + "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyAuxilary("DMAAP with Import File K8s", onapComponentSpec); + onapTestUtils.verifyHealthCheck( + "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s", onapComponentSpec); + onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s", onapComponentSpec); + onapTestUtils.verifyDockerConfig( + "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); + onapTestUtils.verifyParameters( + "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplates); + } +} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java deleted file mode 100644 index 8f4a1f6..0000000 --- a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/OnapBlueprintServiceTest.java +++ /dev/null @@ -1,458 +0,0 @@ -/* - * - * * ============LICENSE_START======================================================= - * * org.onap.dcae - * * ================================================================================ - * * Copyright (c) 2020 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.test; - -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.onap.blueprintgenerator.constants.Constants; -import org.onap.blueprintgenerator.model.common.Input; -import org.onap.blueprintgenerator.model.common.Node; -import org.onap.blueprintgenerator.model.common.OnapBlueprint; -import org.onap.blueprintgenerator.model.common.Properties; -import org.junit.Test; -import org.junit.jupiter.api.DisplayName; -import picocli.CommandLine; - -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.Paths; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertArrayEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -/** - * @author : Ravi Mantena - * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Blueprint Test Cases for ONAP and - * DMAAP - */ -public class OnapBlueprintServiceTest extends BlueprintGeneratorTests { - - private String outputfilesPath = - Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString(); - - /** - * Test Case for Service Name Override Component Spec Input File - * - */ - @DisplayName("Testing K8s Blueprint for Service Name Override Component Spec Input File") - @Test - public void testServiceNameOverrideK8sBlueprint() throws IOException { - Input input = - onapTestUtils.getInput( - Paths.get("src", "test", "resources", "componentspecs", ves).toFile() - .getAbsolutePath(), - outputfilesPath, - "testServiceNameOverrideK8sBlueprint", - "", - "o", - ""); - onapComponentSpec = - onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); - assertNotNull( - "K8s Blueprint for Service Name Override Component Spec is NULL", onapComponentSpec); - - OnapBlueprint onapBlueprint = onapBlueprintService - .createBlueprint(onapComponentSpec, input); - onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); - System.out.println( - onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); - - onapTestUtils.verifyToscaDefVersion( - "Service Name Override K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); - onapTestUtils.verifyBpImports("Service Name Override K8s", onapBlueprint, false); - - Map> k8sBpInputs = onapBlueprint.getInputs(); - assertNotNull("Service Name Override K8s Blueprint Inputs Section is NULL", k8sBpInputs); - assertTrue( - "Service Name Override K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); - - assertEquals( - "Service Name Override K8s Blueprint:Inputs " - + Constants.ONAP_INPUT_CPU_LIMIT - + " Default is not matching", - k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), - Constants.ONAP_DEFAULT250m); - assertEquals( - "Service Name Override K8s Blueprint:Inputs " - + Constants.SERVICE_COMPONENT_NAME_OVERRIDE - + " Default is not matching", - k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), - Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); - - Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); - assertNotNull( - "Service Name Override K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", - k8sBpNodeTemplates); - assertTrue( - "Service Name Override K8s Blueprint Node Templates Section Size is Empty", - k8sBpNodeTemplates.size() > 0); - - assertEquals( - "Service Name Override K8s Blueprint:NodeTemplates:Type is not Matching", - k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), - Constants.ONAP_NODETEMPLATES_TYPE); - - Properties k8sBpNodeTemplateProperties = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); - assertNotNull( - "Service Name Override K8s Blueprint Node Templates:Properties Section is NULL", - k8sBpNodeTemplateProperties); - - Map> bpInputs = onapBlueprint.getInputs(); - onapTestUtils - .verifyArtifacts("Service Name Override K8s", onapComponentSpec, bpInputs, "o"); - - onapTestUtils.verifyStreamsPublishes( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyStreamsSubscribes( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyAuxilary("Service Name Override K8s", onapComponentSpec); - onapTestUtils.verifyHealthCheck( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyServicesCalls("Service Name Override K8s", onapComponentSpec); - onapTestUtils.verifyServicesProvides("Service Name Override K8s", onapComponentSpec); - onapTestUtils.verifyDockerConfig( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyParameters( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplates); - onapTestUtils.verifyVolumes( - "Service Name Override K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - } - - /** - * Test Case for Service Name Override Component Spec Input File with Import File - * - */ - @DisplayName( - "Testing K8s Blueprint for Service Name Override Component Spec Input File with Import File") - @Test - public void testServiceNameOverrideImportFileK8sBlueprint() throws IOException { - Input input = - onapTestUtils.getInput( - Paths.get("src", "test", "resources", "componentspecs", ves).toFile() - .getAbsolutePath(), - "", - "", - Paths.get("src", "test", "resources", "componentspecs", testImports) - .toFile() - .getAbsolutePath(), - "o", - ""); - onapComponentSpec = - onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); - assertNotNull( - "K8s Blueprint for Service Name Override with Import File Component Spec is NULL", - onapComponentSpec); - - OnapBlueprint onapBlueprint = onapBlueprintService - .createBlueprint(onapComponentSpec, input); - - onapTestUtils.verifyToscaDefVersion( - "Service Name Override with Import File K8s", onapBlueprint, - Constants.TOSCA_DEF_VERSION); - onapTestUtils.verifyBpImportsFromFile( - "Service Name Override with Import File K8s", onapBlueprint, input.getImportPath()); - - Map> k8sBpInputs = onapBlueprint.getInputs(); - assertNotNull( - "Service Name Override with Import File K8s Blueprint Inputs Section is NULL", - k8sBpInputs); - assertTrue( - "Service Name Override with Import File K8s Blueprint Inputs Section is Empty", - k8sBpInputs.size() > 0); - - assertEquals( - "Service Name Override with Import File K8s Blueprint:Inputs " - + Constants.ONAP_INPUT_CPU_LIMIT - + " Default is not matching", - k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), - Constants.ONAP_DEFAULT250m); - assertEquals( - "Service Name Override with Import File K8s Blueprint:Inputs " - + Constants.SERVICE_COMPONENT_NAME_OVERRIDE - + " Default is not matching", - k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), - Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); - - Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); - assertNotNull( - "Service Name Override with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", - k8sBpNodeTemplates); - assertTrue( - "Service Name Override with Import File K8s Blueprint Node Templates Section Size is Empty", - k8sBpNodeTemplates.size() > 0); - - assertEquals( - "Service Name Override with Import File K8s Blueprint:NodeTemplates:Type is not Matching", - k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), - Constants.ONAP_NODETEMPLATES_TYPE); - - Properties k8sBpNodeTemplateProperties = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); - assertNotNull( - "Service Name Override with Import File K8s Blueprint Node Templates:Properties Section is NULL", - k8sBpNodeTemplateProperties); - - Map> bpInputs = onapBlueprint.getInputs(); - onapTestUtils.verifyArtifacts( - "Service Name Override with Import File K8s", onapComponentSpec, bpInputs, "o"); - - onapTestUtils.verifyStreamsPublishes( - "Service Name Override with Import File K8s", - onapComponentSpec, - k8sBpNodeTemplateProperties); - onapTestUtils.verifyStreamsSubscribes( - "Service Name Override with Import File K8s", - onapComponentSpec, - k8sBpNodeTemplateProperties); - onapTestUtils - .verifyAuxilary("Service Name Override with Import File K8s", onapComponentSpec); - onapTestUtils.verifyHealthCheck( - "Service Name Override with Import File K8s", - onapComponentSpec, - k8sBpNodeTemplateProperties); - onapTestUtils.verifyServicesCalls( - "Service Name Override with Import File K8s", onapComponentSpec); - onapTestUtils.verifyServicesProvides( - "Service Name Override with Import File K8s", onapComponentSpec); - onapTestUtils.verifyDockerConfig( - "Service Name Override with Import File K8s", - onapComponentSpec, - k8sBpNodeTemplateProperties); - onapTestUtils.verifyParameters( - "Service Name Override with Import File K8s", onapComponentSpec, k8sBpNodeTemplates); - onapTestUtils.verifyVolumes( - "Service Name Override with Import File K8s", - onapComponentSpec, - k8sBpNodeTemplateProperties); - } - - /** - * Test Case for K8s Blueprint with DB - * - */ - @DisplayName("Testing K8s Blueprint with DB") - @Test - public void testDMAAPK8sBlueprintWithDB() { - Input input = - onapTestUtils.getInput( - Paths.get("src", "test", "resources", "componentspecs", ves).toFile() - .getAbsolutePath(), - outputfilesPath, - "testDMAAPK8sBlueprintWithDB", - "", - "d", - ""); - onapComponentSpec = - onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); - assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); - - OnapBlueprint onapBlueprint = dmaapBlueprintService - .createBlueprint(onapComponentSpec, input); - onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); - } - - /** - * Test Case for K8s Blueprint for DMAAP Component Spec Input File - * - */ - @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File") - @Test - public void testDMAAPK8sBlueprint() { - Input input = - onapTestUtils.getInput( - Paths.get("src", "test", "resources", "componentspecs", ves).toFile() - .getAbsolutePath(), - outputfilesPath, - "testDMAAPK8sBlueprint", - "", - "d", - ""); - onapComponentSpec = - onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); - assertNotNull("K8s Blueprint for DMAAP Component Spec is NULL", onapComponentSpec); - - OnapBlueprint onapBlueprint = dmaapBlueprintService - .createBlueprint(onapComponentSpec, input); - onapBlueprintService.blueprintToYaml(onapComponentSpec, onapBlueprint, input); - System.out.println( - onapBlueprintService.blueprintToString(onapComponentSpec, onapBlueprint, input)); - - policyModelService.createPolicyModels(onapComponentSpec.getParameters(), "models"); - - onapTestUtils - .verifyToscaDefVersion("DMAAP K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); - - Map> k8sBpInputs = onapBlueprint.getInputs(); - assertNotNull("DMAAP K8s Blueprint Inputs Section is NULL", k8sBpInputs); - assertTrue("DMAAP K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); - - assertEquals( - "DMAAP K8s Blueprint:Inputs " + Constants.ONAP_INPUT_CPU_LIMIT - + " Default is not matching", - k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), - Constants.ONAP_DEFAULT250m); - assertEquals( - "DMAAP K8s Blueprint:Inputs " - + Constants.SERVICE_COMPONENT_NAME_OVERRIDE - + " Default is not matching", - k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), - Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); - - Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); - assertNotNull( - "DMAAP K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", - k8sBpNodeTemplates); - assertTrue( - "DMAAP K8s Blueprint Node Templates Section Size is Empty", - k8sBpNodeTemplates.size() > 0); - - assertEquals( - "DMAAP K8s Blueprint:NodeTemplates:Type is not Matching", - k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), - Constants.DMAAP_NODETEMPLATES_TYPE); - - Properties k8sBpNodeTemplateProperties = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); - assertNotNull( - "DMAAP K8s Blueprint Node Templates:Properties Section is NULL", - k8sBpNodeTemplateProperties); - - List bpNodeTemplateRelationships = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); - assertNotNull( - "DMAAP K8s Blueprint Node Templates:Relationships Section is NULL", - bpNodeTemplateRelationships); - - onapTestUtils.verifyStreamsPublishes( - "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyStreamsSubscribes( - "DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyAuxilary("DMAAP K8s", onapComponentSpec); - onapTestUtils - .verifyHealthCheck("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyServicesCalls("DMAAP K8s", onapComponentSpec); - onapTestUtils.verifyServicesProvides("DMAAP K8s", onapComponentSpec); - onapTestUtils - .verifyDockerConfig("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyParameters("DMAAP K8s", onapComponentSpec, k8sBpNodeTemplates); - } - - /** - * Test Case for K8s Blueprint for DMAAP Component Spec Input File with Import File - * - */ - @DisplayName("Testing K8s Blueprint for DMAAP Component Spec Input File with Import File") - @Test - public void testDMAAPK8sImportFileBlueprint() throws IOException { - Input input = - onapTestUtils.getInput( - Paths.get("src", "test", "resources", "componentspecs", ves).toFile() - .getAbsolutePath(), - "", - "", - Paths.get("src", "test", "resources", "componentspecs", testImports) - .toFile() - .getAbsolutePath(), - "d", - ""); - onapComponentSpec = - onapComponentSpecService.createComponentSpecFromFile(input.getComponentSpecPath()); - assertNotNull( - "K8s Blueprint for DMAAP Component Spec with Import File is NULL", onapComponentSpec); - - OnapBlueprint onapBlueprint = dmaapBlueprintService - .createBlueprint(onapComponentSpec, input); - - onapTestUtils.verifyToscaDefVersion( - "DMAAP with Import File K8s", onapBlueprint, Constants.TOSCA_DEF_VERSION); - onapTestUtils.verifyBpImportsFromFile( - "DMAAP with Import File K8s", onapBlueprint, input.getImportPath()); - - Map> k8sBpInputs = onapBlueprint.getInputs(); - assertNotNull("DMAAP with Import File K8s Blueprint Inputs Section is NULL", k8sBpInputs); - assertTrue( - "DMAAP with Import File K8s Blueprint Inputs Section is Empty", k8sBpInputs.size() > 0); - - assertEquals( - "DMAAP with Import File K8s Blueprint:Inputs " - + Constants.ONAP_INPUT_CPU_LIMIT - + " Default is not matching", - k8sBpInputs.get(Constants.ONAP_INPUT_CPU_LIMIT).get("default"), - Constants.ONAP_DEFAULT250m); - assertEquals( - "DMAAP with Import File K8s Blueprint:Inputs " - + Constants.SERVICE_COMPONENT_NAME_OVERRIDE - + " Default is not matching", - k8sBpInputs.get(Constants.SERVICE_COMPONENT_NAME_OVERRIDE).get("default"), - Constants.ONAP_SERVICE_COMPONENTNAME_OVERRIDE_DEFAULT); - - Map k8sBpNodeTemplates = onapBlueprint.getNode_templates(); - assertNotNull( - "DMAAP with Import File K8s Blueprint Node Templates Section is NULL in the K8s DMAAP Blueprint", - k8sBpNodeTemplates); - assertTrue( - "DMAAP with Import File K8s Blueprint Node Templates Section Size is Empty", - k8sBpNodeTemplates.size() > 0); - - assertEquals( - "DMAAP with Import File K8s Blueprint:NodeTemplates:Type is not Matching", - k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES).getType(), - Constants.DMAAP_NODETEMPLATES_TYPE); - - Properties k8sBpNodeTemplateProperties = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getProperties(); - assertNotNull( - "DMAAP with Import File K8s Blueprint Node Templates:Properties Section is NULL", - k8sBpNodeTemplateProperties); - - List bpNodeTemplateRelationships = - ((Node) k8sBpNodeTemplates.get(Constants.ONAP_NODETEMPLATES)).getRelationships(); - assertNotNull( - "DMAAP with Import File K8s Blueprint Node Templates:Relationships Section is NULL", - bpNodeTemplateRelationships); - - onapTestUtils.verifyStreamsPublishes( - "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyStreamsSubscribes( - "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyAuxilary("DMAAP with Import File K8s", onapComponentSpec); - onapTestUtils.verifyHealthCheck( - "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyServicesCalls("DMAAP with Import File K8s", onapComponentSpec); - onapTestUtils.verifyServicesProvides("DMAAP with Import File K8s", onapComponentSpec); - onapTestUtils.verifyDockerConfig( - "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplateProperties); - onapTestUtils.verifyParameters( - "DMAAP with Import File K8s", onapComponentSpec, k8sBpNodeTemplates); - } -} diff --git a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java index 984c262..433240f 100644 --- a/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java +++ b/mod/bpgenerator/onap/src/test/java/org/onap/blueprintgenerator/test/TlsInfoTest.java @@ -209,8 +209,7 @@ public class TlsInfoTest extends BlueprintGeneratorTests { private OnapBlueprint createBlueprintFromFile(String path) { onapComponentSpec = onapComponentSpecService.createComponentSpecFromFile(path); Input input = onapTestUtils.getInput(path, "", "", "", "o", ""); - OnapBlueprint onapBlueprint = onapBlueprintService - .createBlueprint(onapComponentSpec, input); + OnapBlueprint onapBlueprint = onapBlueprintCreatorService.createBlueprint(onapComponentSpec, input); return onapBlueprint; } } -- cgit 1.2.3-korg