summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authorxuegao <xue.gao@intl.att.com>2021-03-19 14:04:17 +0100
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 07:00:09 +0000
commitb2c0528da052b5c73e3fc1f7f98d22578acd91f0 (patch)
tree12a64e553c7c6c321b4a8ec83880777f1c485f5e /openecomp-be/lib
parentd378c37fbd1ecec7b43394926f1ca32a695e07de (diff)
Improve test coverage
Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I29a8f1d49f1dfd6bca79f3d873d1e1ff7adc4fb2 Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/test/java/org/openecomp/types/AsdcElementTest.java66
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypesTest.java64
-rw-r--r--openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/test/java/org/openecomp/sdc/destinationprovider/impl/MulticastDestinationTest.java28
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java43
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertorTest.java9
5 files changed, 177 insertions, 33 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/test/java/org/openecomp/types/AsdcElementTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/test/java/org/openecomp/types/AsdcElementTest.java
index 3197767379..74ec1a6859 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/test/java/org/openecomp/types/AsdcElementTest.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/test/java/org/openecomp/types/AsdcElementTest.java
@@ -19,10 +19,25 @@
*/
package org.openecomp.types;
-import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
-import static org.junit.Assert.assertThat;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.item.Action;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.Relation;
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.HashMap;
-import org.junit.Test;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSettersExcluding;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class AsdcElementTest {
@Test
@@ -30,4 +45,49 @@ public class AsdcElementTest {
assertThat(AsdcElement.class,
hasValidGettersAndSettersExcluding("data", "info", "searchableData", "visualization"));
}
+
+ @Test
+ public void getInfoTest() {
+ AsdcElement element = new AsdcElement();
+ element.setName("name");
+ element.setType("type");
+ element.setProperties(new HashMap<>());
+ element.setDescription("desc");
+
+ Info actualInfo = element.getInfo();
+ assertEquals("name", actualInfo.getName());
+ assertEquals(1, actualInfo.getProperties().size());
+ assertEquals("type", actualInfo.getProperty("elementType"));
+ assertEquals("desc", actualInfo.getDescription());
+ }
+
+ @Test
+ public void getSearchableDataTest() {
+ AsdcElement element = new AsdcElement();
+ assertNull(element.getSearchableData());
+ }
+
+ @Test
+ public void getVisualizationTest() {
+ AsdcElement element = new AsdcElement();
+ assertNull(element.getVisualization());
+ }
+
+ @Test
+ public void dataTest() throws IOException {
+ AsdcElement element = new AsdcElement();
+ InputStream inputStream = new ByteArrayInputStream( "testString".getBytes(StandardCharsets.UTF_8) );
+ element.setData(inputStream);
+
+ assertEquals("testString", IOUtils.toString(element.getData(), StandardCharsets.UTF_8));
+ }
+
+ @Test
+ public void addSubElementTest() throws IOException {
+ AsdcElement element = new AsdcElement();
+ assertEquals(0, element.getSubElements().size());
+
+ element.addSubElement(new AsdcElement());
+ assertEquals(1, element.getSubElements().size());
+ }
} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypesTest.java b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypesTest.java
new file mode 100644
index 0000000000..1298681b70
--- /dev/null
+++ b/openecomp-be/lib/openecomp-heat-lib/src/test/java/org/openecomp/sdc/heat/datatypes/model/HeatResourcesTypesTest.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.heat.datatypes.model;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+import java.util.List;
+import java.util.Map;
+
+public class HeatResourcesTypesTest {
+
+ @Test
+ public void findByHeatResourceTest() {
+ assertEquals(HeatResourcesTypes.NOVA_SERVER_GROUP_RESOURCE_TYPE,
+ HeatResourcesTypes.findByHeatResource("OS::Nova::ServerGroup"));
+ }
+
+ @Test
+ public void isResourceExpectedToBeExposedTest() {
+ assertEquals(true, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Nova::ServerGroup"));
+ assertEquals(true, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Contrail::VirtualNetwork"));
+ assertEquals(true, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Neutron::Net"));
+ assertEquals(true, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Cinder::Volume"));
+ assertEquals(true, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Neutron::SecurityGroup"));
+ assertEquals(false, HeatResourcesTypes.isResourceExpectedToBeExposed("OS::Nova::Server"));
+ }
+
+ @Test
+ public void isResourceTypeValidTest() {
+ assertEquals(true, HeatResourcesTypes.isResourceTypeValid("OS::Neutron::SecurityGroup"));
+ assertEquals(false, HeatResourcesTypes.isResourceTypeValid("OS::Neutron::test"));
+ }
+
+ @Test
+ public void getListForResourceTypeTest() {
+ Map<HeatResourcesTypes, List<String>> res = HeatResourcesTypes.getListForResourceType(
+ HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE, HeatResourcesTypes.HEAT_CLOUD_CONFIG_TYPE);
+
+ assertNotNull(res.get(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE));
+ assertNotNull(res.get(HeatResourcesTypes.HEAT_CLOUD_CONFIG_TYPE));
+ assertNull(res.get(HeatResourcesTypes.CONTRAIL_SERVICE_TEMPLATE));
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/test/java/org/openecomp/sdc/destinationprovider/impl/MulticastDestinationTest.java b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/test/java/org/openecomp/sdc/destinationprovider/impl/MulticastDestinationTest.java
index b739f32513..78265769e5 100644
--- a/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/test/java/org/openecomp/sdc/destinationprovider/impl/MulticastDestinationTest.java
+++ b/openecomp-be/lib/openecomp-sdc-notification-lib/openecomp-sdc-notification-core/src/test/java/org/openecomp/sdc/destinationprovider/impl/MulticastDestinationTest.java
@@ -20,10 +20,10 @@
package org.openecomp.sdc.destinationprovider.impl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.openecomp.sdc.notification.services.SubscriptionService;
import java.util.Arrays;
@@ -31,7 +31,10 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import static org.junit.Assert.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
@@ -39,6 +42,7 @@ import static org.mockito.Mockito.doReturn;
* @author avrahamg
* @since July 13, 2017
*/
+@ExtendWith(MockitoExtension.class)
public class MulticastDestinationTest {
@Mock
private SubscriptionService subscriptionServiceMock;
@@ -47,10 +51,6 @@ public class MulticastDestinationTest {
private Set<String> subscribers = new HashSet<>(Arrays.asList("a", "b", excludedSubscriber));
private MulticastDestination multicastDestination;
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- }
@Test
public void shouldReturnAllSubscribersIfNoExcludedProvided() throws Exception {
@@ -72,13 +72,11 @@ public class MulticastDestinationTest {
assertFalse(actualSubscribers.contains(excludedSubscriber));
}
- @Test(expected = UnsupportedOperationException.class)
- public void shouldThrowUnsupportedOperationExceptionWhenTryingToChangeSubscribersList() throws
- Exception {
- doReturn(subscribers).when(subscriptionServiceMock).getSubscribers(any());
+ @Test
+ public void entityIdTest() {
multicastDestination =
- new MulticastDestination("aa", subscriptionServiceMock, excludedSubscriber);
- List<String> actualSubscribers = multicastDestination.getSubscribers();
- actualSubscribers.add("sss");
+ new MulticastDestination("aa", subscriptionServiceMock, excludedSubscriber);
+ multicastDestination.setEntityId("entityId");
+ assertEquals("entityId", multicastDestination.getEntityId());
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java
index 8f17f0f357..3541465736 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-api/src/test/java/org/openecomp/core/validation/types/GlobalValidationContextTest.java
@@ -18,12 +18,13 @@ package org.openecomp.core.validation.types;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
-import org.junit.Assert;
-import org.junit.Test;
+
+import org.junit.jupiter.api.Test;
import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -31,6 +32,10 @@ import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class GlobalValidationContextTest {
private static String filename = "testName";
private static String yaml1 = "one.yaml";
@@ -45,7 +50,7 @@ public class GlobalValidationContextTest {
ErrorMessageCode error = new ErrorMessageCode("Error");
globalValidationContext.setMessageCode(error);
- Assert.assertEquals(error, globalValidationContext.getMessageCode());
+ assertEquals(error, globalValidationContext.getMessageCode());
}
@Test
@@ -54,8 +59,8 @@ public class GlobalValidationContextTest {
globalValidationContext.addFileContext(filename, content.getBytes());
Map<String, FileValidationContext> fileContextMap = globalValidationContext.getFileContextMap();
- Assert.assertTrue(MapUtils.isNotEmpty(fileContextMap));
- Assert.assertTrue(fileContextMap.containsKey(filename));
+ assertTrue(MapUtils.isNotEmpty(fileContextMap));
+ assertTrue(fileContextMap.containsKey(filename));
}
@Test
@@ -82,6 +87,18 @@ public class GlobalValidationContextTest {
}
@Test
+ public void testGetFileContent() {
+ GlobalValidationContext globalValidationContext = new GlobalValidationContext();
+
+ assertTrue(globalValidationContext.getFileContent(yaml1).isEmpty());
+
+ byte[] bytes = content.getBytes();
+ globalValidationContext.addFileContext(yaml1, bytes);
+
+ assertTrue(globalValidationContext.getFileContent(yaml1).get() instanceof InputStream);
+ }
+
+ @Test
public void testGetFiles() {
GlobalValidationContext globalValidationContext = new GlobalValidationContext();
byte[] bytes = content.getBytes();
@@ -94,7 +111,7 @@ public class GlobalValidationContextTest {
testGetFilesByFileType((fileName, globalContext) -> fileName.endsWith(".txt"),
1, Collections.singletonList(text1), globalValidationContext);
-
+ assertEquals(3, globalValidationContext.getFiles().size());
}
private void testGetFilesByFileType(BiPredicate<String, GlobalValidationContext> func,
@@ -102,23 +119,23 @@ public class GlobalValidationContextTest {
List<String> expectedFileNames,
GlobalValidationContext globalValidationContext) {
Collection<String> files = globalValidationContext.files(func);
- Assert.assertTrue(CollectionUtils.isNotEmpty(files));
- Assert.assertEquals(files.size(), expectedFilesNumberToFind);
- expectedFileNames.forEach(filename -> Assert.assertTrue(files.contains(filename)));
+ assertTrue(CollectionUtils.isNotEmpty(files));
+ assertEquals(files.size(), expectedFilesNumberToFind);
+ expectedFileNames.forEach(filename -> assertTrue(files.contains(filename)));
}
private void testIfFileHasMessageContainer(Map<String, MessageContainer> messageContainers) {
- Assert.assertNotNull(messageContainers);
- Assert.assertTrue(messageContainers.containsKey(filename));
+ assertNotNull(messageContainers);
+ assertTrue(messageContainers.containsKey(filename));
}
private void testIfFileHasErrorMessage(Map<String, MessageContainer> messageContainers,
int expectedErrorsNumber) {
MessageContainer messageContainer = messageContainers.get(filename);
- Assert.assertEquals(messageContainer.getErrorMessageList().size(), expectedErrorsNumber);
+ assertEquals(messageContainer.getErrorMessageList().size(), expectedErrorsNumber);
ErrorMessage errorMessage =
new ErrorMessage(ErrorLevel.ERROR, ErrorLevel.ERROR.toString() + ": " + message);
- Assert.assertTrue(messageContainer.getErrorMessageList().contains(errorMessage));
+ assertTrue(messageContainer.getErrorMessageList().contains(errorMessage));
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertorTest.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertorTest.java
index 49624a5c55..d1be5ed9a8 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertorTest.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToFeatureGroupConvertorTest.java
@@ -17,6 +17,7 @@ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor;
import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
@@ -36,7 +37,9 @@ public class ElementToFeatureGroupConvertorTest {
@Test
public void shouldConvertElementToFeatureGroupEntity() {
- ZusammenElement elementToConvert = new ZusammenElement();
+ ZusammenElement elementToConvert = null;
+ assertNull(converter.convert(elementToConvert));
+ elementToConvert = new ZusammenElement();
elementToConvert.setElementId(new Id(ENTITY_ID));
elementToConvert.setInfo(createInfo());
FeatureGroupEntity result = converter.convert(elementToConvert);
@@ -47,7 +50,9 @@ public class ElementToFeatureGroupConvertorTest {
@Test
public void shouldConvertElementInfoToFeatureGroupEntity(){
- ElementInfo elementToConvert = new ElementInfo();
+ ElementInfo elementToConvert = null;
+ assertNull(converter.convert(elementToConvert));
+ elementToConvert = new ElementInfo();
elementToConvert.setId(new Id(ENTITY_ID));
elementToConvert.setInfo(createInfo());
FeatureGroupEntity result = converter.convert(elementToConvert);