summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java
diff options
context:
space:
mode:
authorxuegao <xue.gao@intl.att.com>2021-03-22 11:22:47 +0100
committerxuegao <xue.gao@intl.att.com>2021-03-24 08:25:00 +0100
commit134ca5667da901a703ecb0c78d96873712a9d0d3 (patch)
tree38738cddb2798a54d1f81c22d005b9ff1e0c79f0 /catalog-be/src/test/java
parenteb57d1efc197968a4073b331b2dc8f40d8109847 (diff)
Improve test coverage
Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I9e00af2824366ae45d47d2dcecf322fd3e9a6fea Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'catalog-be/src/test/java')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditAuthRequestEventFactoryTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribDownloadEventFactoryTest.java35
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribStatusEventFactoryTest.java5
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditGetUebClusterEventFactoryTest.java28
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/UserValidationsTest.java77
5 files changed, 84 insertions, 66 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditAuthRequestEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditAuthRequestEventFactoryTest.java
index d0c919d1d2..d5aaf7e70f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditAuthRequestEventFactoryTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditAuthRequestEventFactoryTest.java
@@ -20,7 +20,8 @@
package org.openecomp.sdc.be.auditing.impl;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder;
@@ -30,7 +31,7 @@ public class AuditAuthRequestEventFactoryTest {
private AuditAuthRequestEventFactory createTestSubject() {
Builder newBuilder = CommonAuditData.newBuilder();
CommonAuditData build = newBuilder.build();
- return new AuditAuthRequestEventFactory(build, "mock", "mock", "mock", "mock");
+ return new AuditAuthRequestEventFactory(build, "mock", "mock", "mock", "mock", "");
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribDownloadEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribDownloadEventFactoryTest.java
index 8fffe1fb2c..629d0cd237 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribDownloadEventFactoryTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribDownloadEventFactoryTest.java
@@ -20,38 +20,37 @@
package org.openecomp.sdc.be.auditing.impl.distribution;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
+import org.openecomp.sdc.be.resources.data.auditing.DistributionDeployEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
-public class AuditDistribDownloadEventFactoryTest {
+import static org.junit.jupiter.api.Assertions.assertEquals;
- private AuditDistributionDeployEventFactory createTestSubject() {
- Builder newBuilder = CommonAuditData.newBuilder();
- CommonAuditData build = newBuilder.build();
- return new AuditDistributionDeployEventFactory(build,new ResourceCommonInfo(),"",new User(),"1.0");
- }
+public class AuditDistribDownloadEventFactoryTest {
@Test
public void testGetLogMessage() throws Exception {
- AuditDistributionDeployEventFactory testSubject;
- String result;
+ Builder newBuilder = CommonAuditData.newBuilder();
+ CommonAuditData build = newBuilder.build();
+ AuditDistributionDeployEventFactory testSubject = new AuditDistributionDeployEventFactory(build,new ResourceCommonInfo(),"",new User(),"1.0");
+ String expected = "ACTION = \"DResult\" RESOURCE_NAME = \"\" RESOURCE_TYPE = \"\" SERVICE_INSTANCE_ID = \"\" CURR_VERSION = \"1.0\" MODIFIER = \"\" DID = \"\" STATUS = \"\" DESC = \"\"";
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLogMessage();
+ assertEquals(expected, testSubject.getLogMessage());
}
@Test
public void testGetDbEvent() throws Exception {
- AuditDistributionDeployEventFactory testSubject;
- AuditingGenericEvent result;
+ Builder newBuilder = CommonAuditData.newBuilder();
+ CommonAuditData build = newBuilder.build();
+ AuditDistributionDeployEventFactory testSubject = new AuditDistributionDeployEventFactory(build,new ResourceCommonInfo(),"","user","1.0", "");
+ DistributionDeployEvent result = (DistributionDeployEvent)testSubject.getDbEvent();
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDbEvent();
+ assertEquals("DResult", result.getAction());
+ assertEquals("1.0", result.getCurrVersion());
+ assertEquals("", result.getDid());
+ assertEquals("user", result.getModifier());
}
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribStatusEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribStatusEventFactoryTest.java
index 8d3ec84ba9..4c13901b2d 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribStatusEventFactoryTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditDistribStatusEventFactoryTest.java
@@ -20,7 +20,8 @@
package org.openecomp.sdc.be.auditing.impl.distribution;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder;
@@ -31,7 +32,7 @@ public class AuditDistribStatusEventFactoryTest {
private AuditDistributionStatusEventFactory createTestSubject() {
Builder newBuilder = CommonAuditData.newBuilder();
CommonAuditData build = newBuilder.build();
- return new AuditDistributionStatusEventFactory(build,new DistributionData("",""), "", "", "");
+ return new AuditDistributionStatusEventFactory(build,new DistributionData("",""), "", "", "", "");
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditGetUebClusterEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditGetUebClusterEventFactoryTest.java
index 5f2e8c2f3d..7d7c78101e 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditGetUebClusterEventFactoryTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/distribution/AuditGetUebClusterEventFactoryTest.java
@@ -20,37 +20,37 @@
package org.openecomp.sdc.be.auditing.impl.distribution;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class AuditGetUebClusterEventFactoryTest {
private AuditGetUebClusterEventFactory createTestSubject() {
Builder newBuilder = CommonAuditData.newBuilder();
CommonAuditData build = newBuilder.build();
- return new AuditGetUebClusterEventFactory(build, "");
+ return new AuditGetUebClusterEventFactory(build, "", "");
}
@Test
public void testGetLogMessage() throws Exception {
- AuditGetUebClusterEventFactory testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getLogMessage();
+ AuditGetUebClusterEventFactory testSubject = createTestSubject();
+ String expected1 = "ACTION = \"GetUebCluster\" CONSUMER_ID = \"\" STATUS_TIME =";
+ String expected2 = "STATUS = \"\" STATUS_DESC = \"\"";
+ String actual = testSubject.getLogMessage();
+ assertTrue(actual.contains(expected1));
+ assertTrue(actual.contains(expected2));
}
@Test
public void testGetDbEvent() throws Exception {
- AuditGetUebClusterEventFactory testSubject;
- AuditingGenericEvent result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getDbEvent();
+ AuditGetUebClusterEventFactory testSubject = createTestSubject();
+ AuditingGenericEvent result = testSubject.getDbEvent();
+ assertEquals("GetUebCluster", result.getAction());
}
}
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 37fb99afd5..6c08fcb357 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
@@ -20,8 +20,8 @@
package org.openecomp.sdc.be.components.validation;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -31,7 +31,6 @@ import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
-import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
@@ -41,8 +40,7 @@ import java.util.List;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.catchThrowable;
+import static org.junit.jupiter.api.Assertions.*;
public class UserValidationsTest {
@@ -52,10 +50,7 @@ public class UserValidationsTest {
@Mock
UserBusinessLogic userAdmin;
- @Mock
- ComponentsUtils componentsUtils;
-
- @Before
+ @BeforeEach
public void setUp() {
//TestUtilsSdc.setFinalStatic(UserValidations.class, "log", LoggerFactory.getLogger(UserValidations.class));
MockitoAnnotations.initMocks(this);
@@ -67,33 +62,44 @@ public class UserValidationsTest {
String userId = "mock";
User usr = new User();
usr.setUserId(userId);
- usr.setStatus(UserStatusEnum.ACTIVE);
+ usr.setStatus(UserStatusEnum.INACTIVE);
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenReturn(usr);
+
+ assertThrows(ByActionStatusComponentException.class, () -> {
+ testSubject.validateUserExists(userId);
+ });
+ Mockito.verify(userAdmin, Mockito.times(1)).getUser(Mockito.anyString());
+
// default test
+ usr.setStatus(UserStatusEnum.ACTIVE);
User result = testSubject.validateUserExists(userId);
- assertThat(result).isNotNull().isEqualTo(usr);
+ assertNotNull(result);
+ assertEquals(usr, result);
}
-
+
@Test
public void testValidateNonExistingUser2() {
String userId = "mock";
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
- Throwable thrown = catchThrowable(() -> testSubject.validateUserExists(userId) );
- assertThat(thrown).isInstanceOf(ComponentException.class).hasFieldOrPropertyWithValue("actionStatus" , ActionStatus.USER_NOT_FOUND);
-
+ assertThrows(ComponentException.class, () -> {
+ testSubject.validateUserExists(userId);
+ });
+ Mockito.verify(userAdmin, Mockito.times(1)).getUser(Mockito.anyString());
}
@Test
public void testValidateUserRole() {
User user = new User();
List<Role> roles = new LinkedList<>();
- roles.add(Role.DESIGNER);
user.setRole(Role.DESIGNER.name());
- // test 1
- Throwable thrown = catchThrowable(() -> testSubject.validateUserRole(user, roles));
- assertThat(thrown).isNull();
+ assertThrows(ByActionStatusComponentException.class, () -> {
+ testSubject.validateUserRole(user, roles);
+ });
+
+ roles.add(Role.DESIGNER);
+ assertDoesNotThrow(() -> testSubject.validateUserRole(user, roles));
}
@Test
@@ -103,12 +109,14 @@ public class UserValidationsTest {
User usr = new User();
usr.setUserId(userId);
usr.setStatus(UserStatusEnum.ACTIVE);
-
+
+ Mockito.when(userAdmin.hasActiveUser(Mockito.anyString())).thenReturn(false);
+ assertEquals(ActionStatus.RESTRICTED_OPERATION, testSubject.validateUserExistsActionStatus(userId));
+ Mockito.verify(userAdmin, Mockito.times(1)).hasActiveUser(Mockito.anyString());
+
Mockito.when(userAdmin.hasActiveUser(Mockito.anyString())).thenReturn(true);
-
- // default test
- result = testSubject.validateUserExistsActionStatus(userId);
- assertThat(result).isEqualTo(ActionStatus.OK);
+ assertEquals(ActionStatus.OK, testSubject.validateUserExistsActionStatus(userId));
+ Mockito.verify(userAdmin, Mockito.times(2)).hasActiveUser(Mockito.anyString());
}
@Test
@@ -117,20 +125,27 @@ public class UserValidationsTest {
Mockito.when(userAdmin.hasActiveUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException((ActionStatus.USER_NOT_FOUND)));
// default test
- Throwable thrown = catchThrowable(() -> testSubject.validateUserExistsActionStatus(userId));
- assertThat(thrown).isInstanceOf(ComponentException.class).hasFieldOrPropertyWithValue("actionStatus" , ActionStatus.USER_NOT_FOUND);
+ assertThrows(ComponentException.class, () -> {
+ testSubject.validateUserExistsActionStatus(userId);
+ });
+ Mockito.verify(userAdmin, Mockito.times(1)).hasActiveUser(Mockito.anyString());
}
@Test
public void testValidateUserNotEmpty() {
User user = new User();
- user.setUserId("userId");
+ user.setUserId("");
String ecompErrorContext = "mock";
User result;
// default test
+ assertThrows(ByActionStatusComponentException.class, () -> {
+ testSubject.validateUserNotEmpty(user, ecompErrorContext);
+ });
+
+ user.setUserId("userId");
result = testSubject.validateUserNotEmpty(user, ecompErrorContext);
- assertThat(result).isEqualTo(user);
+ assertEquals(user, result);
}
@Test
@@ -140,7 +155,9 @@ public class UserValidationsTest {
Mockito.when(userAdmin.getUser(Mockito.anyString())).thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
// default test
- Throwable thrown = catchThrowable(() -> testSubject.validateUserExists(userId) );
- assertThat(thrown).isInstanceOf(ComponentException.class).hasFieldOrPropertyWithValue("actionStatus" , ActionStatus.USER_NOT_FOUND);
+ assertThrows(ComponentException.class, () -> {
+ testSubject.validateUserExists(userId);
+ });
+ Mockito.verify(userAdmin, Mockito.times(1)).getUser(Mockito.anyString());
}
}