summaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/task/MigrationResultTest.java43
-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
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java43
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java40
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java52
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java35
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java44
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/util/ThreadLocalsHolderTest.java53
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListCapabilityDataDefinitionTest.java27
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypesTest.java55
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java27
15 files changed, 369 insertions, 200 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/task/MigrationResultTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/task/MigrationResultTest.java
index 4ac5a9fdc6..75c974b2a9 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/task/MigrationResultTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/core/task/MigrationResultTest.java
@@ -20,9 +20,11 @@
package org.openecomp.sdc.asdctool.migration.core.task;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult.MigrationStatus;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class MigrationResultTest {
@@ -32,27 +34,13 @@ public class MigrationResultTest {
@Test
- public void testGetMsg() {
- MigrationResult testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMsg();
- }
-
-
- @Test
- public void testSetMsg() {
- MigrationResult testSubject;
- String msg = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setMsg(msg);
+ public void testMsg() {
+ MigrationResult testSubject = createTestSubject();
+ assertNull(testSubject.getMsg());
+ testSubject.setMsg("msg");
+ assertEquals("msg", testSubject.getMsg());
}
-
@Test
public void testGetMigrationStatus() {
MigrationResult testSubject;
@@ -63,7 +51,6 @@ public class MigrationResultTest {
result = testSubject.getMigrationStatus();
}
-
@Test
public void testSetMigrationStatus() {
MigrationResult testSubject;
@@ -73,4 +60,18 @@ public class MigrationResultTest {
testSubject = createTestSubject();
testSubject.setMigrationStatus(migrationStatus);
}
+
+ @Test
+ public void testSuccess() {
+ MigrationResult testSubject = createTestSubject();
+ assertEquals(MigrationResult.MigrationStatus.COMPLETED, testSubject.success().getMigrationStatus());
+ }
+
+ @Test
+ public void testError() {
+ MigrationResult testSubject = createTestSubject();
+ MigrationResult result = testSubject.error("testErr");
+ assertEquals(MigrationStatus.FAILED, result.getMigrationStatus());
+ assertEquals("testErr", result.getMsg());
+ }
}
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());
}
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
index b58949d4c2..6b3b766afa 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/MapConverterTest.java
@@ -22,42 +22,37 @@ package org.openecomp.sdc.be.model.tosca.converters;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class MapConverterTest {
- private MapConverter createTestSubject() {
- return new MapConverter();
- }
-
-
@Test
public void testGetInstance() throws Exception {
- MapConverter result;
-
- // default test
- result = MapConverter.getInstance();
+ assertNotNull(MapConverter.getInstance());
}
@Test
public void testConvert() throws Exception {
- MapConverter testSubject;
- String value = "";
- String innerType = "";
+ MapConverter testSubject = new MapConverter();
Map<String, DataTypeDefinition> dataTypes = null;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.convert(value, innerType, dataTypes);
+ assertTrue(testSubject.convert("", null, dataTypes).isEmpty());
+ assertTrue(testSubject.convert("", "string", dataTypes).isEmpty());
+ assertNull(testSubject.convert("{\"key\":}", "integer", dataTypes));
+
+ assertEquals("{\"key\":\"value\"}", testSubject.convert("{\"key\":\"value\"}", "list", dataTypes));
+ assertEquals("{\"key\":\"value\"}", testSubject.convert("{\"key\":\"value\"}", "string", dataTypes));
+ assertEquals("{\"key\":2}", testSubject.convert("{\"key\":2}", "integer", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "integer", dataTypes));
+ assertEquals("{\"key\":0.2}", testSubject.convert("{\"key\":0.2}", "float", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "float", dataTypes));
+ assertEquals("{\"key\":true}", testSubject.convert("{\"key\":true}", "boolean", dataTypes));
+ assertEquals("{\"key\":null}", testSubject.convert("{\"key\":null}", "boolean", dataTypes));
}
-
-
-
-
-
-
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java
new file mode 100644
index 0000000000..1a07314b8d
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/KeyValidatorTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 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.openecomp.sdc.be.model.tosca.validators;
+
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class KeyValidatorTest {
+
+ @Test
+ public void isValidTest() {
+ assertFalse(KeyValidator.getInstance().isValid(null, "string"));
+
+ String veryLongString = "veryverylonglonglonglonglonglongstringveryverylonglonglonglonglonglongstringveryverylonglonglonglonglonglongstring";
+ assertFalse(KeyValidator.getInstance().isValid(veryLongString, "string"));
+
+ assertTrue(KeyValidator.getInstance().isValid("test", "string"));
+ }
+}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java
new file mode 100644
index 0000000000..528ac7a7c9
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/validators/ListValidatorTest.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 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.openecomp.sdc.be.model.tosca.validators;
+
+
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ListValidatorTest {
+
+ @Test
+ public void isValidTest() {
+ Map<String, DataTypeDefinition> map = new HashMap();
+ ListValidator validator = new ListValidator();
+ assertTrue(validator.isValid("", "", map));
+ assertFalse(validator.isValid("test", null, map));
+
+ assertTrue(validator.isValid("[2,3]", "integer", map));
+ assertTrue(validator.isValid("[0.2]", "float", map));
+ assertTrue(validator.isValid("[true]", "boolean", map));
+ assertTrue(validator.isValid("[test]", "string", map));
+ assertTrue(validator.isValid("[{\"key\":1};{\"key2\":2}]", "json", map));
+
+ assertFalse(validator.isValid("[[1,2],[3]]", "list", map));
+ assertFalse(validator.isValid("[2,true]", "integer", map));
+ assertFalse(validator.isValid("test", "wrong", map));
+ }
+}
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
index 1f6c070094..c318a3b514 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
@@ -21,9 +21,11 @@
package org.openecomp.sdc.common.http.config;
import fj.data.Either;
+import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.security.SecurityUtil;
+@EqualsAndHashCode
public class ClientCertificate {
private String keyStore;
private String keyStorePassword;
@@ -68,39 +70,6 @@ public class ClientCertificate {
public String getKeyStorePassword() {
return keyStorePassword;
}
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((keyStore == null) ? 0 : keyStore.hashCode());
- result = prime * result + ((keyStorePassword == null) ? 0 : keyStorePassword.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ClientCertificate other = (ClientCertificate) obj;
- if (keyStore == null) {
- if (other.keyStore != null)
- return false;
- }
- else if (!keyStore.equals(other.keyStore))
- return false;
- if (keyStorePassword == null) {
- if (other.keyStorePassword != null)
- return false;
- }
- else if (!keyStorePassword.equals(other.keyStorePassword))
- return false;
- return true;
- }
@Override
public String toString() {
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java
index b5036060eb..837be1d0ca 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java
@@ -23,17 +23,22 @@ package org.openecomp.sdc.common.util;
import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
public class GeneralUtilityTest {
@@ -56,14 +61,12 @@ public class GeneralUtilityTest {
@Test
public void validateIsBase64EncodedReturnsProperResponseFromByteArray() {
-
final String testString = "testDataToEncode";
final byte[] testBytes = testString.getBytes();
final byte[] testEncodedBytes = Base64.getEncoder().encode(testBytes);
- boolean result = GeneralUtility.isBase64Encoded(testEncodedBytes);
-
- assertTrue(result);
+ assertTrue(GeneralUtility.isBase64Encoded(testEncodedBytes));
+ assertTrue(GeneralUtility.isBase64Encoded(testString));
}
@Test
@@ -191,7 +194,7 @@ public class GeneralUtilityTest {
final String encodedString =
org.apache.commons.codec.digest.DigestUtils.md5Hex(testStringToEncode.getBytes());
- assertArrayEquals(encodedString.getBytes(), Base64.getDecoder().decode(result));
+ assertEquals(encodedString, new String(Base64.getDecoder().decode(result)));
}
@Test
@@ -204,7 +207,7 @@ public class GeneralUtilityTest {
final String encodedString =
org.apache.commons.codec.digest.DigestUtils.md5Hex(testStringToEncode.getBytes());
- assertArrayEquals(encodedString.getBytes(), Base64.getDecoder().decode(result));
+ assertEquals(encodedString, new String(Base64.getDecoder().decode(result)));
}
@Test
@@ -243,8 +246,25 @@ public class GeneralUtilityTest {
final String empty = " \ttest ";
boolean result = GeneralUtility.isEmptyString(empty);
-
+ assertTrue(GeneralUtility.isEmptyString(null));
assertFalse(result);
}
+ @Test
+ public void getCategorizedComponentsTest() {
+
+ List<ICategorizedElement> components = new LinkedList<>();
+ ICategorizedElement componentService = Mockito.mock(ICategorizedElement.class);
+ when(componentService.getComponentTypeAsString()).thenReturn("SERVICE");
+
+ ICategorizedElement componentResource = Mockito.mock(ICategorizedElement.class);
+ when(componentResource.getComponentTypeAsString()).thenReturn("RESOURCE");
+
+ components.add(componentService);
+ components.add(componentResource);
+ Map<String, Map<String, List<ICategorizedElement>>> result = GeneralUtility.getCategorizedComponents(components);
+ verify(componentService, Mockito.times(1)).getComponentTypeAsString();
+ verify(componentResource, Mockito.times(2)).getComponentTypeAsString();
+ assertEquals(2, result.size());
+ }
}
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ThreadLocalsHolderTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ThreadLocalsHolderTest.java
index c8b2920f81..223b027c96 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/ThreadLocalsHolderTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/ThreadLocalsHolderTest.java
@@ -20,10 +20,16 @@
package org.openecomp.sdc.common.util;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.common.api.FilterDecisionEnum;
+import org.openecomp.sdc.common.datastructure.UserContext;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import java.util.HashSet;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class ThreadLocalsHolderTest {
@@ -76,4 +82,45 @@ public class ThreadLocalsHolderTest {
assertNull(ThreadLocalsHolder.getUuid());
assertEquals(ThreadLocalsHolder.isMdcProcessed(), false);
}
+
+ @Test
+ public void validateUserContext() {
+ UserContext userContext = new UserContext("userId", new HashSet<>(), "firstName", "lastName");
+
+ ThreadLocalsHolder.setUserContext(userContext);
+ assertEquals("userId", ThreadLocalsHolder.getUserContext().getUserId());
+ assertEquals("firstName", ThreadLocalsHolder.getUserContext().getFirstName());
+ assertEquals("lastName", ThreadLocalsHolder.getUserContext().getLastName());
+ assertEquals(0, ThreadLocalsHolder.getUserContext().getUserRoles().size());
+ }
+
+ @Test
+ public void validateApiType() {
+ FilterDecisionEnum filterDecision = FilterDecisionEnum.INTERNAL;
+
+ ThreadLocalsHolder.setApiType(filterDecision);
+ assertEquals(filterDecision, ThreadLocalsHolder.getApiType());
+ }
+
+ @Test
+ public void isInternalRequestTest() {
+ FilterDecisionEnum filterDecision = FilterDecisionEnum.INTERNAL;
+ ThreadLocalsHolder.setApiType(filterDecision);
+ assertTrue(ThreadLocalsHolder.isInternalRequest());
+
+ filterDecision = FilterDecisionEnum.EXTERNAL;
+ ThreadLocalsHolder.setApiType(filterDecision);
+ assertFalse(ThreadLocalsHolder.isInternalRequest());
+ }
+
+ @Test
+ public void isExternalRequestTest() {
+ FilterDecisionEnum filterDecision = FilterDecisionEnum.INTERNAL;
+ ThreadLocalsHolder.setApiType(filterDecision);
+ assertFalse(ThreadLocalsHolder.isExternalRequest());
+
+ filterDecision = FilterDecisionEnum.EXTERNAL;
+ ThreadLocalsHolder.setApiType(filterDecision);
+ assertTrue(ThreadLocalsHolder.isExternalRequest());
+ }
}
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListCapabilityDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListCapabilityDataDefinitionTest.java
index 74adfffc15..60bcce50cd 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListCapabilityDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListCapabilityDataDefinitionTest.java
@@ -21,10 +21,11 @@
package org.openecomp.sdc.be.datatypes.elements;
import org.apache.commons.collections.map.HashedMap;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class MapListCapabilityDataDefinitionTest {
@@ -43,24 +44,12 @@ public class MapListCapabilityDataDefinitionTest {
}
@Test
- public void testGetMapToscaDataDefinition() throws Exception {
- MapListCapabilityDataDefinition testSubject;
- Map<String, ListCapabilityDataDefinition> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMapToscaDataDefinition();
- }
-
-
- @Test
public void testAdd() throws Exception {
- MapListCapabilityDataDefinition testSubject;
- String key = "";
- CapabilityDataDefinition value = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.add(key, value);
+ MapListCapabilityDataDefinition testSubject = createTestSubject();
+ testSubject.add("", null);
+ testSubject.add("key2", null);
+ testSubject.add("key2", new CapabilityDataDefinition());
+ assertEquals(2, testSubject.getMapToscaDataDefinition().size());
+ assertEquals(2, testSubject.getMapToscaDataDefinition().get("key2").getListToscaDataDefinition().size());
}
}
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypesTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypesTest.java
new file mode 100644
index 0000000000..0c9ce0ca2a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypesTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2021 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.openecomp.sdc.heat.datatypes;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.LinkedList;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DefinedHeatParameterTypesTest {
+
+ @Test
+ public void testIsValueIsFromGivenType() {
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType(2, "number"));
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType("2 KB", "number"));
+
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType(true, "boolean"));
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType("test", "string"));
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType(new LinkedList<>(), "json"));
+
+ assertTrue(DefinedHeatParameterTypes.isValueIsFromGivenType("val1,val2", "comma_delimited_list"));
+ assertFalse(DefinedHeatParameterTypes.isValueIsFromGivenType("", "wrong"));
+ }
+
+ @Test
+ public void testIsNovaServerEnvValueIsFromRightType() {
+ assertTrue(DefinedHeatParameterTypes.isNovaServerEnvValueIsFromRightType("test"));
+ assertTrue(DefinedHeatParameterTypes.isNovaServerEnvValueIsFromRightType("val1,val2"));
+ }
+
+ @Test
+ public void testIsEmptyValueInEnv() {
+ assertTrue(DefinedHeatParameterTypes.isEmptyValueInEnv(null));
+ assertFalse(DefinedHeatParameterTypes.isEmptyValueInEnv(""));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
index 95963b504f..90672f6eaf 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
@@ -15,6 +15,9 @@
*/
package org.openecomp.sdc.logging.servlet;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -30,6 +33,8 @@ import java.util.function.Function;
* @author evitaliy
* @since 25 Mar 2018
*/
+@EqualsAndHashCode
+@ToString
public class HttpHeader {
private static final String NAMES_CANNOT_BE_NULL = "Names cannot be null";
@@ -75,26 +80,4 @@ public class HttpHeader {
}
return Optional.empty();
}
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- HttpHeader that = (HttpHeader) o;
- return Objects.equals(headerNames, that.headerNames);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(headerNames);
- }
-
- @Override
- public String toString() {
- return "HttpHeader{headerNames=" + headerNames + '}';
- }
}