generateNamingValue = "true".equalsIgnoreCase(generateNaming);
}
service.setOnapGeneratedNaming(generateNamingValue);
- service.setBlueprintName(serviceMetadata.getValue(CDS_MODEL_NAME));
- service.setBlueprintVersion(serviceMetadata.getValue(CDS_MODEL_VERSION));
- service.setSkipPostInstConf(Boolean.valueOf(serviceMetadata.getValue(SKIP_POST_INST_CONF)));
- service.setControllerActor(serviceMetadata.getValue(CONTROLLER_ACTOR));
- }
-
+ List<Input> serviceInputs = toscaResourceStructure.getSdcCsarHelper().getServiceInputs();
+ logger.debug("serviceInputs: {} " + serviceInputs);
+ if (!serviceInputs.isEmpty()) {
+ serviceInputs.forEach(input -> {
+ if (CDS_MODEL_NAME.equalsIgnoreCase(input.getName())) {
+ String value = input.getDefault() != null ? input.getDefault().toString() : null;
+ service.setBlueprintName(value);
+ }
+ if (CDS_MODEL_VERSION.equalsIgnoreCase(input.getName())) {
+ String value = input.getDefault() != null ? input.getDefault().toString() : null;
+ service.setBlueprintVersion(value);
+ }
+ if (CONTROLLER_ACTOR.equalsIgnoreCase(input.getName())) {
+ String value = input.getDefault() != null ? input.getDefault().toString() : null;
+ service.setControllerActor(value);
+ }
+ if (SKIP_POST_INST_CONF.equalsIgnoreCase(input.getName())) {
+ String value = input.getDefault() != null ? input.getDefault().toString() : "false";
+ service.setSkipPostInstConf(Boolean.valueOf(value));
+ }
+ });
+ }
+ }
toscaResourceStructure.setCatalogService(service);
return service;
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
doReturn(namingPolicy).when(metadata).getValue("namingPolicy");
doReturn(ecompGeneratedNaming).when(metadata).getValue("ecompGeneratedNaming");
+ ISdcCsarHelper iSdcCsarHelper = mock(ISdcCsarHelper.class);
+ List<Input> serviceInputs = new ArrayList<Input>();
+
+ LinkedHashMap<String, Object> value = new LinkedHashMap<String, Object>();
+ value.put("controller_actor", "SO-REF-DATA");
+ value.put("type", "string");
+ Input input = new Input("controller_actor", value, null);
+ serviceInputs.add(0, input);
+
+ value = new LinkedHashMap<String, Object>();
+ value.put("cds_model_version", "v1.4.0");
+ value.put("type", "string");
+ input = new Input("cds_model_version", value, null);
+ serviceInputs.add(1, input);
+
+ value = new LinkedHashMap<String, Object>();
+ value.put("cds_model_name", "Blueprint140");
+ value.put("type", "string");
+ input = new Input("cds_model_name", value, null);
+ serviceInputs.add(2, input);
+
+ value = new LinkedHashMap<String, Object>();
+ value.put("skip_post_instantiation_configuration", "false");
+ value.put("type", "boolean");
+ input = new Input("skip_post_instantiation_configuration", value, null);
+ serviceInputs.add(3, input);
+
+ doReturn(iSdcCsarHelper).when(toscaResourceStructure).getSdcCsarHelper();
+ doReturn(serviceInputs).when(iSdcCsarHelper).getServiceInputs();
+
Service service = toscaInstaller.createService(toscaResourceStructure, resourceStructure);
assertNotNull(service);
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Modifications Copyright (c) 2021 Nokia
+ * ================================================================================
+ * 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.so.bpmn.infrastructure.aai.tasks;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Optional;
+import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.common.DelegateExecutionImpl;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import org.onap.so.client.exception.ExceptionBuilder;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AAICommonTasksTest {
+
+ private static final String SERVICE_TYPE = "testService";
+
+ @Mock
+ private ExtractPojosForBB extractPojosForBBMock;
+ @Mock
+ private ExceptionBuilder exceptionBuilder;
+ @InjectMocks
+ private AAICommonTasks testedObject;
+
+ private ServiceInstance serviceInstance;
+ private BuildingBlockExecution buildingBlockExecution;
+
+ @Before
+ public void setup() {
+ serviceInstance = new ServiceInstance();
+ buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake());
+ }
+
+ @Test
+ public void getServiceType_success() throws Exception {
+ // given
+ ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
+ modelInfoServiceInstance.setServiceType(SERVICE_TYPE);
+ serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
+ when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
+ .thenReturn(serviceInstance);
+ // when
+ Optional<String> resultOpt = testedObject.getServiceType(buildingBlockExecution);
+ // then
+ assertThat(resultOpt).isNotEmpty();
+ String result = resultOpt.get();
+ assertThat(result).isEqualTo(SERVICE_TYPE);
+ }
+
+ @Test
+ public void getServiceType_emptyWhenServiceInstanceModelIsNull() throws Exception {
+ // given
+ when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
+ .thenReturn(serviceInstance);
+ // when
+ Optional<String> result = testedObject.getServiceType(buildingBlockExecution);
+ // then
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ public void getServiceType_exceptionHandling() throws Exception {
+ // given
+ BBObjectNotFoundException exception = new BBObjectNotFoundException();
+ when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
+ .thenThrow(exception);
+ // when
+ testedObject.getServiceType(buildingBlockExecution);
+ // then
+ verify(exceptionBuilder).buildAndThrowWorkflowException(buildingBlockExecution, 7000, exception);
+ }
+}
package org.onap.so.simulator.actions.aai;
+import com.consol.citrus.actions.AbstractTestAction;
+import com.consol.citrus.context.TestContext;
+import java.security.SecureRandom;
import org.onap.aai.domain.yang.L3Network;
import org.onap.aaiclient.client.aai.AAIResourcesClient;
import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.consol.citrus.actions.AbstractTestAction;
-import com.consol.citrus.context.TestContext;
public class ProcessNetwork extends AbstractTestAction {
public void doExecute(TestContext context) {
final Logger logger = LoggerFactory.getLogger(ProcessNetwork.class);
try {
- int random = (int) (Math.random() * 50 + 1);
+ int random = (new SecureRandom()).nextInt(50) + 1;
AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
public class ProcessVnfc extends AbstractTestAction {
+ private static final String VNF_SERVER_1_NAME = "ssc_server_1";
+
@Override
public void doExecute(TestContext context) {
final Logger logger = LoggerFactory.getLogger(ProcessVnfc.class);
try {
logger.debug("running ProcessVnfc scenario");
- logger.debug("requestAction: " + context.getVariable("requestAction"));
- logger.debug("serviceAction: " + context.getVariable("serviceAction"));
- logger.debug("cloudOwner: " + context.getVariable("cloudOwner"));
- logger.debug("cloundRegion: " + context.getVariable("cloudRegion"));
- logger.debug("tenant: " + context.getVariable("tenant"));
- logger.debug("vfModuleId: " + context.getVariable("vfModuleId"));
- logger.debug("vnfId: " + context.getVariable("vnfId"));
+ logger.debug("requestAction: {}", context.getVariable("requestAction"));
+ logger.debug("serviceAction: {}", context.getVariable("serviceAction"));
+ logger.debug("cloudOwner: {}", context.getVariable("cloudOwner"));
+ logger.debug("cloundRegion: {}", context.getVariable("cloudRegion"));
+ logger.debug("tenant: {}", context.getVariable("tenant"));
+ logger.debug("vfModuleId: {}", context.getVariable("vfModuleId"));
+ logger.debug("vnfId: {}", context.getVariable("vnfId"));
AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
&& context.getVariable("serviceAction").equals("assign")) {
AAIResourceUri vnfcURI =
- AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc("ssc_server_1"));
+ AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(VNF_SERVER_1_NAME));
Vnfc vnfc = new Vnfc();
- vnfc.setVnfcName("ssc_server_1");
+ vnfc.setVnfcName(VNF_SERVER_1_NAME);
vnfc.setNfcNamingCode("oamfw");
vnfc.setNfcFunction("EPC-OAM-FIREWALL");
vnfc.setProvStatus("PREPROV");
if (aaiResourceClient.exists(vnfcURI)) {
Optional<VfModule> vfModule = aaiResourceClient.get(vfModuleURI).asBean(VfModule.class);
- if (vfModule.get().getVfModuleName().contains("macro")) {
- String vnfcName = "ssc_server_1" + vfModule.get().getVfModuleName()
+ if (vfModule.isPresent() && vfModule.get().getVfModuleName().contains("macro")) {
+ String vnfcName = VNF_SERVER_1_NAME + vfModule.get().getVfModuleName()
.substring(vfModule.get().getVfModuleName().length() - 1);
vnfc.setVnfcName(vnfcName);
vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfcName));
package org.onap.so.simulator.scenarios.openstack.macro;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import com.consol.citrus.endpoint.resolver.DynamicEndpointUriResolver;
import com.consol.citrus.simulator.scenario.AbstractSimulatorScenario;
import com.consol.citrus.simulator.scenario.Scenario;
import com.consol.citrus.simulator.scenario.ScenarioDesigner;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
/**
- * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete
+ * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete.
*
*/
@Scenario("Openstack-QueryStackByID-Macro1")
@RequestMapping(value = "/sim/v1/tenantOne/stacks/macro_module_1/*", method = RequestMethod.GET)
public class QueryStackByIdMacro1 extends AbstractSimulatorScenario {
+ private static final String FILE_STACK_CREATED_PATH = "openstack/gr_api/Stack_Created.json";
+ private static final String FILE_STACK_DELETED_PATH = "openstack/gr_api/Stack_Deleted.json";
@Override
public void run(ScenarioDesigner scenario) {
scenario.variable("stackName", "macro_module_1");
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Create (module_2)
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Create (module_3)
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Create (module_2 recreate)
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Delete
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
// Delete
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
// Poll
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
}
}
package org.onap.so.simulator.scenarios.openstack.macro;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import com.consol.citrus.endpoint.resolver.DynamicEndpointUriResolver;
import com.consol.citrus.simulator.scenario.AbstractSimulatorScenario;
import com.consol.citrus.simulator.scenario.Scenario;
import com.consol.citrus.simulator.scenario.ScenarioDesigner;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
/**
- * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete
+ * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete.
*
*/
@Scenario("Openstack-QueryStackByID-Macro2")
@RequestMapping(value = "/sim/v1/tenantOne/stacks/macro_module_2/*", method = RequestMethod.GET)
public class QueryStackByIdMacro2 extends AbstractSimulatorScenario {
+ private static final String FILE_STACK_CREATED_PATH = "openstack/gr_api/Stack_Created.json";
+ private static final String FILE_STACK_DELETED_PATH = "openstack/gr_api/Stack_Deleted.json";
@Override
public void run(ScenarioDesigner scenario) {
scenario.variable("stackName", "macro_module_2");
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Delete
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
// Poll
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
}
}
package org.onap.so.simulator.scenarios.openstack.macro;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
import com.consol.citrus.endpoint.resolver.DynamicEndpointUriResolver;
import com.consol.citrus.simulator.scenario.AbstractSimulatorScenario;
import com.consol.citrus.simulator.scenario.Scenario;
import com.consol.citrus.simulator.scenario.ScenarioDesigner;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
/**
- * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete
+ * This scenario is used by the following test cases: Resume Service Instance Macro 3 Modules 1 To Complete.
*
*/
@Scenario("Openstack-QueryStackByID-Macro3")
@RequestMapping(value = "/sim/v1/tenantOne/stacks/macro_module_3/*", method = RequestMethod.GET)
public class QueryStackByIdMacro3 extends AbstractSimulatorScenario {
+ private static final String FILE_STACK_CREATED_PATH = "openstack/gr_api/Stack_Created.json";
+ private static final String FILE_STACK_DELETED_PATH = "openstack/gr_api/Stack_Deleted.json";
@Override
public void run(ScenarioDesigner scenario) {
scenario.variable("stackName", "macro_module_3");
// Poll
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
// Delete
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Created.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_CREATED_PATH));
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
// Poll
scenario.http().receive().get();
- scenario.http().send().response(HttpStatus.OK)
- .payload(new ClassPathResource("openstack/gr_api/Stack_Deleted.json"));
+ scenario.http().send().response(HttpStatus.OK).payload(new ClassPathResource(FILE_STACK_DELETED_PATH));
}
package org.onap.so.simulator.scenarios.sdnc.grapi;
+import com.consol.citrus.simulator.scenario.AbstractSimulatorScenario;
+import com.consol.citrus.simulator.scenario.Scenario;
+import com.consol.citrus.simulator.scenario.ScenarioDesigner;
+import java.security.SecureRandom;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import com.consol.citrus.simulator.scenario.AbstractSimulatorScenario;
-import com.consol.citrus.simulator.scenario.Scenario;
-import com.consol.citrus.simulator.scenario.ScenarioDesigner;
@Scenario("SDNC-GRAPI-QueryVFModule")
@RequestMapping(
@Override
public void run(ScenarioDesigner scenario) {
scenario.http().receive().get();
- int random = (int) (Math.random() * 50 + 1);
+ int random = (new SecureRandom()).nextInt(50) + 1;
scenario.variable("vfModuleName", "vfModuleName" + random);