--- /dev/null
+/*-\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