summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-11-28 11:05:39 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-11-28 11:09:09 -0500
commit7f1a2052c6d793a1b77199ac8d98c08cf88df1d1 (patch)
tree3262ad7c9afc18fa4259cd496c739f1473871798 /bpmn
parentb9264cfc0c81ac25416268956c4ab389fdf0fcf6 (diff)
Add support for naming service
Moved client and builder to namingservice package Renamed file to NamingRequestObjectBuilder and updated packages Updated namespaces for namingservice beans Removed unused test resource files Added endpoint and authentication information to yaml Added NamingMapperTest for mapper layer Added NamingMapper for mapping requests and responses Began adding NamingClient for assign and unassign requests Added maven dependency for namingmS client beans Describe NamingClientResponseValidator as a Bean Fix a JUnit for delete tasks for Naming Service. Change NamingClient to return a String with the result and throw an exception. Add delete/create tasks for NamingService interaction and related JUnits. ResponseValidator for NamingClient and Resources class to support Naming Service interactions. removed naming service dependency added serializable flag for naming service model gen Change-Id: I0d9efe4009207f3739a3b6515592e67cfeedf822 Issue-ID: SO-1260 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java3
-rw-r--r--bpmn/so-bpmn-tasks/pom.xml30
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java56
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java53
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java64
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java103
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java38
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java60
-rw-r--r--bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json325
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java4
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java82
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java71
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java84
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java85
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java105
-rw-r--r--bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml3
16 files changed, 1165 insertions, 1 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java
index 4662db23a1..9709ccece0 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java
@@ -30,5 +30,6 @@ public enum ResourceKey {
CONFIGURATION_ID,
NETWORK_COLLECTION_ID,
VPN_ID,
- VPN_BONDING_LINK_ID;
+ VPN_BONDING_LINK_ID,
+ INSTANCE_GROUP_ID;
}
diff --git a/bpmn/so-bpmn-tasks/pom.xml b/bpmn/so-bpmn-tasks/pom.xml
index 63a65cdc24..d66c97f81a 100644
--- a/bpmn/so-bpmn-tasks/pom.xml
+++ b/bpmn/so-bpmn-tasks/pom.xml
@@ -44,6 +44,36 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>io.swagger</groupId>
+ <artifactId>swagger-codegen-maven-plugin</artifactId>
+ <version>2.3.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate</goal>
+ </goals>
+ <configuration>
+ <inputSpec>${project.basedir}/src/main/resources/naming-service/swagger.json</inputSpec>
+ <apiPackage>org.onap.namingservice.api</apiPackage>
+ <modelPackage>org.onap.namingservice.model</modelPackage>
+ <invokerPackage>org.onap.namingservice.invoker</invokerPackage>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <inputSpec>${project.basedir}/src/main/resources/swagger.json</inputSpec>
+ <language>java</language>
+ <configOptions>
+ <sourceFolder>src/gen/java/main</sourceFolder>
+ <serializableModel>true</serializableModel>
+ </configOptions>
+ <output>${project.build.directory}/generated-sources</output>
+ <generateApis>false</generateApis>
+ <library>jersey2</library>
+ <generateSupportingFiles>false</generateSupportingFiles>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencyManagement>
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java
new file mode 100644
index 0000000000..cb4ac5c9d9
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.bpmn.infrastructure.namingservice.tasks;
+
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.client.orchestration.NamingServiceResources;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NamingServiceCreateTasks {
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private NamingServiceResources namingServiceResources;
+
+ public void createInstanceGroupName(BuildingBlockExecution execution) throws Exception {
+ InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID, execution.getLookupMap().get(ResourceKey.INSTANCE_GROUP_ID));
+ String policyInstanceName = execution.getVariable("policyInstanceName");
+ String nfNamingCode = execution.getVariable("nfNamingCode");
+ String generatedInstanceGroupName = "";
+ try {
+ generatedInstanceGroupName = namingServiceResources.generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ instanceGroup.setInstanceGroupName(generatedInstanceGroupName);
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java
new file mode 100644
index 0000000000..ddea2724bc
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.bpmn.infrastructure.namingservice.tasks;
+
+
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.client.orchestration.NamingServiceResources;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NamingServiceDeleteTasks {
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private NamingServiceResources namingServiceResources;
+
+ public void deleteInstanceGroupName(BuildingBlockExecution execution) throws Exception {
+ InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID, execution.getLookupMap().get(ResourceKey.INSTANCE_GROUP_ID));
+
+ try {
+ namingServiceResources.deleteInstanceGroupName(instanceGroup);
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java
new file mode 100644
index 0000000000..f91ad44f2b
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClient.java
@@ -0,0 +1,64 @@
+package org.onap.so.client.namingservice;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.namingservice.model.NameGenDeleteRequest;
+import org.onap.namingservice.model.NameGenDeleteResponse;
+import org.onap.namingservice.model.NameGenRequest;
+import org.onap.namingservice.model.NameGenResponse;
+import org.onap.so.client.exception.BadResponseException;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.RestTemplate;
+
+
+
+@Component
+public class NamingClient{
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingClient.class);
+ private static final String ENDPOINT = "mso.naming.endpoint";
+ private static final String AUTH = "mso.naming.auth";
+
+ @Autowired
+ private RestTemplate restTemplate;
+ @Autowired
+ private Environment env;
+ @Autowired
+ private NamingClientResponseValidator namingClientResponseValidator;
+
+ public String postNameGenRequest(NameGenRequest request) throws BadResponseException {
+ String targetUrl = env.getProperty(ENDPOINT);
+ HttpHeaders headers = setHeaders(env.getProperty(AUTH));
+ msoLogger.info("Sending postNameGenRequest to url: " + targetUrl);
+ HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers);
+ ResponseEntity<NameGenResponse> response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
+ return namingClientResponseValidator.validateNameGenResponse(response);
+ }
+
+ public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException {
+ String targetUrl = env.getProperty(ENDPOINT);
+ HttpHeaders headers = setHeaders(env.getProperty(AUTH));
+ msoLogger.info("Sending deleteNameGenRequest to url: " + targetUrl);
+ HttpEntity<NameGenDeleteRequest> requestEntity = new HttpEntity<>(request, headers);
+ ResponseEntity<NameGenDeleteResponse> response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class);
+ return namingClientResponseValidator.validateNameGenDeleteResponse(response);
+ }
+
+ private HttpHeaders setHeaders(String auth) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ List<MediaType> acceptableMediaTypes = new ArrayList<>();
+ acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
+ headers.setAccept(acceptableMediaTypes);
+ headers.add(HttpHeaders.AUTHORIZATION, auth);
+ return headers;
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java
new file mode 100644
index 0000000000..ab0639574c
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingClientResponseValidator.java
@@ -0,0 +1,103 @@
+package org.onap.so.client.namingservice;
+
+import java.util.List;
+
+import org.apache.http.HttpStatus;
+import org.onap.namingservice.model.NameGenDeleteResponse;
+import org.onap.namingservice.model.NameGenResponse;
+import org.onap.namingservice.model.NameGenResponseError;
+import org.onap.namingservice.model.Respelement;
+import org.onap.so.client.exception.BadResponseException;
+import org.onap.so.logger.MessageEnum;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NamingClientResponseValidator {
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingClientResponseValidator.class);
+ private static final String INSTANCE_GROUP_NAME = "instance-group-name";
+ private static final String NO_RESPONSE_FROM_NAMING_SERVICE = "Error did not receive a response from Naming Service.";
+ private static final String NULL_RESPONSE_FROM_NAMING_SERVICE = "Error received a null response from Naming Service.";
+ private static final String NAMING_SERVICE_ERROR = "Error from Naming Service: %s";
+
+ public String validateNameGenResponse(ResponseEntity<NameGenResponse> response) throws BadResponseException {
+ if (response == null) {
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN",
+ MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_NAMING_SERVICE);
+ throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE);
+ }
+
+ int responseCode = response.getStatusCodeValue();
+ String generatedName = "";
+ NameGenResponse responseBody = response.getBody();
+ if (responseBody == null) {
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN",
+ MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NULL_RESPONSE_FROM_NAMING_SERVICE);
+ throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE);
+ }
+
+ if (isHttpCodeSuccess(responseCode)) {
+ msoLogger.info("Successful Response from Naming Service");
+ List<Respelement> respList = responseBody.getElements();
+
+ if (respList != null) {
+ for (int i=0; i < respList.size(); i++) {
+ Respelement respElement = respList.get(i);
+ if (respElement != null) {
+ String resourceName = respElement.getResourceName();
+ if (INSTANCE_GROUP_NAME.equals(resourceName)) {
+ generatedName = respElement.getResourceValue();
+ break;
+ }
+ }
+ }
+ }
+ return generatedName;
+ } else {
+ NameGenResponseError error = responseBody.getError();
+ String errorMessageString = NAMING_SERVICE_ERROR;
+ if (error != null) {
+ errorMessageString = error.getMessage();
+ }
+ String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.DataError, errorMessage);
+ throw new BadResponseException(errorMessage);
+ }
+ }
+
+ public String validateNameGenDeleteResponse(ResponseEntity<NameGenDeleteResponse> response) throws BadResponseException {
+ if (response == null) {
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NO_RESPONSE_FROM_NAMING_SERVICE, "BPMN",
+ MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NO_RESPONSE_FROM_NAMING_SERVICE);
+ throw new BadResponseException(NO_RESPONSE_FROM_NAMING_SERVICE);
+ }
+
+ int responseCode = response.getStatusCodeValue();
+ String responseMessage = "";
+ NameGenDeleteResponse responseBody = response.getBody();
+ if (responseBody == null) {
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, NULL_RESPONSE_FROM_NAMING_SERVICE, "BPMN",
+ MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, NULL_RESPONSE_FROM_NAMING_SERVICE);
+ throw new BadResponseException(NULL_RESPONSE_FROM_NAMING_SERVICE);
+ }
+
+ if (isHttpCodeSuccess(responseCode)) {
+ msoLogger.info("Successful Response from Naming Service");
+ return responseMessage;
+ } else {
+ String errorMessageString = NAMING_SERVICE_ERROR;
+
+ String errorMessage = String.format(NAMING_SERVICE_ERROR, errorMessageString);
+ msoLogger.error(MessageEnum.RA_GENERAL_EXCEPTION, errorMessage, "BPMN", MsoLogger.getServiceName(),
+ MsoLogger.ErrorCode.DataError, errorMessage);
+ throw new BadResponseException(errorMessage);
+ }
+ }
+
+ private boolean isHttpCodeSuccess(int code) {
+ return code >= HttpStatus.SC_OK && code < HttpStatus.SC_MULTIPLE_CHOICES || code == 0;
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java
new file mode 100644
index 0000000000..c3f216e288
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/namingservice/NamingRequestObjectBuilder.java
@@ -0,0 +1,38 @@
+package org.onap.so.client.namingservice;
+
+import java.util.List;
+
+import org.onap.namingservice.model.Deleteelement;
+import org.onap.namingservice.model.Element;
+import org.onap.namingservice.model.NameGenDeleteRequest;
+import org.onap.namingservice.model.NameGenRequest;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NamingRequestObjectBuilder{
+
+ public Element elementMapper(String instanceGroupId, String policyInstanceName, String namingType, String nfNamingCode, String instanceGroupName){
+ Element element = new Element();
+ element.setExternalKey(instanceGroupId);
+ element.setPolicyInstanceName(policyInstanceName);
+ element.setNamingType(namingType);
+ element.setResourceName(instanceGroupName);
+ element.setNamingIngredientsZeroOrMore(nfNamingCode);
+ return element;
+ }
+ public Deleteelement deleteElementMapper(String instanceGroupId){
+ Deleteelement deleteElement = new Deleteelement();
+ deleteElement.setExternalKey(instanceGroupId);
+ return deleteElement;
+ }
+ public NameGenRequest nameGenRequestMapper(List<Element> elements){
+ NameGenRequest nameGenRequest = new NameGenRequest();
+ nameGenRequest.setElements(elements);
+ return nameGenRequest;
+ }
+ public NameGenDeleteRequest nameGenDeleteRequestMapper(List<Deleteelement> deleteElements){
+ NameGenDeleteRequest nameGenDeleteRequest = new NameGenDeleteRequest();
+ nameGenDeleteRequest.setElements(deleteElements);
+ return nameGenDeleteRequest;
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java
new file mode 100644
index 0000000000..8b443a165b
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NamingServiceResources.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.client.orchestration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.namingservice.model.Element;
+import org.onap.namingservice.model.Deleteelement;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.client.exception.BadResponseException;
+import org.onap.so.client.namingservice.NamingClient;
+import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
+import org.onap.so.logger.MsoLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NamingServiceResources {
+ private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NamingServiceResources.class);
+ private static final String NAMING_TYPE = "instanceGroup";
+
+ @Autowired
+ private NamingClient namingClient;
+
+ @Autowired
+ private NamingRequestObjectBuilder namingRequestObjectBuilder;
+
+ public String generateInstanceGroupName(InstanceGroup instanceGroup, String policyInstanceName, String nfNamingCode) throws BadResponseException {
+ Element element = namingRequestObjectBuilder.elementMapper(instanceGroup.getId(), policyInstanceName, NAMING_TYPE, nfNamingCode, instanceGroup.getInstanceGroupName());
+ List<Element> elements = new ArrayList<Element>();
+ elements.add(element);
+ return(namingClient.postNameGenRequest(namingRequestObjectBuilder.nameGenRequestMapper(elements)));
+ }
+
+ public String deleteInstanceGroupName(InstanceGroup instanceGroup) throws BadResponseException {
+ Deleteelement deleteElement = namingRequestObjectBuilder.deleteElementMapper(instanceGroup.getId());
+ List<Deleteelement> deleteElements = new ArrayList<Deleteelement>();
+ deleteElements.add(deleteElement);
+ return(namingClient.deleteNameGenRequest(namingRequestObjectBuilder.nameGenDeleteRequestMapper(deleteElements)));
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json b/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json
new file mode 100644
index 0000000000..b86ffbc6b0
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/resources/naming-service/swagger.json
@@ -0,0 +1,325 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "version": "2018.08.01",
+ "title": "networkelementnamegenprodtest Service"
+ },
+ "basePath": "/web",
+ "paths": {
+ "/service/v1/addPolicy": {
+ "post": {
+ "summary": "Respond Hello <name>!",
+ "description": "Returns a JSON object with a string to say hello. Uses 'world' if a name is not specified",
+ "operationId": "addPolicyToDB",
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "object"
+ }
+ }
+ },
+ "404": {
+ "description": "Service not available"
+ },
+ "500": {
+ "description": "Unexpected Runtime error"
+ }
+ }
+ }
+ },
+ "/service/v1/genNetworkElementName": {
+ "post": {
+ "summary": "Generates name",
+ "description": "Generates network element name based on a naming policy1 ",
+ "operationId": "generateNetworkElementName",
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/NameGenRequest"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/NameGenResponse"
+ }
+ },
+ "404": {
+ "description": "Service not available"
+ },
+ "500": {
+ "description": "Unexpected Runtime error"
+ }
+ }
+ },
+ "delete": {
+ "summary": "Release an existing name by external key",
+ "description": "Release network element name ",
+ "operationId": "releaseNetworkElementName",
+ "produces": [
+ "application/json"
+ ],"parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/NameGenDeleteRequest"
+ }
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "$ref": "#/definitions/NameGenDeleteResponse"
+ }
+ },
+ "404": {
+ "description": "Service not available"
+ },
+ "500": {
+ "description": "Unexpected Runtime error"
+ }
+ }
+ }
+ },
+ "/service/v1/getpolicyresponse/{policyName}": {
+ "get": {
+ "summary": "Respond Hello <name>!",
+ "description": "Returns a JSON object with a string to say hello. Uses 'world' if a name is not specified",
+ "operationId": "getPolicyResponse",
+ "produces": [
+ "application/json"
+ ],
+ "responses": {
+ "200": {
+ "description": "successful operation",
+ "schema": {
+ "type": "object",
+ "additionalProperties": {
+ "type": "object"
+ }
+ }
+ },
+ "404": {
+ "description": "Service not available"
+ },
+ "500": {
+ "description": "Unexpected Runtime error"
+ }
+ }
+ }
+ }
+ },
+ "definitions": {
+ "HelloWorld": {
+ "type": "object",
+ "properties": {
+ "message": {
+ "type": "string"
+ }
+ }
+ },
+ "NameGenRequest": {
+ "title": "NameGenRequest",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "type": "object",
+ "required": [
+ "elements"
+ ],
+ "properties": {
+ "elements": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/element"
+ }
+ }
+ },
+ "additionalProperties": false,
+ "definitions": {
+ "element": {
+ "type": "object",
+ "required": [
+ "resource-name",
+ "external-key",
+ "policy-instance-name",
+ "naming-type"
+ ],
+ "properties": {
+ "resource-name": {
+ "type": "string",
+ "description": "Name of the resource"
+ },
+ "resource-value": {
+ "type": "string",
+ "description": "Optional. If given, request will be considered as update request"
+ },
+ "external-key": {
+ "type": "string",
+ "description": "Key identifier for generated name. This will be used in release/update request"
+ },
+ "policy-instance-name": {
+ "type": "string",
+ "description": "Name of the policy to be used for name generation"
+ },
+ "naming-type": {
+ "type": "string",
+ "description": "Naming type of the resource"
+ }
+ },
+ "additionalProperties": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "NameGenResponse": {
+ "type": "object",
+ "description":"Response with generated names for each naming type. Either elements(one or more) or an error block will be present",
+ "properties": {
+ "elements" : {
+ "type":"array",
+ "items": { "$ref": "#/definitions/respelement" }
+ },
+ "error" : {
+ "type":"object",
+ "required": ["errorId", "message"],
+ "properties":{
+ "errorId":{"type":"string" , "description":"error code"},
+ "message": {"type":"string", "description":"error message"}
+ }
+ }
+ }
+ },
+ "element": {
+ "type": "object",
+ "required": [
+ "resource-name",
+ "external-key",
+ "policy-instance-name",
+ "naming-type"
+ ],
+ "properties": {
+ "resource-name": {
+ "type": "string",
+ "description": "Name of the resource"
+ },
+ "resource-value": {
+ "type": "string",
+ "description": "Optional. If given, request will be considered as update request"
+ },
+ "external-key": {
+ "type": "string",
+ "description": "Key identifier for generated name. This will be used in release/update request"
+ },
+ "policy-instance-name": {
+ "type": "string",
+ "description": "Name of the policy to be used for name generation"
+ },
+ "naming-type": {
+ "type": "string",
+ "description": "Naming type of the resource"
+ },
+ "${naming-ingredients(zero or more)}": {
+ "type": "string",
+ "description": "values to subsitute in the naming recipe"
+ }
+ },
+ "additionalProperties": {
+ "type": "string"
+ }
+ },
+ "respelement": {
+ "type":"object",
+ "required": [ "resource-name","resource-value","external-key"],
+ "properties": {
+ "resource-value": {
+ "type": "string",
+ "description": "Optional. If given, request will be considered as update request"
+ },
+ "resource-name": {
+ "type": "string",
+ "description": "Name of the resource"
+ },
+ "external-key": {
+ "type": "string",
+ "description": "Key identifier for generated name. This will be used in release/update request"
+ }
+ }
+ },
+ "NameGenDeleteRequest": {
+ "title": "NameGenRequest",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "type": "object",
+ "required": [
+ "elements"
+ ],
+ "properties": {
+ "elements": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/deleteelement"
+ }
+ }
+ }
+ },
+ "deleteelement": {
+ "type": "object",
+ "required": [ "external-key" ],
+ "properties": {
+ "external-key": {
+ "type": "string",
+ "description": "External key of the name that is being released"
+ }
+ }
+ },"NameGenDeleteResponse": {
+ "title": "NameGenRequest",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "type": "object",
+ "required": [
+ "elements"
+ ],
+ "properties": {
+ "elements": {
+ "type": "array",
+ "items": {
+ "$ref": "#/definitions/deleteresponseelement"
+ }
+ }
+ }
+ },
+ "deleteresponseelement": {
+ "type": "object",
+ "required": [ "resource-value","resource_name","external-key" ],
+ "properties": {
+ "resource-value": {
+ "type": "string",
+ "description": "Name that is being release"
+ },
+ "resource-name": {
+ "type": "string",
+ "description": "Resource Name"
+ },
+ "external-key": {
+ "type": "string",
+ "description": "External key of the name that is being released"
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
index 95201d555d..21b89c3731 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java
@@ -44,6 +44,7 @@ import org.onap.so.client.orchestration.AAIVfModuleResources;
import org.onap.so.client.orchestration.AAIVnfResources;
import org.onap.so.client.orchestration.AAIVolumeGroupResources;
import org.onap.so.client.orchestration.AAIVpnBindingResources;
+import org.onap.so.client.orchestration.NamingServiceResources;
import org.onap.so.client.orchestration.NetworkAdapterResources;
import org.onap.so.client.orchestration.SDNCNetworkResources;
import org.onap.so.client.orchestration.SDNCServiceInstanceResources;
@@ -111,6 +112,9 @@ public abstract class BaseTaskTest extends TestDataSetup {
@Mock
protected AAIInstanceGroupResources aaiInstanceGroupResources;
+
+ @Mock
+ protected NamingServiceResources namingServiceResources;
@Mock
protected ApplicationControllerAction appCClient;
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java
new file mode 100644
index 0000000000..41739f37e6
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasksTest.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.bpmn.infrastructure.namingservice.tasks;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+
+public class NamingServiceCreateTasksTest extends BaseTaskTest {
+ @InjectMocks
+ private NamingServiceCreateTasks namingServiceCreateTasks = new NamingServiceCreateTasks();
+
+ private InstanceGroup instanceGroup;
+
+ @Before
+ public void before() throws BBObjectNotFoundException {
+ instanceGroup = setInstanceGroup();
+ when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID), any())).thenReturn(instanceGroup);
+ }
+
+ @Test
+ public void createInstanceGroupTest() throws Exception {
+ String policyInstanceName = "policyInstanceName";
+ String nfNamingCode = "nfNamingCode";
+ String generatedName = "generatedInstanceGroupName";
+ execution.setVariable(policyInstanceName, policyInstanceName);
+ execution.setVariable(nfNamingCode, nfNamingCode);
+ doReturn(generatedName).when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
+
+ namingServiceCreateTasks.createInstanceGroupName(execution);
+ verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
+ assertEquals(instanceGroup.getInstanceGroupName(), generatedName);
+ }
+
+ @Test
+ public void createInstanceGroupExceptionTest() throws Exception {
+ expectedException.expect(BBObjectNotFoundException.class);
+ lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, "notfound");
+ doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID),eq("notfound"));
+ String policyInstanceName = "policyInstanceName";
+ String nfNamingCode = "nfNamingCode";
+ execution.setVariable(policyInstanceName, policyInstanceName);
+ execution.setVariable(nfNamingCode, nfNamingCode);
+ doReturn("").when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
+ namingServiceCreateTasks.createInstanceGroupName(execution);
+ verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
+
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java
new file mode 100644
index 0000000000..97dcc617ac
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasksTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.bpmn.infrastructure.namingservice.tasks;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.InjectMocks;
+import org.onap.so.bpmn.BaseTaskTest;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+
+public class NamingServiceDeleteTasksTest extends BaseTaskTest {
+ @InjectMocks
+ private NamingServiceDeleteTasks namingServiceDeleteTasks = new NamingServiceDeleteTasks();
+
+ private InstanceGroup instanceGroup;
+
+ @Before
+ public void before() throws BBObjectNotFoundException {
+ instanceGroup = setInstanceGroup();
+ when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID), any())).thenReturn(instanceGroup);
+ }
+
+ @Test
+ public void deleteInstanceGroupTest() throws Exception {
+
+ doReturn("").when(namingServiceResources).deleteInstanceGroupName(instanceGroup);
+
+ namingServiceDeleteTasks.deleteInstanceGroupName(execution);
+ verify(namingServiceResources, times(1)).deleteInstanceGroupName(instanceGroup);
+ }
+
+ @Test
+ public void deleteInstanceGroupExceptionTest() throws Exception {
+ expectedException.expect(BBObjectNotFoundException.class);
+ lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, "notfound");
+ doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID),eq("notfound"));
+ doReturn("").when(namingServiceResources).deleteInstanceGroupName(instanceGroup);
+ namingServiceDeleteTasks.deleteInstanceGroupName(execution);
+ verify(namingServiceResources, times(1)).deleteInstanceGroupName(instanceGroup);
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java
new file mode 100644
index 0000000000..70036e7480
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientResponseValidatorTest.java
@@ -0,0 +1,84 @@
+package org.onap.so.client.namingservice;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.namingservice.model.NameGenDeleteResponse;
+import org.onap.namingservice.model.NameGenResponse;
+import org.onap.namingservice.model.Respelement;
+import org.onap.so.bpmn.common.data.TestDataSetup;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+public class NamingClientResponseValidatorTest extends TestDataSetup {
+
+ private NamingClientResponseValidator responseValidator = new NamingClientResponseValidator();
+ private String instanceGroupName = "generatedInstanceGroupName";
+
+ @Test
+ public void validateNameGenResponseSuccessTest() throws BadResponseException {
+ NameGenResponse name = new NameGenResponse();
+ Respelement respElement = new Respelement();
+ respElement.setResourceName("instance-group-name");
+ respElement.setResourceValue(instanceGroupName);
+ List<Respelement> respList = new ArrayList<Respelement>();
+ respList.add(respElement);
+ name.setElements(respList);
+ ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
+
+ String actual = responseValidator.validateNameGenResponse(resp);
+
+ assertEquals(actual, "generatedInstanceGroupName");
+ }
+
+ @Test
+ public void validateNameGenResponseNoNameGeneratedTest() throws BadResponseException {
+ NameGenResponse name = new NameGenResponse();
+ Respelement respElement = new Respelement();
+ respElement.setResourceName("instance-group");
+ respElement.setResourceValue(instanceGroupName);
+ List<Respelement> respList = new ArrayList<Respelement>();
+ respList.add(respElement);
+ name.setElements(respList);
+ ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
+
+ String actual = responseValidator.validateNameGenResponse(resp);
+
+ assertEquals(actual, "");
+ }
+
+ @Test
+ public void validateNameGenResponseBadStatusTest() throws BadResponseException {
+ NameGenResponse name = new NameGenResponse();
+
+ ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
+
+ expectedException.expect(BadResponseException.class);
+ responseValidator.validateNameGenResponse(resp);
+ }
+
+ @Test
+ public void validateNameGenDeleteResponseSuccessTest() throws BadResponseException {
+ NameGenDeleteResponse name = new NameGenDeleteResponse();
+ ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
+
+ String actual = responseValidator.validateNameGenDeleteResponse(resp);
+
+ assertEquals(actual, "");
+ }
+
+ @Test
+ public void validateNameGenDeleteResponseBadStatusTest() throws BadResponseException {
+ NameGenDeleteResponse name = new NameGenDeleteResponse();
+
+ ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.NOT_FOUND);
+
+ expectedException.expect(BadResponseException.class);
+ responseValidator.validateNameGenDeleteResponse(resp);
+ }
+
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java
new file mode 100644
index 0000000000..0a2dc1e4fa
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingRequestObjectBuilderTest.java
@@ -0,0 +1,85 @@
+package org.onap.so.client.namingservice;
+
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.namingservice.model.Deleteelement;
+import org.onap.namingservice.model.Element;
+import org.onap.namingservice.model.NameGenDeleteRequest;
+import org.onap.namingservice.model.NameGenRequest;
+import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
+
+public class NamingRequestObjectBuilderTest {
+
+ private NamingRequestObjectBuilder mapper = new NamingRequestObjectBuilder();
+ private String instanceGroupId = "95cbbe59-1017-4c13-b4e8-d824e54def3e";
+ private String policyInstanceName = "MSO_Policy.Config_MS_VNFInstanceGroup";
+ private String namingType = "InstanceGroup";
+ private String nfNamingCode = "NamingCode";
+ private String instanceGroupName = "InstanceGroupName";
+
+ @Test
+ public void elementMapperTest(){
+ // Expected element
+ Element expected = new Element();
+ expected.setExternalKey(instanceGroupId);
+ expected.setPolicyInstanceName(policyInstanceName);
+ expected.setNamingType(namingType);
+ expected.setResourceName(instanceGroupName);
+ expected.setNamingIngredientsZeroOrMore(nfNamingCode);
+
+ // Actual element
+ Element actual = mapper.elementMapper(instanceGroupId, policyInstanceName, namingType, nfNamingCode, instanceGroupName);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+ @Test
+ public void deleteElementMapperTest(){
+ // Expected Deleteelement
+ Deleteelement expected = new Deleteelement();
+ expected.setExternalKey(instanceGroupId);
+
+ // Actual Deleteelement
+ Deleteelement actual = mapper.deleteElementMapper(instanceGroupId);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+ @Test
+ public void nameGenRequestMapper(){
+ // Expected NameGenRequest
+ NameGenRequest expected = new NameGenRequest();
+ List<Element> elements = new ArrayList<>();
+ Element element = new Element();
+ element.setExternalKey(instanceGroupId);
+ element.setPolicyInstanceName(policyInstanceName);
+ element.setNamingType(namingType);
+ element.setResourceName(instanceGroupName);
+ element.setNamingIngredientsZeroOrMore(nfNamingCode);
+ elements.add(element);
+ expected.setElements(elements);
+
+ //Actual NameGenRequest
+ NameGenRequest actual = mapper.nameGenRequestMapper(elements);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+ @Test
+ public void nameGenDeleteRequestMapper(){
+ // Expected NameGenDeleteRequest
+ NameGenDeleteRequest expected = new NameGenDeleteRequest();
+ List<Deleteelement> deleteElements = new ArrayList<>();
+ Deleteelement deleteElement = new Deleteelement();
+ deleteElement.setExternalKey(instanceGroupId);
+ deleteElements.add(deleteElement);
+ expected.setElements(deleteElements);
+
+ // Actual NameGenDeleteRequest
+ NameGenDeleteRequest actual = mapper.nameGenDeleteRequestMapper(deleteElements);
+
+ assertThat(actual, sameBeanAs(expected));
+ }
+} \ No newline at end of file
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java
new file mode 100644
index 0000000000..629e98abb2
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/NamingServiceResourcesTest.java
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.so.client.orchestration;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.List;
+
+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.data.TestDataSetup;
+import org.onap.namingservice.model.Deleteelement;
+import org.onap.namingservice.model.Element;
+import org.onap.namingservice.model.NameGenDeleteRequest;
+import org.onap.namingservice.model.NameGenDeleteResponse;
+import org.onap.namingservice.model.NameGenRequest;
+import org.onap.namingservice.model.NameGenResponse;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
+import org.onap.so.client.namingservice.NamingClient;
+import org.onap.so.client.namingservice.NamingRequestObjectBuilder;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class NamingServiceResourcesTest extends TestDataSetup{
+ @InjectMocks
+ private NamingServiceResources namingServiceResources = new NamingServiceResources();
+
+ private InstanceGroup instanceGroup;
+
+ @Mock
+ protected NamingRequestObjectBuilder MOCK_namingRequestObjectBuilder;
+
+ @Mock
+ protected NamingClient MOCK_namingClient;
+
+ @Before
+ public void before() {
+ instanceGroup = buildInstanceGroup();
+ }
+
+ @Test
+ public void generateInstanceGroupNameTest() throws Exception {
+ NameGenResponse name = new NameGenResponse();
+ ResponseEntity<NameGenResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
+ Element element = new Element();
+
+ NameGenRequest req = new NameGenRequest();
+ doReturn(element).when(MOCK_namingRequestObjectBuilder).elementMapper(isA(String.class), isA(String.class),
+ isA(String.class), isA(String.class), isA(String.class));
+ doReturn("generatedInstanceGroupName").when(MOCK_namingClient).postNameGenRequest(isA(NameGenRequest.class));
+ doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenRequestMapper(isA(List.class));
+
+ String generatedName = namingServiceResources.generateInstanceGroupName(instanceGroup, "policyInstanceName", "nfNamingCode");
+
+ verify(MOCK_namingClient, times(1)).postNameGenRequest(any(NameGenRequest.class));
+ assertEquals(generatedName, "generatedInstanceGroupName");
+ }
+
+ @Test
+ public void deleteInstanceGroupNameTest() throws Exception {
+ NameGenDeleteResponse name = new NameGenDeleteResponse();
+ ResponseEntity<NameGenDeleteResponse> resp = new ResponseEntity<>(name, null, HttpStatus.OK);
+ Deleteelement deleteElement = new Deleteelement();
+ deleteElement.setExternalKey(instanceGroup.getId());
+ NameGenDeleteRequest req = new NameGenDeleteRequest();
+ doReturn(deleteElement).when(MOCK_namingRequestObjectBuilder).deleteElementMapper(isA(String.class));
+ doReturn("").when(MOCK_namingClient).deleteNameGenRequest(isA(NameGenDeleteRequest.class));
+ doReturn(req).when(MOCK_namingRequestObjectBuilder).nameGenDeleteRequestMapper(isA(List.class));
+
+ namingServiceResources.deleteInstanceGroupName(instanceGroup);
+
+ verify(MOCK_namingClient, times(1)).deleteNameGenRequest(any(NameGenDeleteRequest.class));
+
+ }
+
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
index 4ecdc721f0..7ecb5aa9eb 100644
--- a/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
+++ b/bpmn/so-bpmn-tasks/src/test/resources/application-test.yaml
@@ -41,6 +41,9 @@ pnf:
consumerId: consumerId
topicListenerDelayInSeconds: 5
mso:
+ naming:
+ endpoint: http://localhost:${wiremock.server.port}/web/service/v1/genNetworkElementName
+ auth: Basic YnBlbDptc28tZGItMTUwNyE=
adapters:
requestDb:
auth: Basic YnBlbDptc28tZGItMTUwNyE=