summaryrefslogtreecommitdiffstats
path: root/ms/neng
diff options
context:
space:
mode:
authorBT2983 <BT2983@att.com>2018-10-07 22:39:46 -0600
committerBT2983 <BT2983@att.com>2018-10-07 22:39:46 -0600
commit07a976d05e824365778dac013df88b24ca5d055a (patch)
treecb3d85cd703a3ad2742390ac466a3df7f3e466f7 /ms/neng
parent0c283ec5b010e3af949efa032d9faea7c4383f5f (diff)
Naming micro-service code.
Changes for bypassing normal flow when client passes an already resolved name. Plus, unit test updates, and code formatting updates to follow standards. Change-Id: I7e432531b6f344f6aeb358e2b28b8a6fd74c5070 Issue-ID: CCSDK-608 Signed-off-by: BT2983 <BT2983@att.com>
Diffstat (limited to 'ms/neng')
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java90
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/persistence/NamePersister.java12
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java4
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java20
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java24
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringService.java36
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java127
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestService.java3
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestServiceImpl.java50
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/persistence/repository/GeneratedNameRespository.java11
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java3
-rw-r--r--ms/neng/src/main/resources/db/changelog/db.changelog-master.xml1
-rw-r--r--ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql4
-rw-r--r--ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/11_identifier_map_upd_dml.sql10
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyEarlierTest.java4
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyLaterTest.java4
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyOnUnnamedTest.java2
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorExcMissingDataTest.java16
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorNoSequenceTest.java2
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSeqGenErrorsTest.java6
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceMultiTest.java2
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceTest.java2
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java26
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/AaiResponseTest.java21
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigRequestTest.java10
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigResponseTest.java2
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/HelloWorldTest.java5
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenRequestTest.java14
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenResponseTest.java11
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java38
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java95
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/validator/AaiNameValidatorTest.java52
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/GeneratedNameTest.java127
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/IdentifierMapTest.java27
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/PolicyDetailsTest.java19
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/ServiceParameterTest.java35
-rw-r--r--ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java69
-rw-r--r--ms/neng/src/test/sanity/add-policy-vnf-2.sh46
-rw-r--r--ms/neng/src/test/sanity/add-policy-vnf-ts-2.sh46
-rw-r--r--ms/neng/src/test/sanity/gen-name-vnf-2.sh57
-rw-r--r--ms/neng/src/test/sanity/gen-name-vnf-ts-2-update.sh59
-rw-r--r--ms/neng/src/test/sanity/gen-name-vnf-ts-2.sh57
-rw-r--r--ms/neng/src/test/sanity/policy-vnf-2.json33
-rw-r--r--ms/neng/src/test/sanity/policy-vnf-ts-2.json33
44 files changed, 1033 insertions, 282 deletions
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
index ec04960f..0e1cbc1f 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
@@ -42,7 +42,6 @@ import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
import org.onap.ccsdk.apps.ms.neng.core.persistence.NamePersister;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyFinder;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyParameters;
-import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyPropertyMethodUtils;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicySequence;
import org.onap.ccsdk.apps.ms.neng.core.policy.PropertyOperator;
import org.onap.ccsdk.apps.ms.neng.core.policy.RecipeParser;
@@ -70,6 +69,7 @@ public class NameGenerator {
private final List<Map<String, String>> allElements;
private final Map<String, Map<String, String>> earlierNames;
private final Map<String, Map<String, ?>> policyCache;
+ private final List<String> earlierNamingTypes;
/**
* Constructor.
@@ -89,11 +89,13 @@ public class NameGenerator {
* to names (which is a map with keys "resource-name", "resource-value" and "external-key")
* @param policyCache cache containing policies retrieved in this transaction, to avoid repeated
* calls to policy manager within the same transaction
+ * @param earlierNamingTypes naming-types used earlier in the same transaction
*/
public NameGenerator(PolicyFinder policyFinder, PolicyParameters policyParams, SequenceGenerator seqGenerator,
DbNameValidator dbValidator, AaiNameValidator aaiValidator, NamePersister namePersister,
Map<String, String> requestElement, List<Map<String, String>> allElements,
- Map<String, Map<String, String>> earlierNames, Map<String, Map<String, ?>> policyCache) {
+ Map<String, Map<String, String>> earlierNames, Map<String, Map<String, ?>> policyCache,
+ List<String> earlierNamingTypes) {
this.policyFinder = policyFinder;
this.policyParams = policyParams;
this.seqGenerator = seqGenerator;
@@ -104,6 +106,7 @@ public class NameGenerator {
this.allElements = allElements;
this.earlierNames = earlierNames;
this.policyCache = policyCache;
+ this.earlierNamingTypes = earlierNamingTypes;
}
/**
@@ -117,17 +120,66 @@ public class NameGenerator {
throw new NengException("Could not find policy name in the request");
}
String namingType = findElementNamingType();
+ String relaxedNamingType = relaxedNamingType(namingType);
+ Map<String,String> generated = null;
if (namingType != null) {
- Map<String, String> generated = this.earlierNames.get(namingType);
+ if (!earlierNamingTypes.contains(namingType)) {
+ generated = this.earlierNames.get(namingType);
+ if (generated == null) {
+ generated = this.earlierNames.get(relaxedNamingType);
+ }
+ }
if (generated != null) {
return generated;
}
+ earlierNamingTypes.add(namingType);
return generateNew(policyName, namingType);
+
} else {
throw new NengException("Could not find naming type in the request for policy " + policyName);
}
}
+ /**
+ * Updates a generated name.
+ *
+ * @return the map (with keys "resource-name", "resource-value" and "external-key") containing the name.
+ */
+ public Map<String, String> updateGenerateName() throws Exception {
+ String externalKey = findElementExternalKey();
+ String resourceValue = value(this.requestElement, RESOURCE_VALUE_ELEMENT_ITEM);
+ String reqNamingType = findElementNamingType();
+ String reqResourceName = findElementResourceName();
+ String namingType = (reqNamingType == null) ? reqResourceName : reqNamingType;
+ String relaxedNamingType = relaxedNamingType(namingType);
+
+ if (!aaiValidator.validate(namingType, resourceValue)) {
+ throw new NengException("Name already exists in AAI");
+ }
+ GeneratedName generatedName = null;
+ if (relaxedNamingType != null) {
+ generatedName = namePersister.findByExternalIdAndElementType(externalKey, relaxedNamingType);
+ } else {
+ throw new NengException("Resource Name or naming type must be provided");
+ }
+ if (generatedName == null) {
+ generatedName = new GeneratedName();
+ }
+ generatedName.setName(resourceValue);
+ generatedName.setExternalId(externalKey);
+ generatedName.setElementType(namingType);
+ generatedName.setSequenceNumber(null);
+ generatedName.setSequenceNumberEnc(null);
+ generatedName.setPrefix(null);
+ generatedName.setSuffix(null);
+ generatedName.setIsReleased(null);
+ namePersister.persist(generatedName);
+ Map<String, String> respMap = buildResponse(externalKey, reqResourceName, resourceValue);
+ respMap.put(externalKey, "Resource value updated successfully");
+
+ return respMap;
+ }
+
String applyNameOperation(Map<String, ?> namingModel, String name) throws Exception {
String nameOperation = namingOperation(namingModel);
if (nameOperation != null && !"".equals(nameOperation)) {
@@ -136,8 +188,8 @@ public class NameGenerator {
return name;
}
- String applyPropertyOperation(String value, Map<String, ?> propertyMap) throws Exception {
- return new PropertyOperator().apply(value, propertyMap, this.policyParams);
+ String applyPropertyOperation(String value, Map<String, ?> propertyMap, String recipeItem) throws Exception {
+ return new PropertyOperator().apply(value, propertyMap, this.policyParams, recipeItem);
}
static Map<String, String> buildResponse(String key, String name, String value) {
@@ -210,14 +262,13 @@ public class NameGenerator {
for (String recipeItem : recipe) {
Map<String, ?> propMap = namingProperty(namingModel, recipeItem);
if ("SEQUENCE".equals(recipeItem)) {
- PolicySequence seq = seq(propMap);
- recipeValues.put(recipeItem, seq);
- } else if ("UUID".equals(recipeItem)) {
- String uuid = PolicyPropertyMethodUtils.genUuid();
- recipeValues.put(recipeItem, uuid);
- } else if ("TIMESTAMP".equals(recipeItem)) {
- String ts = PolicyPropertyMethodUtils.getIsoDateString();
- recipeValues.put(recipeItem, ts);
+ String propValue = value(this.requestElement,recipeItem);
+ if (propValue != null) {
+ recipeValues.put(recipeItem, propValue);
+ } else {
+ PolicySequence seq = seq(propMap);
+ recipeValues.put(recipeItem, seq);
+ }
} else {
String val = generateNonSequenceValue(namingModels, policyName, namingType, namingModel, propMap,
recipeItem);
@@ -361,7 +412,13 @@ public class NameGenerator {
val = generateValueRecursively(namingModels, policyName, recipeItem);
}
if (val != null) {
- val = applyPropertyOperation(val, propMap);
+ val = applyPropertyOperation(val, propMap, null);
+ }
+ if (val == null) {
+ val = applyPropertyOperation(val, propMap, recipeItem);
+ }
+ if (val == null) {
+ val = value(namingModel, recipeItem);
}
return val;
}
@@ -389,7 +446,8 @@ public class NameGenerator {
}
if (relaxedElement != null) {
NameGenerator recursive = new NameGenerator(policyFinder, policyParams, seqGenerator, dbValidator,
- aaiValidator, namePersister, relaxedElement, allElements, earlierNames, policyCache);
+ aaiValidator, namePersister, relaxedElement, allElements, earlierNames, policyCache,
+ earlierNamingTypes);
Map<String, String> gen =
recursive.generateNew(policyName, relaxedNamingType, namingModels, relaxedModel);
if (gen != null) {
@@ -455,7 +513,7 @@ public class NameGenerator {
seqEncoded = seqData.getSeqEncoded();
}
GeneratedName record = new GeneratedName();
- GeneratedName releasedName = namePersister.findBy(namingType, name, "Y");
+ GeneratedName releasedName = namePersister.findByElementTypeAndNameAndReleased(namingType, name, "Y");
if (releasedName != null) {
record = releasedName;
record.setLastUpdatedTime(new Timestamp(System.currentTimeMillis()));
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/persistence/NamePersister.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/persistence/NamePersister.java
index 4875052b..cd07a46e 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/persistence/NamePersister.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/persistence/NamePersister.java
@@ -47,7 +47,17 @@ public class NamePersister {
* @param name A name
* @param isReleased An Y/N flag indicating if the name is released or not
*/
- public GeneratedName findBy(String elementType, String name, String isReleased) {
+ public GeneratedName findByElementTypeAndNameAndReleased(String elementType, String name, String isReleased) {
return repository.findByElementTypeAndNameAndIsReleased(elementType, name, isReleased);
}
+
+ /**
+ * Finds a name stored in the DB of the given external ID and type.
+ *
+ * @param externalId The external ID
+ * @param elementType The type of the name
+ */
+ public GeneratedName findByExternalIdAndElementType(String externalId, String elementType) {
+ return repository.findByExternalIdAndRelaxedElementType(externalId, elementType);
+ }
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
index 67805246..79ad2a7a 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
@@ -77,7 +77,9 @@ public class PolicyPropertyMethodUtils {
*/
public static String genUuid() {
UUID uuid = UUID.randomUUID();
- return uuid.toString();
+ String str = uuid.toString();
+ str = str.replaceAll("-", "");
+ return str;
}
/**
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java
index 778c4781..73f46c95 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyReader.java
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Pattern;
/**
* Converts policy data to the structure expected by this micro-service.
@@ -163,7 +164,11 @@ public abstract class PolicyReader implements PolicyFinder {
* Finds the property-value from the given property map.
*/
public static String propertyValue(Map<String, ?> properties) {
- return value(properties, "property-value");
+ String value = value(properties, "property-value");
+ if (value != null && !Pattern.matches("\\$\\{.*\\}.*", value)) {
+ return value;
+ }
+ return null;
}
/**
@@ -175,6 +180,9 @@ public abstract class PolicyReader implements PolicyFinder {
* @param type the naming-type
*/
public static String relaxedNamingType(String type) {
+ if (type == null) {
+ return type;
+ }
type = type.toUpperCase();
if (type.endsWith("NAME")) {
type = type.substring(0, type.length() - 4);
@@ -221,6 +229,11 @@ public abstract class PolicyReader implements PolicyFinder {
if (!(value instanceof String)) {
value = null;
}
+ if (value != null && !Pattern.matches("\\$\\{.*\\}.*", value)) {
+ return value;
+ } else {
+ value = null;
+ }
}
return value;
}
@@ -259,6 +272,11 @@ public abstract class PolicyReader implements PolicyFinder {
if (!(value instanceof String)) {
value = null;
}
+ if (value != null && !Pattern.matches("\\$\\{.*\\}.*", value)) {
+ return value;
+ } else {
+ value = null;
+ }
}
return value;
} else {
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java
index 7eb63244..448ee075 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperator.java
@@ -38,10 +38,12 @@ public class PropertyOperator {
* @param propertyMap a map representing the property, the key of which is "property-operation"
* and the value is the actual property
* @param policyParams parameters configuring policy
+ * @param recipeItem a special recipe item (such as TIMESTAMP, UUID)
* @return the result of applying the property
* @throws Exception all exceptions are propagated
*/
- public String apply(String value, Map<String, ?> propertyMap, PolicyParameters policyParams) throws Exception {
+ public String apply(String value, Map<String, ?> propertyMap, PolicyParameters policyParams,
+ String recipeItem) throws Exception {
String op = propertyOperation(propertyMap);
String mapped = null;
if (op != null) {
@@ -56,6 +58,8 @@ public class PropertyOperator {
}
}
value = applyJavaOperation(value, op, mapped);
+ } else if (recipeItem != null) {
+ value = applyOperationByRecipeName(recipeItem, policyParams);
}
return value;
}
@@ -99,8 +103,11 @@ public class PropertyOperator {
argPart = op.substring(funcStartIndex + 1, funcEndIndex);
}
- argPart = inputString + "," + argPart;
- String[] args = argPart.split(",");
+ String[] args = new String[0];
+ if (inputString != null) {
+ argPart = inputString + "," + argPart;
+ args = argPart.split(",");
+ }
PolicyPropertyMethodUtils utils = new PolicyPropertyMethodUtils();
for (Method m : PolicyPropertyMethodUtils.class.getDeclaredMethods()) {
@@ -115,6 +122,15 @@ public class PropertyOperator {
}
return postOp;
}
+
+ private String applyOperationByRecipeName(String recipeItem, PolicyParameters policyParams) throws Exception {
+ String mapped = policyParams.mapFunction(recipeItem);
+ if (mapped == null) {
+ mapped = camelConverted(recipeItem);
+ }
+ String value = applyJavaOperation(null, recipeItem, mapped);
+ return value;
+ }
static String operationFunction(String operation) throws Exception {
operation = operation.trim();
@@ -149,4 +165,6 @@ public class PropertyOperator {
}
return buf.toString();
}
+
+
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringService.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringService.java
index 1cdd61e1..982ffd38 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringService.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringService.java
@@ -20,6 +20,8 @@
package org.onap.ccsdk.apps.ms.neng.core.service;
+import java.util.List;
+import java.util.Map;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.HelloWorld;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenResponse;
@@ -30,33 +32,43 @@ import org.onap.ccsdk.apps.ms.neng.persistence.entity.PolicyDetails;
*/
public interface SpringService {
/**
- * Name generation API.
+ * API to add a naming policy to the database cache in this micro-service.
+ *
+ * <p/>This is not used by clients -- it is here to help with diagnostics.
*/
- public NameGenResponse genNetworkElementName(NameGenRequest request) throws Exception;
+ public void addPolicy(Object request) throws Exception;
/**
- * Name removal API.
+ * Name generation API.
*/
- public NameGenResponse releaseNetworkElementName(NameGenRequest request) throws Exception;
+ public NameGenResponse genNetworkElementName(NameGenRequest request) throws Exception;
/**
- * API to return naming policy cached in this micro-service.
- *
- * <p/>This is not used by clients -- it is here to help with diagnostics.
+ * Name generation or update API.
*/
- public PolicyDetails getPolicyDetails(String policyName);
+ public NameGenResponse generateOrUpdateName(NameGenRequest request) throws Exception;
/**
- * API to add a naming policy to the database cache in this micro-service.
+ * Heart-beat/ping API.
*
* <p/>This is not used by clients -- it is here to help with diagnostics.
*/
- public void addPolicy(Object request) throws Exception;
+ public HelloWorld getQuickHello(String name);
/**
- * Heart-beat/ping API.
+ * API to return naming policy cached in this micro-service.
*
* <p/>This is not used by clients -- it is here to help with diagnostics.
*/
- public HelloWorld getQuickHello(String name);
+ public PolicyDetails getPolicyDetails(String policyName);
+
+ /**
+ * Name removal API.
+ */
+ public NameGenResponse releaseNetworkElementName(NameGenRequest request) throws Exception;
+
+ /**
+ * Name update API.
+ */
+ public List<Map<String, String>> updateNetworkElementName(NameGenRequest request) throws Exception;
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
index a8ca4bb6..01c8324d 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
@@ -28,15 +28,15 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
+import java.util.regex.Pattern;
import javax.transaction.Transactional;
import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
import org.onap.ccsdk.apps.ms.neng.core.gen.NameGenerator;
import org.onap.ccsdk.apps.ms.neng.core.persistence.NamePersister;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyFinder;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyParameters;
+import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyReader;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.HelloWorld;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenResponse;
@@ -76,18 +76,33 @@ public class SpringServiceImpl implements SpringService {
@Autowired GeneratedNameRespository generatedNameRepository;
/**
- * Heart-beat/ping API.
+ * API to add a naming policy to the database cache in this micro-service.
*/
@Override
- public HelloWorld getQuickHello(String name) {
- if (name == null || name.isEmpty()) {
- name = "world";
+ public void addPolicy(Object request) throws Exception {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> policyData = (Map<String, Object>)request;
+ PolicyDetails pd = new PolicyDetails();
+ String name = (String) policyData.get("policyName");
+ pd.setPolicyName(name);
+ ObjectMapper objectmapper = new ObjectMapper();
+ log.info(objectmapper.writeValueAsString(policyData.get("policyValue")));
+ pd.setPolicyResponse((String)policyData.get("policyValue"));
+ policyDetailsRepository.save(pd);
+ }
+
+ /**
+ * Name generation API -- generates or updates the name.
+ */
+ @Transactional(rollbackOn = Exception.class)
+ public NameGenResponse generateOrUpdateName(NameGenRequest request) throws Exception {
+ if (isUpdateRequest(request)) {
+ NameGenResponse resp = new NameGenResponse();
+ resp.setElements(updateNetworkElementName(request));
+ return resp;
+ } else {
+ return genNetworkElementName(request);
}
- String message = "Hello " + name + "!";
- log.info(message);
- HelloWorld hello = new HelloWorld(message);
- log.info(hello.toString());
- return hello;
}
/**
@@ -100,8 +115,9 @@ public class SpringServiceImpl implements SpringService {
List<Map<String, String>> allElements = new ArrayList<>();
Map<String, Map<String, ?>> policyCache = new HashMap<>();
List<Map<String, String>> generatedNames = new ArrayList<>();
+ List<String> earlierNamingTypes = new ArrayList<String>();
validateRequest(request);
- if (!request.getElements().isEmpty()) {
+ if (request.getElements() != null && !request.getElements().isEmpty()) {
allElements.addAll(request.getElements());
}
PolicyFinder policyFinderImpl = findPolicyFinderImpl(request);
@@ -109,7 +125,7 @@ public class SpringServiceImpl implements SpringService {
log.info("Processing " + requestElement.toString());
NameGenerator nameGen = new NameGenerator(policyFinderImpl, policyParameters, sequenceGenerator,
dbNameValidator, aaiNameValidator, namePersister, requestElement, allElements,
- earlierNames, policyCache);
+ earlierNames, policyCache, earlierNamingTypes);
generatedNames.add(nameGen.generate());
}
NameGenResponse resp = new NameGenResponse();
@@ -126,6 +142,33 @@ public class SpringServiceImpl implements SpringService {
}
/**
+ * API to return naming policy cached in this micro-service.
+ */
+ @Override
+ public PolicyDetails getPolicyDetails(String policyName) {
+ try {
+ return policyDetailsRepository.findPolicyResponseByName(policyName);
+ } catch (Exception e) {
+ return new PolicyDetails();
+ }
+ }
+
+ /**
+ * Heart-beat/ping API.
+ */
+ @Override
+ public HelloWorld getQuickHello(String name) {
+ if (name == null || name.isEmpty()) {
+ name = "world";
+ }
+ String message = "Hello " + name + "!";
+ log.info(message);
+ HelloWorld hello = new HelloWorld(message);
+ log.info(hello.toString());
+ return hello;
+ }
+
+ /**
* Name removal API.
*/
@Transactional(rollbackOn = Exception.class)
@@ -154,31 +197,19 @@ public class SpringServiceImpl implements SpringService {
}
/**
- * API to return naming policy cached in this micro-service.
+ * Name update API.
*/
@Override
- public PolicyDetails getPolicyDetails(String policyName) {
- try {
- return policyDetailsRepository.findPolicyResponseByName(policyName);
- } catch (Exception e) {
- return new PolicyDetails();
+ @Transactional(rollbackOn = Exception.class)
+ public List<Map<String, String>> updateNetworkElementName(NameGenRequest request) throws Exception {
+ List<Map<String, String>> responseList = new ArrayList<>();
+ for (Map<String, String> reqElement :request.getElements()) {
+ NameGenerator nameGen = new NameGenerator(null, null,null, null, aaiNameValidator, namePersister,
+ reqElement, request.getElements(),null, null, null);
+ Map<String, String> resp = nameGen.updateGenerateName();
+ responseList.add(resp);
}
- }
-
- /**
- * API to add a naming policy to the database cache in this micro-service.
- */
- @Override
- public void addPolicy(Object request) throws Exception {
- @SuppressWarnings("unchecked")
- Map<String, Object> policyData = (Map<String, Object>)request;
- PolicyDetails pd = new PolicyDetails();
- String name = (String) policyData.get("policyName");
- pd.setPolicyName(name);
- ObjectMapper objectmapper = new ObjectMapper();
- log.info(objectmapper.writeValueAsString(policyData.get("policyValue")));
- pd.setPolicyResponse((String)policyData.get("policyValue"));
- policyDetailsRepository.save(pd);
+ return responseList;
}
void buildUnAssignResponse(List<GeneratedName> generatedNames, NameGenResponse response) {
@@ -195,22 +226,6 @@ public class SpringServiceImpl implements SpringService {
}
void validateRequest(NameGenRequest request) throws Exception {
- List<Map<String, String>> elems = request.getElements();
- if (elems != null && !elems.isEmpty()) {
- boolean error = false;
- Set<String> externalKeySet = elems.stream().map(s -> s.get("external-key")).collect(Collectors.toSet());
- if (externalKeySet.size() != request.getElements().size()) {
- error = true;
- }
- for (String externalKey : externalKeySet) {
- if (externalKey == null || externalKeyValidator.isPresent(externalKey)) {
- error = true;
- }
- }
- if (error) {
- throw new NengException("External Key is required and must be unique");
- }
- }
}
private PolicyFinder findPolicyFinderImpl(NameGenRequest request) {
@@ -224,4 +239,14 @@ public class SpringServiceImpl implements SpringService {
}
return this.policyFinder;
}
+
+ private boolean isUpdateRequest(NameGenRequest request) throws Exception {
+ for (Map<String, String> reqElement : request.getElements()) {
+ String resourceValue = PolicyReader.value(reqElement, "resource-value");
+ if (resourceValue != null && !Pattern.matches("\\$\\{.*\\}.*", resourceValue)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestService.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestService.java
index 8319a545..8d6db91b 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestService.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestService.java
@@ -24,7 +24,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
-import java.util.Map;
import javax.validation.Valid;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -87,7 +86,7 @@ public interface RestService {
@POST
@Path("/v1/addPolicy")
@Produces({MediaType.APPLICATION_JSON})
- public Map<String, Object> addPolicyToDb(Object request) throws Exception;
+ public Response addPolicyToDb(Object request) throws Exception;
/**
* Heart-beat/ping API.
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestServiceImpl.java
index bc8cab42..e52e0016 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/rs/RestServiceImpl.java
@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.logging.Logger;
import javax.validation.Valid;
import javax.ws.rs.core.Response;
+import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.HelloWorld;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenResponse;
@@ -40,6 +41,7 @@ import org.springframework.web.bind.annotation.RequestBody;
@Component
public class RestServiceImpl implements RestService {
private static Logger log = Logger.getLogger(RestServiceImpl.class.getName());
+ private static final String INTERNAL_ERROR_MSG = "Internal error occured while processing the request.";
@Autowired SpringService service;
@@ -59,12 +61,18 @@ public class RestServiceImpl implements RestService {
@Override
public Response generateNetworkElementName(@RequestBody @Valid NameGenRequest request) {
log.info("Received request: " + request.toString());
+ Map<String, Object> response = new HashMap<>();
try {
- NameGenResponse resp = service.genNetworkElementName(request);
- return Response.ok().entity(resp).build();
+ NameGenResponse resp = service.generateOrUpdateName(request);
+ return buildResponse(resp);
+ } catch (NengException e) {
+ log.warning(e.getMessage());
+ response.put("error", buildErrorResponse("NELGEN-0003", e.getMessage()));
+ return buildErrorResponse(response);
} catch (Exception e) {
log.warning(e.getMessage());
- return Response.status(500).entity("{ \"error\": \"" + e.getMessage() + "\" }").build();
+ response.put("error", buildErrorResponse("err-0500", INTERNAL_ERROR_MSG));
+ return buildErrorResponse(response);
}
}
@@ -74,12 +82,18 @@ public class RestServiceImpl implements RestService {
@Override
public Response releaseNetworkElementName(NameGenRequest request) {
NameGenResponse resp;
+ Map<String, Object> response = new HashMap<>();
try {
resp = service.releaseNetworkElementName(request);
- return Response.ok().entity(resp).build();
+ return buildResponse(resp);
+ } catch (NengException e) {
+ log.warning(e.getMessage());
+ response.put("error", buildErrorResponse("NELGEN-0002", e.getMessage()));
+ return buildErrorResponse(response);
} catch (Exception e) {
log.warning(e.getMessage());
- return Response.status(500).entity("{ \"error\": \"" + e.getMessage() + "\" }").build();
+ response.put("error", buildErrorResponse("err-0500", INTERNAL_ERROR_MSG));
+ return buildErrorResponse(response);
}
}
@@ -98,15 +112,31 @@ public class RestServiceImpl implements RestService {
* API to add a naming policy to the database cache in this micro-service.
*/
@Override
- public Map<String, Object> addPolicyToDb(Object request) throws Exception {
- Map<String, Object> respMap = new HashMap<>();
+ public Response addPolicyToDb(Object request) throws Exception {
+ Map<String, Object> response = new HashMap<>();
try {
service.addPolicy(request);
- respMap.put("status", "Policy added successfully");
+ response.put("status", "Policy added successfully");
+ return buildResponse(response);
} catch (Exception e) {
log.warning(e.getMessage());
- respMap.put("status", "Failed");
+ response.put("error", buildErrorResponse("err-0500", e.getMessage()));
+ return buildErrorResponse(response);
}
- return respMap;
+ }
+
+ Response buildResponse(Object response) {
+ return Response.ok().entity(response).build();
+ }
+
+ Response buildErrorResponse(Map<String, Object> response) {
+ return Response.status(500).entity(response).build();
+ }
+
+ Map<String,Object> buildErrorResponse(String errorCode, String message) {
+ Map<String,Object> error = new HashMap<>();
+ error.put("errorId", errorCode);
+ error.put("message", message);
+ return error;
}
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/persistence/repository/GeneratedNameRespository.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/persistence/repository/GeneratedNameRespository.java
index 4f5f65d5..ed2ac531 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/persistence/repository/GeneratedNameRespository.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/persistence/repository/GeneratedNameRespository.java
@@ -42,6 +42,15 @@ public interface GeneratedNameRespository extends CrudRepository<GeneratedName,
public List<GeneratedName> findByExternalId(String externalId);
/*
+ * Finds entities for a given external system ID and element type, ignoring any special characters in names.
+ */
+ @Query(value = "select * from Generated_Name g where g.external_Id=:externalId and "
+ + "REPLACE(REPLACE(REPLACE(element_type,'NAME',''),'-',''),'_','')=:elementType",
+ nativeQuery = true)
+ public GeneratedName findByExternalIdAndRelaxedElementType(@Param("externalId")String externalId,
+ @Param("elementType")String elementType);
+
+ /*
* Finds the maximum sequence number used for a given prefix and suffix.
*/
@Query("select max(sequenceNumber) from GeneratedName where prefix=:prefix "
@@ -64,4 +73,6 @@ public interface GeneratedNameRespository extends CrudRepository<GeneratedName,
@Query("select g from GeneratedName g where g.elementType=:elementType "
+ "and g.name=:name and (g.isReleased is null or g.isReleased ='N')")
public GeneratedName findUnReleased(@Param("elementType") String elementType, @Param("name") String name);
+
+
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
index 4dd45725..6c4ae889 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
@@ -23,9 +23,6 @@ package org.onap.ccsdk.apps.ms.neng.service.extinf.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.util.logging.Logger;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
diff --git a/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml b/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml
index e481be8c..521a78d2 100644
--- a/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml
+++ b/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml
@@ -32,6 +32,7 @@
<include file="db/changelog/scripts/rel_18_10/create_message_table.sql" />
<include file="db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql" />
+ <include file="db/changelog/scripts/rel_18_10/11_identifier_map_upd_dml.sql" />
</databaseChangeLog>
diff --git a/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql
index bf16b621..f8a6397c 100644
--- a/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql
+++ b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql
@@ -3,8 +3,8 @@
delete from IDENTIFIER_MAP where POLICY_FN_NAME='UUID';
-INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('UUID','genUUID', 'Initial');
+INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('UUID','genUuid', 'Initial');
delete from IDENTIFIER_MAP where POLICY_FN_NAME='TIMESTAMP';
-INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('TIMESTAMP','getISODateString', 'Initial');
+INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('TIMESTAMP','getIsoDateString', 'Initial');
diff --git a/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/11_identifier_map_upd_dml.sql b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/11_identifier_map_upd_dml.sql
new file mode 100644
index 00000000..b7c12fff
--- /dev/null
+++ b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/11_identifier_map_upd_dml.sql
@@ -0,0 +1,10 @@
+--liquibase formatted sql
+--changeset 11_identifier_map_update_sql_recipefunction:18_10.identifier_map_upd_dml.sql
+
+delete from IDENTIFIER_MAP where POLICY_FN_NAME='UUID';
+
+INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('UUID','genUuid', 'Initial');
+
+delete from IDENTIFIER_MAP where POLICY_FN_NAME='TIMESTAMP';
+
+INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('TIMESTAMP','getIsoDateString', 'Initial');
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyEarlierTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyEarlierTest.java
index ccbd4913..44ff6e93 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyEarlierTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyEarlierTest.java
@@ -107,7 +107,7 @@ public class NameGeneratorDependencyEarlierTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), anyInt())).thenReturn(1L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement1, allElements, earlierNames, policyCache);
+ namePresister, requestElement1, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp = gen.generate();
assertEquals("vnf-name", resp.get("resource-name"));
@@ -115,7 +115,7 @@ public class NameGeneratorDependencyEarlierTest {
assertEquals("abcde001ve1", resp.get("resource-value"));
NameGenerator gen2 = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp2 = gen2.generate();
assertEquals("vm-name", resp2.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyLaterTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyLaterTest.java
index 009db5da..a2f54337 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyLaterTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyLaterTest.java
@@ -106,7 +106,7 @@ public class NameGeneratorDependencyLaterTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), anyInt())).thenReturn(1L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement1, allElements, earlierNames, policyCache);
+ namePresister, requestElement1, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp = gen.generate();
assertEquals("vm-name", resp.get("resource-name"));
@@ -114,7 +114,7 @@ public class NameGeneratorDependencyLaterTest {
assertEquals("abcde001ve1mts001", resp.get("resource-value"));
NameGenerator gen2 = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp2 = gen2.generate();
assertEquals("vnf-name", resp2.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyOnUnnamedTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyOnUnnamedTest.java
index e4f3ddc2..be243407 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyOnUnnamedTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorDependencyOnUnnamedTest.java
@@ -107,7 +107,7 @@ public class NameGeneratorDependencyOnUnnamedTest {
}).when(namePresister).persist(anyObject());
NameGenerator gen2 = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp2 = gen2.generate();
assertEquals("vm-name", resp2.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorExcMissingDataTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorExcMissingDataTest.java
index d05644b8..fdbf5d30 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorExcMissingDataTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorExcMissingDataTest.java
@@ -81,7 +81,7 @@ public class NameGeneratorExcMissingDataTest {
when(policyFinder.findPolicy(policyName)).thenReturn(null);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -102,7 +102,7 @@ public class NameGeneratorExcMissingDataTest {
allElements.add(requestElement);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -124,7 +124,7 @@ public class NameGeneratorExcMissingDataTest {
allElements.add(requestElement);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -145,7 +145,7 @@ public class NameGeneratorExcMissingDataTest {
allElements.add(requestElement);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -173,7 +173,7 @@ public class NameGeneratorExcMissingDataTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), anyInt())).thenReturn(1L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -199,7 +199,7 @@ public class NameGeneratorExcMissingDataTest {
when(policyFinder.findPolicy(policyName)).thenReturn(policy);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -225,7 +225,7 @@ public class NameGeneratorExcMissingDataTest {
when(policyFinder.findPolicy(policyName)).thenReturn(policy);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -251,7 +251,7 @@ public class NameGeneratorExcMissingDataTest {
when(policyFinder.findPolicy(policyName)).thenReturn(policy);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorNoSequenceTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorNoSequenceTest.java
index e46ab083..2242229c 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorNoSequenceTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorNoSequenceTest.java
@@ -82,7 +82,7 @@ public class NameGeneratorNoSequenceTest {
when(dbValidator.validate(anyObject(), anyObject())).thenReturn(true);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp = gen.generate();
assertEquals("vnf-name", resp.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSeqGenErrorsTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSeqGenErrorsTest.java
index 46f1e942..ae8dcffd 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSeqGenErrorsTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSeqGenErrorsTest.java
@@ -124,7 +124,7 @@ public class NameGeneratorSeqGenErrorsTest {
}).when(namePresister).persist(anyObject());
NameGenerator gen2 = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp2 = gen2.generate();
assertEquals("vm-name", resp2.get("resource-name"));
@@ -183,7 +183,7 @@ public class NameGeneratorSeqGenErrorsTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), eq(3))).thenReturn(3L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
@@ -210,7 +210,7 @@ public class NameGeneratorSeqGenErrorsTest {
when(dbValidator.validate(anyObject(), anyObject())).thenReturn(false);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement2, allElements, earlierNames, policyCache);
+ namePresister, requestElement2, allElements, earlierNames, policyCache, new ArrayList<>());
try {
gen.generate();
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceMultiTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceMultiTest.java
index 41f0531a..2f23fbdb 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceMultiTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceMultiTest.java
@@ -103,7 +103,7 @@ public class NameGeneratorSequenceMultiTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), eq(4))).thenReturn(4L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp = gen.generate();
assertEquals("vnf-name", resp.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceTest.java
index 9501522d..df94ab50 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGeneratorSequenceTest.java
@@ -95,7 +95,7 @@ public class NameGeneratorSequenceTest {
when(sequenceGenerator.generate(anyObject(), anyObject(), anyObject(), anyObject(), anyInt())).thenReturn(1L);
NameGenerator gen = new NameGenerator(policyFinder, policyParams, sequenceGenerator, dbValidator, aaiValidator,
- namePresister, requestElement, allElements, earlierNames, policyCache);
+ namePresister, requestElement, allElements, earlierNames, policyCache, new ArrayList<>());
Map<String, String> resp = gen.generate();
assertEquals("vnf-name", resp.get("resource-name"));
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java
index 38d44f18..c3471564 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/policy/PropertyOperatorTest.java
@@ -65,7 +65,7 @@ public class PropertyOperatorTest {
Map<String, String> props = new HashMap<>();
props.put("property-operation", "to_lower_case()");
PropertyOperator op = new PropertyOperator();
- assertEquals("asdf", op.apply("ASDF", props, params));
+ assertEquals("asdf", op.apply("ASDF", props, params, null));
}
@Test
@@ -73,7 +73,7 @@ public class PropertyOperatorTest {
Map<String, String> props = new HashMap<>();
props.put("property-operation", "to_upper_case()");
PropertyOperator op = new PropertyOperator();
- assertEquals("ASDF", op.apply("asdf", props, params));
+ assertEquals("ASDF", op.apply("asdf", props, params, null));
}
@Test
@@ -90,21 +90,31 @@ public class PropertyOperatorTest {
Map<String, String> props = new HashMap<>();
props.put("property-operation", "sub_str(0,5)");
- assertEquals("01234", op.apply("0123456789", props, params));
+ assertEquals("01234", op.apply("0123456789", props, params, null));
props.put("property-operation", " sub_str(0,4)");
- assertEquals("0123", op.apply("0123456789", props, params));
+ assertEquals("0123", op.apply("0123456789", props, params, null));
props.put("property-operation", "sub_str(1,5)");
- assertEquals("1234", op.apply("0123456789", props, params));
+ assertEquals("1234", op.apply("0123456789", props, params, null));
props.put("property-operation", "sub_str(1)");
- assertEquals("0", op.apply("0", props, params));
+ assertEquals("0", op.apply("0", props, params, null));
props.put("property-operation", "sub_str(-2)");
- assertEquals("89", op.apply("0123456789", props, params));
+ assertEquals("89", op.apply("0123456789", props, params, null));
props.put("property-operation", "sub_str(-3)");
- assertEquals("789", op.apply("0123456789", props, params));
+ assertEquals("789", op.apply("0123456789", props, params, null));
+ }
+
+ @Test
+ public void testApply_non_mapped() throws Exception {
+ String operation = "to_upper_case";
+ PolicyParameters policyParams = mock(PolicyParameters.class);
+ when(policyParams.mapFunction("sub_str")).thenReturn("substring");
+ PropertyOperator op = new PropertyOperator();
+ String resp = op.apply("MyString", operation, policyParams);
+ assertEquals("MYSTRING", resp);
}
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/AaiResponseTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/AaiResponseTest.java
index 81279b9d..a8b2cfa9 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/AaiResponseTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/AaiResponseTest.java
@@ -21,21 +21,22 @@
package org.onap.ccsdk.apps.ms.neng.core.resource.model;
import static org.junit.Assert.assertEquals;
+
import org.junit.Before;
import org.junit.Test;
public class AaiResponseTest {
- private AaiResponse aai;
+ private AaiResponse aai;
- @Before
- public void setup() {
- aai = new AaiResponse();
- }
-
- @Test
+ @Before
+ public void setup() {
+ aai = new AaiResponse();
+ }
+
+ @Test
public void isRecFound() {
- aai.setRecFound(true);
- assertEquals(true, aai.isRecFound());
+ aai.setRecFound(true);
+ assertEquals(true, aai.isRecFound());
}
-
}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigRequestTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigRequestTest.java
index 20d234ab..fcf0d8bb 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigRequestTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigRequestTest.java
@@ -20,8 +20,6 @@
package org.onap.ccsdk.apps.ms.neng.core.resource.model;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -35,25 +33,25 @@ public class GetConfigRequestTest {
}
@Test
- public void TestGetSetConfigName() {
+ public void testGetSetConfigName() {
getConfigRequest.setConfigName("configName");
Assert.assertEquals("configName", getConfigRequest.getConfigName());
}
@Test
- public void TestGetSetEcompName() {
+ public void testGetSetEcompName() {
getConfigRequest.setEcompName("ecompName");
Assert.assertEquals("ecompName", getConfigRequest.getEcompName());
}
@Test
- public void TestGetSetPolicyName() {
+ public void testGetSetPolicyName() {
getConfigRequest.setPolicyName("policy");
Assert.assertEquals("policy", getConfigRequest.getPolicyName());
}
@Test
- public void TestIsUniqueFunction() {
+ public void testIsUniqueFunction() {
getConfigRequest.setUnique(true);
Assert.assertTrue(getConfigRequest.isUnique());
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigResponseTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigResponseTest.java
index a833834f..90735d95 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigResponseTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/GetConfigResponseTest.java
@@ -33,7 +33,7 @@ public class GetConfigResponseTest {
}
@Test
- public void TestGetSetConfigName() {
+ public void testGetSetConfigName() {
String obj = new String();
getConfigResponse.setResponse(obj);
Assert.assertEquals(obj, getConfigResponse.getResponse());
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/HelloWorldTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/HelloWorldTest.java
index b09d6d60..d6e36fc9 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/HelloWorldTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/HelloWorldTest.java
@@ -21,21 +21,20 @@
package org.onap.ccsdk.apps.ms.neng.core.resource.model;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
public class HelloWorldTest {
private HelloWorld helloWorld;
@Test
- public void TestGetSetMessage() {
+ public void testGetSetMessage() {
helloWorld = new HelloWorld();
helloWorld.setMessage("new Message");
Assert.assertEquals("new Message", helloWorld.getMessage());
}
@Test
- public void TestToString() {
+ public void testToString() {
helloWorld = new HelloWorld("new Message");
Assert.assertEquals("message = new Message", helloWorld.toString());
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenRequestTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenRequestTest.java
index 620208a1..ef33de21 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenRequestTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenRequestTest.java
@@ -20,13 +20,13 @@
package org.onap.ccsdk.apps.ms.neng.core.resource.model;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.HashMap;
public class NameGenRequestTest {
private NameGenRequest nameGenRequest;
@@ -37,7 +37,7 @@ public class NameGenRequestTest {
}
@Test
- public void TestGetSetElements() {
+ public void testGetSetElements() {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("el1", "el2");
@@ -47,7 +47,7 @@ public class NameGenRequestTest {
}
@Test
- public void TestToStringFunction() {
+ public void testToStringFunction() {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("el1", "el2");
@@ -57,7 +57,7 @@ public class NameGenRequestTest {
}
@Test
- public void TestGetSetUseDb() {
+ public void testGetSetUseDb() {
nameGenRequest.setUseDb(true);
Assert.assertTrue(nameGenRequest.getUseDb());
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenResponseTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenResponseTest.java
index f1a73199..509601c1 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenResponseTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/resource/model/NameGenResponseTest.java
@@ -20,16 +20,13 @@
package org.onap.ccsdk.apps.ms.neng.core.resource.model;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
public class NameGenResponseTest {
private NameGenResponse nameGenResponse;
@@ -40,7 +37,7 @@ public class NameGenResponseTest {
}
@Test
- public void TestGetSetElements() {
+ public void testGetSetElements() {
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map = new HashMap<String, String>();
map.put("el1", "el2");
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java
index aca0a533..737eea7b 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceIntTest.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -49,6 +50,7 @@ import org.onap.ccsdk.apps.ms.neng.persistence.entity.ExternalInterface;
import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
import org.onap.ccsdk.apps.ms.neng.persistence.entity.PolicyDetails;
import org.onap.ccsdk.apps.ms.neng.persistence.repository.ExternalInterfaceRespository;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.GeneratedNameRespository;
import org.onap.ccsdk.apps.ms.neng.persistence.repository.PolicyDetailsRepository;
import org.onap.ccsdk.apps.ms.neng.persistence.repository.ServiceParameterRepository;
import org.onap.ccsdk.apps.ms.neng.service.extinf.impl.AaiServiceImpl;
@@ -90,6 +92,8 @@ public class SpringServiceIntTest {
RestServiceImpl restServiceImpl;
@Autowired
ExternalInterfaceRespository extIntRepo;
+ @Autowired
+ GeneratedNameRespository repository;
@Before
public void setup() {
@@ -115,7 +119,7 @@ public class SpringServiceIntTest {
name.setExternalId("EXT-11");
namePersister.persist(name);
- name = namePersister.findBy("VNF", "abcd6ytx", null);
+ name = namePersister.findByElementTypeAndNameAndReleased("VNF", "abcd6ytx", null);
assertNotNull(name);
}
@@ -238,5 +242,37 @@ public class SpringServiceIntTest {
assertNotNull(extIntDb);
assertEquals("nodes/generic-vnfs?vnf-name=",extIntDb.getUrlSuffix());
}
+
+ @Test
+ public void testUpdateNetworkElementName() throws Exception {
+ GeneratedName gn = new GeneratedName();
+ gn.setExternalId("VQA-UN81");
+ gn.setSequenceNumber(1L);
+ gn.setElementType("VNF");
+ gn.setName("DG001ESP");
+ gn.setPrefix("DG");
+ gn.setSuffix("ESP");
+ gn.setCreatedBy("test");
+ gn.setCreatedTime(new Timestamp(System.currentTimeMillis()));
+
+ namePersister.persist(gn);
+ Map<String, String> reqMap = new HashMap<String, String>();
+ reqMap.put("external-key","VQA-UN81");
+ reqMap.put("resource-name", "vnf-name");
+ reqMap.put("resource-value", "DG001ESP1");
+
+ when(aaiServiceImpl.validate(Matchers.anyString(), Matchers.anyString())).thenReturn(true);
+
+ List<Map<String,String>> elList = new ArrayList<>();
+ elList.add(reqMap);
+ NameGenRequest request = new NameGenRequest();
+ request.setElements(elList);
+ restServiceImpl.generateNetworkElementName(request);
+
+ List<GeneratedName> newGn = repository.findByExternalId("VQA-UN81");
+ assertTrue(newGn != null);
+ assertTrue(newGn.size() == 1);
+ assertEquals("DG001ESP1", newGn.get(0).getName());
+ }
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java
index 22063a4d..b679e9ba 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceTest.java
@@ -30,11 +30,15 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
+import org.onap.ccsdk.apps.ms.neng.core.persistence.NamePersister;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.HelloWorld;
import org.onap.ccsdk.apps.ms.neng.core.resource.model.NameGenRequest;
+import org.onap.ccsdk.apps.ms.neng.core.validator.AaiNameValidator;
import org.onap.ccsdk.apps.ms.neng.core.validator.ExternalKeyValidator;
import org.onap.ccsdk.apps.ms.neng.persistence.entity.GeneratedName;
import org.onap.ccsdk.apps.ms.neng.persistence.entity.PolicyDetails;
@@ -58,6 +62,10 @@ public class SpringServiceTest {
PolicyDetailsRepository policyDetailsRepository;
@Mock
GeneratedNameRespository generatedNameRepository;
+ @Mock
+ AaiNameValidator aaiNameValidator;
+ @Mock
+ NamePersister namePersister;
@InjectMocks
SpringServiceImpl springserviceImpl;
@@ -85,8 +93,31 @@ public class SpringServiceTest {
Mockito.when(externalKeyValidator.isPresent(req.get("external-key"))).thenReturn(false);
Mockito.when(serviceParamRepo.findByName("use_db_policy")).thenReturn(param);
springserviceImpl.genNetworkElementName(request);
+ }
+
+ @Test
+ public void genNetworkElementNameTest_empty_elements() throws Exception {
+ NameGenRequest request = new NameGenRequest();
+ request.setElements(new ArrayList<>());
+ springserviceImpl.genNetworkElementName(request);
}
+
+ @Test
+ public void genNetworkElementNameTest_extkey_error_3() throws Exception {
+ NameGenRequest request = new NameGenRequest();
+ List<Map<String, String>> rsp = new ArrayList<>();
+ request.setElements(rsp);
+ springserviceImpl.genNetworkElementName(request);
+ }
+
+ @Test(expected = Exception.class)
+ public void genNetworkElementNameTest_useDb() throws Exception {
+ Mockito.when(externalKeyValidator.isPresent(req.get("external-key"))).thenReturn(false);
+ Mockito.when(serviceParamRepo.findByName("use_db_policy")).thenReturn(param);
+ request.setUseDb(true);
+ springserviceImpl.genNetworkElementName(request);
+ }
@Test
public void getPolicyDetailsTest() {
@@ -109,9 +140,30 @@ public class SpringServiceTest {
Assert.assertNotNull(springserviceImpl.releaseNetworkElementName(request));
}
- @Test(expected=Exception.class)
+ @Test(expected = Exception.class)
public void releaseNetworkElementNameTestForNull() throws Exception {
- springserviceImpl.releaseNetworkElementName(null);
+ springserviceImpl.releaseNetworkElementName(null);
+ }
+
+ @Test(expected = Exception.class)
+ public void releaseNetworkElementNameTest_exp() throws Exception {
+ GeneratedName gn = new GeneratedName();
+ List<GeneratedName> generatedNameList = new ArrayList<>();
+ generatedNameList.add(gn);
+
+ Mockito.when(generatedNameRepository.findByExternalId(req.get("external-key"))).thenThrow(new Exception());
+ springserviceImpl.releaseNetworkElementName(request);
+ }
+
+ @Test(expected = Exception.class)
+ public void releaseNetworkElementNameTest_exp_neng() throws Exception {
+ GeneratedName gn = new GeneratedName();
+ List<GeneratedName> generatedNameList = new ArrayList<>();
+ generatedNameList.add(gn);
+
+ Mockito.when(generatedNameRepository.findByExternalId(req.get("external-key"))).thenThrow(
+ new NengException("Failed"));
+ springserviceImpl.releaseNetworkElementName(request);
}
@Test
@@ -123,4 +175,43 @@ public class SpringServiceTest {
public void testGetQuickHelloForNullMessage() {
Assert.assertTrue(springserviceImpl.getQuickHello("") instanceof HelloWorld);
}
+
+ @Test
+ public void updateNetworkElementName() throws Exception {
+ req.clear();
+ req.put("external-key", "TST-UV1");
+ req.put("resource-name", "vnf-name");
+ req.put("resource-value", "dst1000tv1");
+ req.put("naming-type", "vnf");
+
+ GeneratedName gn = new GeneratedName();
+ gn.setExternalId("TST-UV1");
+ gn.setElementType("VNF");
+ gn.setName("dst1000tv1");
+
+ List<GeneratedName> generatedNameList = new ArrayList<>();
+ generatedNameList.add(gn);
+ Mockito.when(namePersister.findByExternalIdAndElementType(req.get("external-key"), "VNF")).thenReturn(gn);
+ Mockito.when(aaiNameValidator.validate(Matchers.anyString(), Matchers.anyString())).thenReturn(true);
+ Assert.assertNotNull(springserviceImpl.updateNetworkElementName(request));
+ Mockito.verify(namePersister, Mockito.times(1)).persist(gn);
+ }
+
+ @Test(expected = NengException.class)
+ public void updateNetworkElementName_Aai_Fail() throws Exception {
+ req.clear();
+ req.put("external-key", "TST-UV1");
+ req.put("resource-name", "vnf-name");
+ req.put("resource-value", "dst1000tv1");
+ req.put("naming-type", "vnf");
+
+ GeneratedName gn = new GeneratedName();
+ gn.setExternalId("TST-UV1");
+ gn.setElementType("VNF");
+ gn.setName("dst1000tv1");
+
+ Mockito.when(namePersister.findByExternalIdAndElementType(req.get("external-key"), "VNF")).thenReturn(null);
+ Mockito.when(aaiNameValidator.validate(Matchers.anyString(), Matchers.anyString())).thenReturn(false);
+ springserviceImpl.updateNetworkElementName(request);
+ }
}
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/validator/AaiNameValidatorTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/validator/AaiNameValidatorTest.java
new file mode 100644
index 00000000..e8fa6d0b
--- /dev/null
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/core/validator/AaiNameValidatorTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK.apps
+ * ================================================================================
+ * Copyright (C) 2018 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.ccsdk.apps.ms.neng.core.validator;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.apps.ms.neng.persistence.repository.ExternalInterfaceRespository;
+import org.onap.ccsdk.apps.ms.neng.service.extinf.impl.AaiServiceImpl;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiNameValidatorTest {
+ @Mock
+ AaiServiceImpl aaiImpl;
+
+ @Mock
+ ExternalInterfaceRespository dbStuff;
+
+ @InjectMocks
+ AaiNameValidator nameValidator;
+
+ @Test
+ public void testValidate() throws Exception {
+ when(dbStuff.getUriByNameType(Matchers.anyString())).thenReturn(null);
+ assertTrue(nameValidator.validate("VNF", "xyz112uyv"));
+ }
+}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/GeneratedNameTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/GeneratedNameTest.java
index 7965b7a4..bdd5356c 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/GeneratedNameTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/GeneratedNameTest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.ccsdk.apps.ms.neng.persistence.entity;
import org.junit.Assert;
@@ -24,67 +25,67 @@ import org.junit.Before;
import org.junit.Test;
public class GeneratedNameTest {
- private GeneratedName generatedName;
-
- @Before
- public void setUp() {
- generatedName = new GeneratedName();
- }
-
- @Test
- public void testGetSetGeneratedNameId() {
- generatedName.setGeneratedNameId(1);
- Integer expected = 1;
- Assert.assertEquals(expected, generatedName.getGeneratedNameId());
- }
-
- @Test
- public void testGetSetSequenceNumber() {
- generatedName.setSequenceNumber(2121314312321L);
- Long expected = 2121314312321L;
- Assert.assertEquals(expected, generatedName.getSequenceNumber());
- }
-
- @Test
- public void testGetSetSequenceNumberEnc() {
- generatedName.setSequenceNumberEnc("TestSequenceNumberEnc");
- String expected = "TestSequenceNumberEnc";
- Assert.assertEquals(expected, generatedName.getSequenceNumberEnc());
- }
-
- @Test
- public void testGetSetElementType() {
- generatedName.setElementType("TestElementType");
- String expected = "TestElementType";
- Assert.assertEquals(expected, generatedName.getElementType());
- }
-
- @Test
- public void testGetSetName() {
- generatedName.setName("TestName");
- String expected = "TestName";
- Assert.assertEquals(expected, generatedName.getName());
- }
-
- @Test
- public void testGetSetPrefix() {
- generatedName.setPrefix("TestPrefix");
- String expected = "TestPrefix";
- Assert.assertEquals(expected, generatedName.getPrefix());
- }
-
- @Test
- public void testGetSetSuffix() {
- generatedName.setSuffix("TestSuffix");
- String expected = "TestSuffix";
- Assert.assertEquals(expected, generatedName.getSuffix());
- }
-
- @Test
- public void testGetSetIsReleased() {
- generatedName.setIsReleased("TestIsReleased");
- String expected = "TestIsReleased";
- Assert.assertEquals(expected, generatedName.getIsReleased());
- }
-
+ private GeneratedName generatedName;
+
+ @Before
+ public void setUp() {
+ generatedName = new GeneratedName();
+ }
+
+ @Test
+ public void testGetSetGeneratedNameId() {
+ generatedName.setGeneratedNameId(1);
+ Integer expected = 1;
+ Assert.assertEquals(expected, generatedName.getGeneratedNameId());
+ }
+
+ @Test
+ public void testGetSetSequenceNumber() {
+ generatedName.setSequenceNumber(2121314312321L);
+ Long expected = 2121314312321L;
+ Assert.assertEquals(expected, generatedName.getSequenceNumber());
+ }
+
+ @Test
+ public void testGetSetSequenceNumberEnc() {
+ generatedName.setSequenceNumberEnc("TestSequenceNumberEnc");
+ String expected = "TestSequenceNumberEnc";
+ Assert.assertEquals(expected, generatedName.getSequenceNumberEnc());
+ }
+
+ @Test
+ public void testGetSetElementType() {
+ generatedName.setElementType("TestElementType");
+ String expected = "TestElementType";
+ Assert.assertEquals(expected, generatedName.getElementType());
+ }
+
+ @Test
+ public void testGetSetName() {
+ generatedName.setName("TestName");
+ String expected = "TestName";
+ Assert.assertEquals(expected, generatedName.getName());
+ }
+
+ @Test
+ public void testGetSetPrefix() {
+ generatedName.setPrefix("TestPrefix");
+ String expected = "TestPrefix";
+ Assert.assertEquals(expected, generatedName.getPrefix());
+ }
+
+ @Test
+ public void testGetSetSuffix() {
+ generatedName.setSuffix("TestSuffix");
+ String expected = "TestSuffix";
+ Assert.assertEquals(expected, generatedName.getSuffix());
+ }
+
+ @Test
+ public void testGetSetIsReleased() {
+ generatedName.setIsReleased("TestIsReleased");
+ String expected = "TestIsReleased";
+ Assert.assertEquals(expected, generatedName.getIsReleased());
+ }
}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/IdentifierMapTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/IdentifierMapTest.java
index dc510429..30e98d4d 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/IdentifierMapTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/IdentifierMapTest.java
@@ -31,68 +31,69 @@ import org.junit.Before;
import org.junit.Test;
public class IdentifierMapTest {
- private IdentifierMap identifierMap;
+ private IdentifierMap identifierMap;
@Before
public void setUp() {
- identifierMap = new IdentifierMap();
+ identifierMap = new IdentifierMap();
}
@Test
public void testGetSetIdentifierMapId() {
- identifierMap.setIdentifierMapId(1);
+ identifierMap.setIdentifierMapId(1);
Integer expected = 1;
Assert.assertEquals(expected, identifierMap.getIdentifierMapId());
}
@Test
public void testGetSetPolicyFnName() {
- identifierMap.setPolicyFnName("PolicyFnName");
+ identifierMap.setPolicyFnName("PolicyFnName");
String expected = "PolicyFnName";
Assert.assertEquals(expected, identifierMap.getPolicyFnName());
}
@Test
public void testGetSetJsFnName() {
- identifierMap.setJsFnName("JsFnName");
+ identifierMap.setJsFnName("JsFnName");
String expected = "JsFnName";
Assert.assertEquals(expected, identifierMap.getJsFnName());
}
@Test
public void testGetSetCreatedTime() throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
Timestamp timeStamp = new Timestamp(time);
- identifierMap.setCreatedTime(timeStamp);
- Timestamp expected = timeStamp;
+ identifierMap.setCreatedTime(timeStamp);
+ Timestamp expected = timeStamp;
Assert.assertEquals(expected, identifierMap.getCreatedTime());
}
@Test
public void testGetSetCreatedBy() {
- identifierMap.setCreatedBy("Name");
+ identifierMap.setCreatedBy("Name");
String expected = "Name";
Assert.assertEquals(expected, identifierMap.getCreatedBy());
}
@Test
public void testGetSetLastUpdatedTime() throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
Timestamp timeStamp = new Timestamp(time);
- identifierMap.setLastUpdatedTime(timeStamp);
- Timestamp expected = timeStamp;
+ identifierMap.setLastUpdatedTime(timeStamp);
+ Timestamp expected = timeStamp;
Assert.assertEquals(expected, identifierMap.getLastUpdatedTime());
}
@Test
public void testGetSetLastUpdatedBy() {
- identifierMap.setLastUpdatedBy("Name");
+ identifierMap.setLastUpdatedBy("Name");
String expected = "Name";
Assert.assertEquals(expected, identifierMap.getLastUpdatedBy());
}
}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/PolicyDetailsTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/PolicyDetailsTest.java
index 70508684..6506f439 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/PolicyDetailsTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/PolicyDetailsTest.java
@@ -20,7 +20,6 @@
package org.onap.ccsdk.apps.ms.neng.persistence.entity;
-
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
@@ -32,44 +31,42 @@ import org.junit.Before;
import org.junit.Test;
public class PolicyDetailsTest {
- private PolicyDetails policyDetails;
+ private PolicyDetails policyDetails;
@Before
public void setUp() {
- policyDetails = new PolicyDetails();
+ policyDetails = new PolicyDetails();
}
@Test
public void testGetSetPolicyId() {
- policyDetails.setPolicyId(1);
+ policyDetails.setPolicyId(1);
Integer expected = 1;
Assert.assertEquals(expected, policyDetails.getPolicyId());
}
@Test
public void testGetSetPolicyName() {
- policyDetails.setPolicyName("PolicyName");
+ policyDetails.setPolicyName("PolicyName");
String expected = "PolicyName";
Assert.assertEquals(expected, policyDetails.getPolicyName());
}
@Test
public void testGetSetPolicyResponse() {
- policyDetails.setPolicyResponse("PolicyResponse");
+ policyDetails.setPolicyResponse("PolicyResponse");
String expected = "PolicyResponse";
Assert.assertEquals(expected, policyDetails.getPolicyResponse());
}
@Test
public void testGetSetCreatedTime() throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
Timestamp timeStamp = new Timestamp(time);
- policyDetails.setCreatedTime(timeStamp);
- String expected = "PolicyResponse";
+ policyDetails.setCreatedTime(timeStamp);
Assert.assertEquals(timeStamp, policyDetails.getCreatedTime());
}
-
-
}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/ServiceParameterTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/ServiceParameterTest.java
index 42118a5d..25bfe126 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/ServiceParameterTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/persistence/entity/ServiceParameterTest.java
@@ -31,65 +31,66 @@ import org.junit.Before;
import org.junit.Test;
public class ServiceParameterTest {
- private ServiceParameter serviceParameter;
+ private ServiceParameter serviceParameter;
@Before
public void setUp() {
- serviceParameter = new ServiceParameter();
+ serviceParameter = new ServiceParameter();
}
@Test
public void testGetSetServiceParameterId() {
- serviceParameter.setServiceParameterId(1);
+ serviceParameter.setServiceParameterId(1);
Integer expected = 1;
Assert.assertEquals(expected, serviceParameter.getServiceParameterId());
}
@Test
public void testGetSetName() {
- serviceParameter.setName("Name");
+ serviceParameter.setName("Name");
String expected = "Name";
Assert.assertEquals(expected, serviceParameter.getName());
}
@Test
public void testGetSetValue() {
- serviceParameter.setValue("Value");
+ serviceParameter.setValue("Value");
String expected = "Value";
Assert.assertEquals(expected, serviceParameter.getValue());
}
@Test
public void testGetSetCreatedTime() throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- Timestamp timeStamp = new Timestamp(time);
- serviceParameter.setCreatedTime(timeStamp);
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateFormat.parse("23/09/2007");
+ long time = date.getTime();
+ Timestamp timeStamp = new Timestamp(time);
+ serviceParameter.setCreatedTime(timeStamp);
Assert.assertEquals(timeStamp, serviceParameter.getCreatedTime());
}
@Test
public void testGetSetCreatedBy() {
- serviceParameter.setCreatedBy("CreatedBy");
+ serviceParameter.setCreatedBy("CreatedBy");
String expected = "CreatedBy";
Assert.assertEquals(expected, serviceParameter.getCreatedBy());
}
@Test
public void testGetSetLastUpdatedBy() {
- serviceParameter.setLastUpdatedBy("LastUpdatedBy");
+ serviceParameter.setLastUpdatedBy("LastUpdatedBy");
String expected = "LastUpdatedBy";
Assert.assertEquals(expected, serviceParameter.getLastUpdatedBy());
}
@Test
public void testGetSetLastUpdatedTime() throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateFormat.parse("23/09/2007");
- long time = date.getTime();
- Timestamp timeStamp = new Timestamp(time);
- serviceParameter.setLastUpdatedTime(timeStamp);
+ DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateFormat.parse("23/09/2007");
+ long time = date.getTime();
+ Timestamp timeStamp = new Timestamp(time);
+ serviceParameter.setLastUpdatedTime(timeStamp);
Assert.assertEquals(timeStamp, serviceParameter.getLastUpdatedTime());
}
}
+
diff --git a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java
index 77ec7eeb..7732ac71 100644
--- a/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java
+++ b/ms/neng/src/test/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImplTest.java
@@ -22,7 +22,18 @@
package org.onap.ccsdk.apps.ms.neng.service.extinf.impl;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
import com.fasterxml.jackson.databind.ObjectMapper;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -43,14 +54,6 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class PolicyFinderServiceImplTest {
@InjectMocks
@@ -77,13 +80,13 @@ public class PolicyFinderServiceImplTest {
assertNull(policyFinder.findPolicy("policy"));
}
- @SuppressWarnings("unchecked")
@Test(expected = NengException.class)
- public void testHandleError_NOT_FOUND() throws Exception{
- HttpStatusCodeException e = new HttpClientErrorException(HttpStatus.NOT_FOUND,"",null,StandardCharsets.US_ASCII);
+ public void testHandleError_Not_Found() throws Exception {
+ HttpStatusCodeException e = new HttpClientErrorException(HttpStatus.NOT_FOUND,"",
+ null,StandardCharsets.US_ASCII);
policyFinder.handleError(e);
-
}
+
@SuppressWarnings("unchecked")
@Test
public void testmakeOutboundCall() throws Exception {
@@ -213,4 +216,46 @@ public class PolicyFinderServiceImplTest {
configMap.put("config", contentMap);
return configMap;
}
+
+ @SuppressWarnings("unchecked")
+ @Test(expected = NengException.class)
+ public void testmakeOutboundCall_500_statusExp() throws Exception {
+ HttpClientErrorException exp = new HttpClientErrorException(HttpStatus.METHOD_NOT_ALLOWED, "{error}");
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenThrow(exp);
+ policManProps.setUrl("http://policyManager.onap.org");
+ GetConfigRequest request = new GetConfigRequest();
+ request.setPolicyName("policy");
+ policyFinder.makeOutboundCall(request, GetConfigResponse.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(expected = NengException.class)
+ public void testmakeOutboundCall_500_statusExp_notFound() throws Exception {
+ HttpClientErrorException exp = new HttpClientErrorException(HttpStatus.NOT_FOUND, "{error}");
+ when(restTemplate.exchange(Matchers.any(RequestEntity.class), Matchers.any(Class.class))).thenThrow(exp);
+ policManProps.setUrl("http://policyManager.onap.org");
+ GetConfigRequest request = new GetConfigRequest();
+ request.setPolicyName("policy");
+ policyFinder.makeOutboundCall(request, GetConfigResponse.class);
+ }
+
+ @Test
+ public void testmakeOutboundCall_err_policy() throws Exception {
+ Map<String, Object> configMap = buildPolicyResponse();
+ Object resp = configMap;
+ GetConfigResponse configResp = new GetConfigResponse();
+ configResp.setResponse(resp);
+ doReturn(configResp).when(policyFinder).getConfig("policy");
+ assertNull(policyFinder.findPolicy("policy"));
+ }
+
+ @Test
+ public void testmakeOutboundCall_err_policy_empty() throws Exception {
+ Object resp = Arrays.asList(new Object[]{});
+ GetConfigResponse configResp = new GetConfigResponse();
+ configResp.setResponse(resp);
+ doReturn(configResp).when(policyFinder).getConfig("policy");
+ assertNull(policyFinder.findPolicy("policy"));
+ }
+
}
diff --git a/ms/neng/src/test/sanity/add-policy-vnf-2.sh b/ms/neng/src/test/sanity/add-policy-vnf-2.sh
new file mode 100644
index 00000000..e4820671
--- /dev/null
+++ b/ms/neng/src/test/sanity/add-policy-vnf-2.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#============LICENSE_START=======================================================
+# ONAP : CCSDK.apps
+# ================================================================================
+# Copyright (C) 2018 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=========================================================
+
+#==================================================================================
+# This script does a sanity test on the add-policy API of the micro-service.
+#==================================================================================
+
+. ./env.sh
+URL=web/service/v1/addPolicy
+TEMP_FILE=/tmp/add-policy.$$.$RANDOM
+EXTERNAL_KEY=${1:-123456789}
+
+printf '{ ' > $TEMP_FILE
+printf '"policyName": "vnf-policy-2' >> $TEMP_FILE
+printf '", "policyValue" : "' >> $TEMP_FILE
+cat ./policy-vnf-2.json | sed 's/\"/\\\"/g' | tr '\n' ' ' | tr '\r' ' ' >> $TEMP_FILE
+echo '"}' >> $TEMP_FILE
+
+echo "==================================================="
+echo "====== Adding Policy: ==========================="
+cat $TEMP_FILE
+echo ""
+echo "==================================================="
+
+echo "==================================================="
+curl -vi -H "Content-Type: application/json" --data @$TEMP_FILE $PROTOCOL://$HOST:$PORT/$URL
+echo "==================================================="
+
+rm -f $TEMP_FILE
+
diff --git a/ms/neng/src/test/sanity/add-policy-vnf-ts-2.sh b/ms/neng/src/test/sanity/add-policy-vnf-ts-2.sh
new file mode 100644
index 00000000..009b7c34
--- /dev/null
+++ b/ms/neng/src/test/sanity/add-policy-vnf-ts-2.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#============LICENSE_START=======================================================
+# ONAP : CCSDK.apps
+# ================================================================================
+# Copyright (C) 2018 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=========================================================
+
+#==================================================================================
+# This script does a sanity test on the add-policy API of the micro-service.
+#==================================================================================
+
+. ./env.sh
+URL=web/service/v1/addPolicy
+TEMP_FILE=/tmp/add-policy.$$.$RANDOM
+EXTERNAL_KEY=${1:-123456789}
+
+printf '{ ' > $TEMP_FILE
+printf '"policyName": "vnf-policy-ts-2' >> $TEMP_FILE
+printf '", "policyValue" : "' >> $TEMP_FILE
+cat ./policy-vnf-ts-2.json | sed 's/\"/\\\"/g' | tr '\n' ' ' | tr '\r' ' ' >> $TEMP_FILE
+echo '"}' >> $TEMP_FILE
+
+echo "==================================================="
+echo "====== Adding Policy: ==========================="
+cat $TEMP_FILE
+echo ""
+echo "==================================================="
+
+echo "==================================================="
+curl -vi -H "Content-Type: application/json" --data @$TEMP_FILE $PROTOCOL://$HOST:$PORT/$URL
+echo "==================================================="
+
+rm -f $TEMP_FILE
+
diff --git a/ms/neng/src/test/sanity/gen-name-vnf-2.sh b/ms/neng/src/test/sanity/gen-name-vnf-2.sh
new file mode 100644
index 00000000..27901538
--- /dev/null
+++ b/ms/neng/src/test/sanity/gen-name-vnf-2.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+#============LICENSE_START=======================================================
+# ONAP : CCSDK.apps
+# ================================================================================
+# Copyright (C) 2018 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=========================================================
+
+#==================================================================================
+# This script does a sanity test on the generate-name API of this micro-service.
+#==================================================================================
+
+. ./env.sh
+URL=web/service/v1/genNetworkElementName
+TEMP_FILE=/tmp/gen-name.$$.$RANDOM
+EXTERNAL_KEY=$RANDOM
+
+USE_DB=${1:-'Y'}
+USE_DB_BOOL=$([ "$USE_DB" == "Y" ] && echo "true" || echo "false")
+
+printf '{ "UseDb": "' > $TEMP_FILE
+printf $USE_DB_BOOL >> $TEMP_FILE
+printf '", "elements": [ { "external-key": "sanity-' >> $TEMP_FILE
+printf $EXTERNAL_KEY >> $TEMP_FILE
+printf '", "policy-instance-name": "vnf-policy-2", "NF_NAMING_CODE": "me9", "COMPLEX": "dlstxa", ' >> $TEMP_FILE
+printf '"resource-name": "VNF2", "naming-type": "VNF2" } ] }' >> $TEMP_FILE
+
+echo "==================================================="
+echo "======== Generating name with request: ============"
+echo ""
+echo ""
+cat $TEMP_FILE
+echo ""
+echo ""
+echo ""
+echo "==================================================="
+
+echo "==================================================="
+curl -vi -H "Content-Type: application/json" --data @$TEMP_FILE $PROTOCOL://$HOST:$PORT/$URL
+echo ""
+echo ""
+echo "==================================================="
+
+rm -f $TEMP_FILE
+
+
diff --git a/ms/neng/src/test/sanity/gen-name-vnf-ts-2-update.sh b/ms/neng/src/test/sanity/gen-name-vnf-ts-2-update.sh
new file mode 100644
index 00000000..b90af171
--- /dev/null
+++ b/ms/neng/src/test/sanity/gen-name-vnf-ts-2-update.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+#============LICENSE_START=======================================================
+# ONAP : CCSDK.apps
+# ================================================================================
+# Copyright (C) 2018 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=========================================================
+
+#==================================================================================
+# This script does a sanity test on the generate-name API of this micro-service.
+#==================================================================================
+
+. ./env.sh
+URL=web/service/v1/genNetworkElementName
+TEMP_FILE=/tmp/gen-name.$$.$RANDOM
+EXTERNAL_KEY=$RANDOM
+
+USE_DB=${1:-'Y'}
+USE_DB_BOOL=$([ "$USE_DB" == "Y" ] && echo "true" || echo "false")
+
+printf '{ "UseDb": "' > $TEMP_FILE
+printf $USE_DB_BOOL >> $TEMP_FILE
+printf '", "elements": [ { "external-key": "sanity-' >> $TEMP_FILE
+printf $EXTERNAL_KEY >> $TEMP_FILE
+printf '", "policy-instance-name": "vnf-policy-ts-2", "NF_NAMING_CODE": "me9", "COMPLEX": "dlstxa", ' >> $TEMP_FILE
+printf '"resource-name": "VNF2", "resource-value": "ASDF' >> $TEMP_FILE
+printf $EXTERNAL_KEY >> $TEMP_FILE
+printf '", "naming-type": "VNF2" } ] }' >> $TEMP_FILE
+
+echo "==================================================="
+echo "======== Generating name with request: ============"
+echo ""
+echo ""
+cat $TEMP_FILE
+echo ""
+echo ""
+echo ""
+echo "==================================================="
+
+echo "==================================================="
+curl -vi -H "Content-Type: application/json" --data @$TEMP_FILE $PROTOCOL://$HOST:$PORT/$URL
+echo ""
+echo ""
+echo "==================================================="
+
+rm -f $TEMP_FILE
+
+
diff --git a/ms/neng/src/test/sanity/gen-name-vnf-ts-2.sh b/ms/neng/src/test/sanity/gen-name-vnf-ts-2.sh
new file mode 100644
index 00000000..3aeeea8e
--- /dev/null
+++ b/ms/neng/src/test/sanity/gen-name-vnf-ts-2.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+#============LICENSE_START=======================================================
+# ONAP : CCSDK.apps
+# ================================================================================
+# Copyright (C) 2018 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=========================================================
+
+#==================================================================================
+# This script does a sanity test on the generate-name API of this micro-service.
+#==================================================================================
+
+. ./env.sh
+URL=web/service/v1/genNetworkElementName
+TEMP_FILE=/tmp/gen-name.$$.$RANDOM
+EXTERNAL_KEY=$RANDOM
+
+USE_DB=${1:-'Y'}
+USE_DB_BOOL=$([ "$USE_DB" == "Y" ] && echo "true" || echo "false")
+
+printf '{ "UseDb": "' > $TEMP_FILE
+printf $USE_DB_BOOL >> $TEMP_FILE
+printf '", "elements": [ { "external-key": "sanity-' >> $TEMP_FILE
+printf $EXTERNAL_KEY >> $TEMP_FILE
+printf '", "policy-instance-name": "vnf-policy-ts-2", "NF_NAMING_CODE": "me9", "COMPLEX": "dlstxa", ' >> $TEMP_FILE
+printf '"resource-name": "VNF2", "naming-type": "VNF2" } ] }' >> $TEMP_FILE
+
+echo "==================================================="
+echo "======== Generating name with request: ============"
+echo ""
+echo ""
+cat $TEMP_FILE
+echo ""
+echo ""
+echo ""
+echo "==================================================="
+
+echo "==================================================="
+curl -vi -H "Content-Type: application/json" --data @$TEMP_FILE $PROTOCOL://$HOST:$PORT/$URL
+echo ""
+echo ""
+echo "==================================================="
+
+rm -f $TEMP_FILE
+
+
diff --git a/ms/neng/src/test/sanity/policy-vnf-2.json b/ms/neng/src/test/sanity/policy-vnf-2.json
new file mode 100644
index 00000000..0ff6ea33
--- /dev/null
+++ b/ms/neng/src/test/sanity/policy-vnf-2.json
@@ -0,0 +1,33 @@
+[
+ {
+ "config": {
+ "content": {
+ "naming-models":[
+ {
+ "naming-properties":[
+ { "property-name" : "COMPLEX", "property-operation" : "substr(5)" },
+ { "property-name" : "SEQUENCE", "increment-sequence":{
+ "max" : "zzz" , "scope" : "ENTIRETY" , "start-value" : "001" , "length" : "3",
+ "increment" : "1" , "sequence-type" : "alpha-numeric"}
+ },
+ {"property-name" : "NF_NAMING_CODE"}
+ ],
+ "naming-type" : "VNF2",
+ "nfRole" : "vPE",
+ "naming-recipe" : "COMPLEX|SEQUENCE|NF_NAMING_CODE"
+ },
+ {
+ "naming-properties":[
+ {"property-name" : "NF_NAMING_CODE"}
+ ],
+ "naming-type" : "VNF2",
+ "nfRole" : "VNF2",
+ "naming-recipe" : "NF_NAMING_CODE"
+ }
+ ]
+ }
+ },
+ "policyName": "vnf2-policy-1"
+ }
+]
+
diff --git a/ms/neng/src/test/sanity/policy-vnf-ts-2.json b/ms/neng/src/test/sanity/policy-vnf-ts-2.json
new file mode 100644
index 00000000..21b61892
--- /dev/null
+++ b/ms/neng/src/test/sanity/policy-vnf-ts-2.json
@@ -0,0 +1,33 @@
+[
+ {
+ "config": {
+ "content": {
+ "naming-models":[
+ {
+ "naming-properties":[
+ { "property-name" : "COMPLEX", "property-operation" : "substr(5)" },
+ { "property-name" : "SEQUENCE", "increment-sequence":{
+ "max" : "zzz" , "scope" : "ENTIRETY" , "start-value" : "001" , "length" : "3",
+ "increment" : "1" , "sequence-type" : "alpha-numeric"}
+ },
+ {"property-name" : "NF_NAMING_CODE"}
+ ],
+ "naming-type" : "VNF2",
+ "nfRole" : "vPE",
+ "naming-recipe" : "COMPLEX|UUID|SEQUENCE|NF_NAMING_CODE|TIMESTAMP"
+ },
+ {
+ "naming-properties":[
+ {"property-name" : "NF_NAMING_CODE"}
+ ],
+ "naming-type" : "VNF2",
+ "nfRole" : "VNF2",
+ "naming-recipe" : "NF_NAMING_CODE"
+ }
+ ]
+ }
+ },
+ "policyName": "vnf-policy-2"
+ }
+]
+