summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml17
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java14
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java5
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java11
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java51
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java16
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java10
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java206
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java116
9 files changed, 279 insertions, 167 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml
index a628903085..16cc4ac269 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml
@@ -45,6 +45,23 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>${testng.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
index c7623f8181..fa23b51742 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,13 +24,13 @@ import java.util.Collection;
public interface BaseDao<T> {
- Collection<T> list(T entity);
+ Collection<T> list(T entity);
- void create(T entity);
+ void create(T entity);
- void update(T entity);
+ void update(T entity);
- T get(T entity);
+ T get(T entity);
- void delete(T entity);
+ void delete(T entity);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
index 1fa4bb23fe..36dfefa840 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,7 +20,6 @@
package org.openecomp.core.dao;
-
import org.openecomp.core.dao.types.UniqueValueEntity;
public interface UniqueValueDao extends BaseDao<UniqueValueEntity> {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
index 9f57e4fadd..022ad8e09d 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
@@ -7,9 +7,9 @@
* 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.
@@ -24,7 +24,8 @@ import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
public abstract class UniqueValueDaoFactory extends AbstractComponentFactory<UniqueValueDao> {
- public static UniqueValueDaoFactory getInstance() {
- return AbstractFactory.getInstance(UniqueValueDaoFactory.class);
- }
+
+ public static UniqueValueDaoFactory getInstance() {
+ return AbstractFactory.getInstance(UniqueValueDaoFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
index c53280ed7a..24038b9b0c 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
@@ -7,9 +7,9 @@
* 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.
@@ -23,42 +23,21 @@ package org.openecomp.core.dao.types;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@NoArgsConstructor
+@AllArgsConstructor
+@Getter
+@Setter
@Table(name = "unique_value")
public class UniqueValueEntity {
- @PartitionKey
- private String type;
-
- @PartitionKey(value = 1)
- private String value;
-
- /**
- * Every entity class must have a default constructor according to
- * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
- * Definition of mapped classes</a>.
- */
- public UniqueValueEntity() {
- // Don't delete! Default constructor is required by DataStax driver
- }
-
- public UniqueValueEntity(String type, String value) {
- this.type = type;
- this.value = value;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getValue() {
- return value;
- }
+ @PartitionKey
+ private String type;
- public void setValue(String value) {
- this.value = value;
- }
+ @PartitionKey(value = 1)
+ private String value;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
index 56d15a88d4..ff4661c44d 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
@@ -7,9 +7,9 @@
* 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.
@@ -25,15 +25,15 @@ import com.datastax.driver.mapping.MappingManager;
public interface NoSqlDb {
- //TODO: remove cassandra types from here!! (like done in SDC...).
+ //TODO: remove cassandra types from here!! (like done in SDC...).
- void insert(String tableName, String[] colNames, Object[] values);
+ void insert(String tableName, String[] colNames, Object[] values);
- ResultSet execute(String statement);
+ ResultSet execute(String statement);
- ResultSet execute(String statementName, Object... values);
+ ResultSet execute(String statementName, Object... values);
- MappingManager getMappingManager();
+ MappingManager getMappingManager();
- String getVersion();
+ String getVersion();
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
index ede264f288..31b6f6a505 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
@@ -7,9 +7,9 @@
* 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.
@@ -27,8 +27,8 @@ import org.openecomp.core.nosqldb.api.NoSqlDb;
public abstract class NoSqlDbFactory extends AbstractComponentFactory<NoSqlDb> {
- public static NoSqlDbFactory getInstance() {
+ public static NoSqlDbFactory getInstance() {
- return AbstractFactory.getInstance(NoSqlDbFactory.class);
- }
+ return AbstractFactory.getInstance(NoSqlDbFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
index 0ba7228cce..aded1fa99f 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
@@ -28,120 +28,120 @@ import org.openecomp.sdc.common.errors.ErrorCode;
public class UniqueValueUtil {
- private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION";
- private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists.";
- private static final char FORMATTED_UNIQUE_VALUE_SEPARATOR = '_';
-
- private final UniqueValueDao uniqueValueDao;
-
- public UniqueValueUtil(UniqueValueDao uniqueValueDao) {
- this.uniqueValueDao = uniqueValueDao;
- }
-
- /**
- * Create unique value.
- *
- * @param type the type
- * @param uniqueCombination the unique combination
- */
- public void createUniqueValue(String type, String... uniqueCombination) {
- String originalEntityName = null;
- if (ArrayUtils.isNotEmpty(uniqueCombination)) {
- originalEntityName = uniqueCombination[uniqueCombination.length - 1];
+ private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION";
+ private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists.";
+ private static final char FORMATTED_UNIQUE_VALUE_SEPARATOR = '_';
+
+ private final UniqueValueDao uniqueValueDao;
+
+ public UniqueValueUtil(UniqueValueDao uniqueValueDao) {
+ this.uniqueValueDao = uniqueValueDao;
}
- Optional<String> formattedValue = formatValue(uniqueCombination);
- if (formattedValue.isPresent()) {
- validateUniqueValue(type, formattedValue.get(), originalEntityName);
- uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get()));
+ /**
+ * Create unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void createUniqueValue(String type, String... uniqueCombination) {
+ String originalEntityName = null;
+ if (ArrayUtils.isNotEmpty(uniqueCombination)) {
+ originalEntityName = uniqueCombination[uniqueCombination.length - 1];
+ }
+
+ Optional<String> formattedValue = formatValue(uniqueCombination);
+ if (formattedValue.isPresent()) {
+ validateUniqueValue(type, formattedValue.get(), originalEntityName);
+ uniqueValueDao.create(new UniqueValueEntity(type, formattedValue.get()));
+ }
}
- }
-
- /**
- * Delete unique value.
- *
- * @param type the type
- * @param uniqueCombination the unique combination
- */
- public void deleteUniqueValue(String type, String... uniqueCombination) {
- formatValue(uniqueCombination).ifPresent(
- formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
-
- }
-
- /**
- * Update unique value.
- *
- * @param type the type
- * @param oldValue the old value
- * @param newValue the new value
- * @param uniqueContext the unique context
- */
- public void updateUniqueValue(String type, String oldValue, String newValue,
- String... uniqueContext) {
- if (newValue == null || oldValue == null || !newValue.equalsIgnoreCase(oldValue)) {
- createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue}));
- deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue}));
+
+ /**
+ * Delete unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void deleteUniqueValue(String type, String... uniqueCombination) {
+ formatValue(uniqueCombination).ifPresent(
+ formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
+
}
- }
-
- /**
- * Validate unique value.
- *
- * @param type the type
- * @param uniqueCombination the unique combination
- */
- public void validateUniqueValue(String type, String... uniqueCombination) {
- String originalEntityName = null;
- if (ArrayUtils.isNotEmpty(uniqueCombination)) {
- originalEntityName = uniqueCombination[uniqueCombination.length - 1];
+
+ /**
+ * Update unique value.
+ *
+ * @param type the type
+ * @param oldValue the old value
+ * @param newValue the new value
+ * @param uniqueContext the unique context
+ */
+ public void updateUniqueValue(String type, String oldValue, String newValue,
+ String... uniqueContext) {
+ if (newValue == null || !newValue.equalsIgnoreCase(oldValue)) {
+ createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {newValue}));
+ deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {oldValue}));
+ }
}
- Optional<String> formattedValue = formatValue(uniqueCombination);
- if (formattedValue.isPresent()) {
- validateUniqueValue(type, formattedValue.get(), originalEntityName);
+ /**
+ * Validate unique value.
+ *
+ * @param type the type
+ * @param uniqueCombination the unique combination
+ */
+ public void validateUniqueValue(String type, String... uniqueCombination) {
+ String originalEntityName = null;
+ if (ArrayUtils.isNotEmpty(uniqueCombination)) {
+ originalEntityName = uniqueCombination[uniqueCombination.length - 1];
+ }
+
+ Optional<String> formattedValue = formatValue(uniqueCombination);
+ if (formattedValue.isPresent()) {
+ validateUniqueValue(type, formattedValue.get(), originalEntityName);
+ }
}
- }
-
- /**
- * Checks if a unique value is taken.
- *
- * @return true if the unique value is occupied, false otherwise
- */
- public boolean isUniqueValueOccupied(String type, String... uniqueCombination) {
- return formatValue(uniqueCombination)
- .map(formattedValue -> isUniqueValueOccupied(type, formattedValue))
- .orElse(false);
- }
-
- private void validateUniqueValue(String type, String formattedValue, String originalEntityName) {
- if (isUniqueValueOccupied(type, formattedValue)) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId(UNIQUE_VALUE_VIOLATION)
- .withMessage(String
- .format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName))
- .build());
+
+ private void validateUniqueValue(String type, String formattedValue, String originalEntityName) {
+ if (isUniqueValueOccupied(type, formattedValue)) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withId(UNIQUE_VALUE_VIOLATION)
+ .withMessage(String
+ .format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName))
+ .build());
+ }
}
- }
- private boolean isUniqueValueOccupied(String type, String formattedValue) {
- return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null;
- }
+ /**
+ * Checks if a unique value is taken.
+ *
+ * @return true if the unique value is occupied, false otherwise
+ */
+ public boolean isUniqueValueOccupied(String type, String... uniqueCombination) {
+ return formatValue(uniqueCombination)
+ .map(formattedValue -> isUniqueValueOccupied(type, formattedValue))
+ .orElse(false);
+ }
- private static Optional<String> formatValue(String[] uniqueCombination) {
- if (uniqueCombination == null || uniqueCombination.length == 0
- || getValueWithoutContext(uniqueCombination) == null) {
- return Optional.empty();
+ private boolean isUniqueValueOccupied(String type, String formattedValue) {
+ return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null;
}
- uniqueCombination[uniqueCombination.length - 1] =
- getValueWithoutContext(uniqueCombination).toLowerCase();
- return Optional.of(CommonMethods
- .arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
- }
+ private static Optional<String> formatValue(String[] uniqueCombination) {
+ if (uniqueCombination == null || uniqueCombination.length == 0
+ || getValueWithoutContext(uniqueCombination) == null) {
+ return Optional.empty();
+ }
- private static String getValueWithoutContext(String... uniqueCombination) {
- return uniqueCombination[uniqueCombination.length - 1];
- }
+ uniqueCombination[uniqueCombination.length - 1] =
+ getValueWithoutContext(uniqueCombination).toLowerCase();
+ return Optional.of(CommonMethods
+ .arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
+ }
+
+ private static String getValueWithoutContext(String... uniqueCombination) {
+ return uniqueCombination[uniqueCombination.length - 1];
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java
new file mode 100644
index 0000000000..eeae2f75b0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java
@@ -0,0 +1,116 @@
+/*
+ *
+ * Copyright © 2017-2018 European Support Limited
+ *
+ * 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.
+ * /
+ *
+ */
+
+package org.openecomp.core.util;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.core.dao.UniqueValueDao;
+import org.openecomp.core.dao.types.UniqueValueEntity;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class UniqueValueUtilTest {
+
+ private static final String ENTITLEMENT_POOL_NAME = "Entitlement Pool name";
+ private static final String ORIGINAL_ENTITY_NAME = "originalEntityName";
+
+ @Mock
+ private UniqueValueDao uniqueValueDao;
+
+ private UniqueValueUtil uniqueValueUtil;
+
+ @BeforeMethod
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
+ }
+
+ @Test
+ public void testCreateUniqueValue() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null);
+ uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME);
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).create(Mockito.any());
+ }
+
+ @Test(expectedExceptions = CoreException.class)
+ public void testCreateUniqueValueNotUnique() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity());
+ uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME);
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).create(Mockito.any());
+ }
+
+ @Test
+ public void testDeleteUniqueValue() {
+ Mockito.doNothing().when(uniqueValueDao).delete(Mockito.any());
+ uniqueValueUtil.deleteUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME);
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).delete(Mockito.any());
+ }
+
+ @Test
+ public void testDeleteUniqueValueNoValue() {
+ uniqueValueUtil.deleteUniqueValue(ENTITLEMENT_POOL_NAME);
+ Mockito.verify(uniqueValueDao, Mockito.times(0)).delete(Mockito.any());
+ }
+
+ @Test
+ public void testUpdateUniqueValue() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null);
+ Mockito.doNothing().when(uniqueValueDao).delete(Mockito.any());
+
+ uniqueValueUtil.updateUniqueValue(ENTITLEMENT_POOL_NAME, "oldName", "newName", "uniqueContext");
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).create(Mockito.any());
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).delete(Mockito.any());
+ }
+
+ @Test
+ public void testValidateUniqueValue() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null);
+ uniqueValueUtil.validateUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME);
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).get(Mockito.any());
+ }
+
+ @Test(expectedExceptions = CoreException.class)
+ public void testValidateUniqueValueNotUnique() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity());
+ uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME);
+
+ Mockito.verify(uniqueValueDao, Mockito.times(1)).get(Mockito.any());
+ }
+
+ @Test
+ public void testIsUniqueValueOccupied() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity());
+ Assert.assertTrue(uniqueValueUtil.isUniqueValueOccupied(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME));
+ }
+
+ @Test
+ public void testIsUniqueValueOccupiedFalse() {
+ Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null);
+ Assert.assertFalse(uniqueValueUtil.isUniqueValueOccupied(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME));
+ }
+}