summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm.kowalski3 <m.kowalski3@partner.samsung.com>2020-05-26 09:11:52 +0200
committerKrystian Kedron <k.kedron@partner.samsung.com>2020-06-16 07:21:05 +0000
commit3f0d480cbc49f2c5a811eac91c5c637775e038e1 (patch)
tree1d33c4f4e517c8349aa3b951f5e2b6aa4f4904ea
parent95bdca4419af09c4eeab5562589ea6baf9a4490d (diff)
Add unit tests for ZusammenElementUtil
Also improve tests for ZusammenAdaptorImplTest Issue-ID: SDC-2327 Signed-off-by: Marcin Kowalski <m.kowalski3@partner.samsung.com> Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: Id6c27fd5bb4a651a857cc5bdb55e310709cb4ed3
-rw-r--r--zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java43
-rw-r--r--zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenElementUtilTest.java55
2 files changed, 79 insertions, 19 deletions
diff --git a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java
index 4fc4b97..75df88e 100644
--- a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java
+++ b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java
@@ -16,16 +16,6 @@
package org.onap.sdc.common.zusammen.services.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
@@ -34,6 +24,7 @@ import com.amdocs.zusammen.datatypes.SessionContext;
import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.ElementContext;
import com.amdocs.zusammen.datatypes.item.Info;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -47,14 +38,27 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.sdc.common.zusammen.persistence.ZusammenConnector;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
public class ZusammenAdaptorImplTest {
private static final SessionContext CONTEXT = new SessionContext();
private static final ElementContext ELEMENT_CONTEXT = new ElementContext();
+
+ private static final String NOT_EXISTING_ELEMENT_NAME = "nonExistingName";
+ private static final String ELEMENT_NAME = "element2";
private static final Id ELEMENT_ID = new Id("elementId 0");
private static final List<ElementInfo> ELEMENTS =
- Arrays.asList(createElementInfo("elementId1", "element1"), createElementInfo("elementId2", "element2"),
- createElementInfo("elementId3", "element3"));
+ Arrays.asList(createElementInfo("elementId1", "element1"), createElementInfo("elementId2",
+ ELEMENT_NAME), createElementInfo("elementId3", "element3"));
private final ZusammenConnector connector = Mockito.mock(ZusammenConnector.class);
@InjectMocks
@@ -72,7 +76,7 @@ public class ZusammenAdaptorImplTest {
doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID);
Optional<Element> element =
- zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName");
+ zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, NOT_EXISTING_ELEMENT_NAME);
assertFalse(element.isPresent());
}
@@ -82,7 +86,7 @@ public class ZusammenAdaptorImplTest {
doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID);
Optional<ElementInfo> elementInfo =
- zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName");
+ zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, NOT_EXISTING_ELEMENT_NAME);
assertFalse(elementInfo.isPresent());
}
@@ -93,7 +97,8 @@ public class ZusammenAdaptorImplTest {
ZusammenElement returnedElement = new ZusammenElement();
doReturn(returnedElement).when(connector).getElement(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(1).getId());
- Optional<Element> element = zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2");
+ Optional<Element> element = zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID,
+ ELEMENT_NAME);
assertTrue(element.isPresent());
assertEquals(returnedElement, element.get());
@@ -104,7 +109,7 @@ public class ZusammenAdaptorImplTest {
doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID);
Optional<ElementInfo> elementInfo =
- zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2");
+ zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, ELEMENT_NAME);
assertTrue(elementInfo.isPresent());
assertEquals(ELEMENTS.get(1), elementInfo.get());
@@ -131,7 +136,7 @@ public class ZusammenAdaptorImplTest {
doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID);
Collection<ElementInfo> elements =
- zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName");
+ zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, NOT_EXISTING_ELEMENT_NAME);
assertTrue(elements.isEmpty());
}
@@ -144,7 +149,7 @@ public class ZusammenAdaptorImplTest {
doReturn(returnedElements).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(1).getId());
Collection<ElementInfo> elements =
- zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2");
+ zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, ELEMENT_NAME);
assertEquals(returnedElements, elements);
}
@@ -254,7 +259,7 @@ public class ZusammenAdaptorImplTest {
ZusammenElement nonExistingSub = new ZusammenElement();
nonExistingSub.setAction(Action.UPDATE);
Info info = new Info();
- info.setName("nonExistingName");
+ info.setName(NOT_EXISTING_ELEMENT_NAME);
nonExistingSub.setInfo(info);
element.addSubElement(nonExistingSub);
diff --git a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenElementUtilTest.java b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenElementUtilTest.java
new file mode 100644
index 0000000..aeb28ae
--- /dev/null
+++ b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenElementUtilTest.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Samsung. 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.onap.sdc.common.zusammen.services.impl;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.item.Action;
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.common.zusammen.services.ZusammenElementUtil;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ZusammenElementUtilTest {
+
+ private static final String ELEMENT_ID = "1";
+ private static final String ELEMENT_TYPE = "Type";
+
+ @Test
+ public void testBuildElement() {
+
+ ZusammenElement zusammenElement =
+ ZusammenElementUtil.buildElement(new Id(ELEMENT_ID), Action.CREATE);
+ assertEquals(ELEMENT_ID, zusammenElement.getElementId().getValue());
+ assertEquals(Action.CREATE, zusammenElement.getAction());
+ }
+
+ @Test
+ public void testBuildStructuralElement() {
+
+ ZusammenElement zusammenElement =
+ ZusammenElementUtil.buildStructuralElement(ELEMENT_TYPE, Action.CREATE);
+ assertEquals(ELEMENT_TYPE, zusammenElement.getInfo().getName());
+ }
+
+}