Add some unit tests 41/105741/5
authorReo Inoue <inoue.reo@jp.fujitsu.com>
Fri, 10 Apr 2020 00:32:45 +0000 (09:32 +0900)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Thu, 16 Apr 2020 07:55:18 +0000 (07:55 +0000)
This change adds unit tests for ComponentLogi
to increase test coverage.

Issue-ID: SDC-2885
Change-Id: I53e5da1a1022ef2a6e29119cc531b61dcc3020b1
Signed-off-by: Reo Inoue <inoue.reo@jp.fujitsu.com>
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentLockerTest.java [new file with mode: 0644]

diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentLockerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentLockerTest.java
new file mode 100644 (file)
index 0000000..d2c7c7a
--- /dev/null
@@ -0,0 +1,71 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * SDC\r
+ * ================================================================================\r
+ * Copyright (C) 2020 Fujitsu Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.sdc.be.components.impl;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.MockitoAnnotations;\r
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;\r
+import org.openecomp.sdc.be.model.Component;\r
+import org.openecomp.sdc.be.model.operations.StorageException;\r
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;\r
+import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;\r
+import org.openecomp.sdc.be.model.Service;\r
+import static org.mockito.Mockito.when;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.times;\r
+\r
+public class ComponentLockerTest {\r
+\r
+    private static final String USER_ID = "userId";\r
+\r
+    @Mock\r
+    private GraphLockOperation graphLockOperation;\r
+\r
+    @InjectMocks\r
+    private ComponentLocker testInstance;\r
+\r
+    @Before\r
+    public void init() {\r
+        MockitoAnnotations.initMocks(this);\r
+    }\r
+\r
+    @Test\r
+    public void lock_Component() {\r
+        Component component= new Service();\r
+        component.setComponentType(ComponentTypeEnum.SERVICE);\r
+        component.setUniqueId(USER_ID);\r
+        when(graphLockOperation.lockComponent(USER_ID, component.getComponentType().getNodeType())).thenReturn(StorageOperationStatus.OK);\r
+        testInstance.lock(component);\r
+        verify(graphLockOperation, times(1)).lockComponent(USER_ID, component.getComponentType().getNodeType());\r
+    }\r
+\r
+    @Test(expected = StorageException.class)\r
+    public void lock_Component_Exception() {\r
+        Component component= new Service();\r
+        component.setComponentType(ComponentTypeEnum.SERVICE);\r
+        component.setUniqueId(USER_ID);\r
+        when(graphLockOperation.lockComponent(USER_ID, component.getComponentType().getNodeType())).thenReturn(StorageOperationStatus.INVALID_VALUE);\r
+        testInstance.lock(component);\r
+    }\r
+\r
+}\r