summaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java45
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java29
2 files changed, 47 insertions, 27 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
index df4e3847e2..9c8b5e48a5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ComponentValidationsTest.java
@@ -16,7 +16,13 @@
package org.openecomp.sdc.be.components.validation;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import fj.data.Either;
+import java.util.ArrayList;
+import java.util.List;
import mockit.Deencapsulation;
import org.junit.Before;
import org.junit.Test;
@@ -31,6 +37,7 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Resource;
@@ -60,35 +67,52 @@ public class ComponentValidationsTest {
@Test
public void testValidateComponentInstanceExist() throws Exception {
+ String instanceId = "test";
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setUniqueId(instanceId);
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(instance);
+
Component component = new Resource();
- String instanceId = "";
- boolean result;
+ component.setComponentInstances(instances);
// default test
- result = ComponentValidations.validateComponentInstanceExist(component, instanceId);
+ boolean result = ComponentValidations.validateComponentInstanceExist(component, instanceId);
+ assertTrue(result);
}
@Test
public void testGetNormalizedName() throws Exception {
+ String name = "mock";
ToscaDataDefinition toscaDataDefinition = new AdditionalInfoParameterDataDefinition();
- toscaDataDefinition.setToscaPresentationValue(JsonPresentationFields.NAME, "mock");
- String result;
+ toscaDataDefinition.setToscaPresentationValue(JsonPresentationFields.NAME, name);
// default test
- result = ComponentValidations.getNormalizedName(toscaDataDefinition);
+ String result = ComponentValidations.getNormalizedName(toscaDataDefinition);
+ assertEquals(name, result);
}
@Test
public void testValidateNameIsUniqueInComponent() throws Exception {
- String currentName = "";
- String newName = "";
+ String currentName = "curr_name";
+ String newName = "curr_name";
String newName2 = "mock";
+
+ ComponentInstance instance = new ComponentInstance();
+ instance.setName(currentName);
+ instance.setNormalizedName(currentName);
+ List<ComponentInstance> instances = new ArrayList<>();
+ instances.add(instance);
+
Component component = new Resource();
- boolean result;
+ component.setComponentInstances(instances);
// default test
- result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName, component);
+ boolean result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName, component);
+ assertTrue(result);
result = ComponentValidations.validateNameIsUniqueInComponent(currentName, newName2, component);
+ assertTrue(result);
}
@Test(expected=ComponentException.class)
@@ -117,6 +141,7 @@ public class ComponentValidationsTest {
// default test
result = Deencapsulation.invoke(testSubject, "getComponent", componentId, ComponentTypeEnum.RESOURCE);
+ assertThat(result).isInstanceOf(Component.class);
}
@Test(expected = StorageException.class)
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java
index ce5a3871a5..37fb99afd5 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java
@@ -70,17 +70,13 @@ public class UserValidationsTest {
usr.setStatus(UserStatusEnum.ACTIVE);
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenReturn(usr);
// default test
- testSubject.validateUserExists(userId);
+ User result = testSubject.validateUserExists(userId);
+ assertThat(result).isNotNull().isEqualTo(usr);
}
@Test
public void testValidateNonExistingUser2() {
String userId = "mock";
- String ecompErrorContext = "mock";
- boolean inTransaction = false;
- User result;
-
-
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
Throwable thrown = catchThrowable(() -> testSubject.validateUserExists(userId) );
@@ -93,37 +89,36 @@ public class UserValidationsTest {
User user = new User();
List<Role> roles = new LinkedList<>();
roles.add(Role.DESIGNER);
-
user.setRole(Role.DESIGNER.name());
// test 1
- testSubject.validateUserRole(user, roles);
+ Throwable thrown = catchThrowable(() -> testSubject.validateUserRole(user, roles));
+ assertThat(thrown).isNull();
}
@Test
public void testValidateUserExistsActionStatus() {
String userId = "mock";
- String ecompErrorContext = "mock";
ActionStatus result;
User usr = new User();
+ usr.setUserId(userId);
+ usr.setStatus(UserStatusEnum.ACTIVE);
- Mockito.when(userAdmin.getUser(Mockito.anyString())).thenReturn(usr);
+ Mockito.when(userAdmin.hasActiveUser(Mockito.anyString())).thenReturn(true);
// default test
result = testSubject.validateUserExistsActionStatus(userId);
+ assertThat(result).isEqualTo(ActionStatus.OK);
}
@Test
public void testValidateUserExistsActionStatus2() {
String userId = "mock";
- String ecompErrorContext = "mock";
- ActionStatus result;
- User usr = new User();
-
- Mockito.when(userAdmin.getUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException((ActionStatus.USER_NOT_FOUND)));
+ Mockito.when(userAdmin.hasActiveUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException((ActionStatus.USER_NOT_FOUND)));
// default test
- result = testSubject.validateUserExistsActionStatus(userId);
+ Throwable thrown = catchThrowable(() -> testSubject.validateUserExistsActionStatus(userId));
+ assertThat(thrown).isInstanceOf(ComponentException.class).hasFieldOrPropertyWithValue("actionStatus" , ActionStatus.USER_NOT_FOUND);
}
@Test
@@ -135,12 +130,12 @@ public class UserValidationsTest {
// default test
result = testSubject.validateUserNotEmpty(user, ecompErrorContext);
+ assertThat(result).isEqualTo(user);
}
@Test
public void testValidateNonExistingUser() {
String userId = "";
- String ecompErrorContext = "";
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));