aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-07-02 12:55:35 +0200
committerOren Kleks <orenkle@amdocs.com>2019-07-07 13:05:01 +0000
commit8f82ddc9c6a2bc45680748f3f584e36a1ce131d4 (patch)
tree24888e1fbeb4942f294f37aad0644ce5d2b22f7c /catalog-model/src/test
parent6185ebc6d0e1e002029764dadd43818c71ab1120 (diff)
Improved unit tests for ComponentValidationUtils and Sonar fixes.
Improved unit tests for ComponentValidationUtils. Checkstyle for ComponentValidationUtils. Add a private constructor to hide the implicit public one in the ComponentValidationUtils. Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I8a2f2f7b9a5e6475a4e28d13f3acab333b4af6da
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtilsTest.java119
1 files changed, 115 insertions, 4 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtilsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtilsTest.java
index b2e7c60beb..1b5b9cb5f8 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtilsTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/utils/ComponentValidationUtilsTest.java
@@ -1,16 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * 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.operations.utils;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
-import static org.junit.Assert.assertTrue;
+import fj.data.Either;
+@RunWith(MockitoJUnitRunner.class)
public class ComponentValidationUtilsTest {
+ private static final String USER_ID = "jh003";
+ private static final String BAD_USER_ID = "badID";
+ private static final String COMPONENT_ID = "componentID";
+
private Resource resource;
+ @Mock
+ ToscaOperationFacade toscaOperationFacade;
+ @Mock
+ Component component;
+
@Before
public void setup() {
resource = new Resource();
@@ -21,11 +62,81 @@ public class ComponentValidationUtilsTest {
@Test
public void testCanWorkOnResource() {
- assertTrue (ComponentValidationUtils.canWorkOnResource(resource, "jh003"));
+ assertTrue(ComponentValidationUtils.canWorkOnResource(resource, USER_ID));
+ }
+
+ @Test
+ public void testCanWorkOnBadResourceAndBadUser() {
+ assertFalse(ComponentValidationUtils.canWorkOnResource(resource, BAD_USER_ID));
+
+ resource.setLifecycleState(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ assertFalse(ComponentValidationUtils.canWorkOnResource(resource, USER_ID));
+
+ resource.setIsDeleted(true);
+ assertFalse(ComponentValidationUtils.canWorkOnResource(resource, USER_ID));
}
@Test
public void testCanWorkOnComponent() {
- assertTrue (ComponentValidationUtils.canWorkOnComponent(resource, "jh003"));
+ // given
+ when(component.getLifecycleState()).thenReturn(resource.getLifecycleState());
+ when(component.getLastUpdaterUserId()).thenReturn(resource.getLastUpdaterUserId());
+
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID),
+ eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.left(component));
+
+ // when
+ boolean resultFromExtractComponent = ComponentValidationUtils
+ .canWorkOnComponent(COMPONENT_ID, toscaOperationFacade, USER_ID);
+ boolean resultFromComponent =
+ ComponentValidationUtils.canWorkOnComponent(component, USER_ID);
+
+ // then
+ assertTrue(resultFromExtractComponent);
+ assertTrue(resultFromComponent);
+ }
+
+ @Test
+ public void testCanWorkOnBadComponent() {
+ // given
+ when(component.getLifecycleState())
+ .thenReturn(LifecycleStateEnum.CERTIFICATION_IN_PROGRESS);
+ when(component.getLastUpdaterUserId()).thenReturn(resource.getLastUpdaterUserId());
+
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID),
+ eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.left(component));
+
+ // when
+ boolean resultFromExtractComponent = ComponentValidationUtils
+ .canWorkOnComponent(COMPONENT_ID, toscaOperationFacade, USER_ID);
+ boolean resultFromComponent =
+ ComponentValidationUtils.canWorkOnComponent(component, USER_ID);
+
+ // then
+ assertFalse(resultFromExtractComponent);
+ assertFalse(resultFromComponent);
+ }
+
+ @Test
+ public void testCanWorkOnComponentWithBadUser() {
+ // given
+ when(component.getLifecycleState()).thenReturn(resource.getLifecycleState());
+ when(component.getLastUpdaterUserId()).thenReturn(resource.getLastUpdaterUserId());
+
+ when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID),
+ eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.left(component));
+
+ // when
+ boolean resultFromExtractComponent = ComponentValidationUtils
+ .canWorkOnComponent(COMPONENT_ID, toscaOperationFacade, BAD_USER_ID);
+ boolean resultFromComponent =
+ ComponentValidationUtils.canWorkOnComponent(component, BAD_USER_ID);
+ boolean resultFromComponentWithNullUser =
+ ComponentValidationUtils.canWorkOnComponent(component, null);
+
+ // then
+ assertFalse(resultFromExtractComponent);
+ assertFalse(resultFromComponent);
+ assertFalse(resultFromComponentWithNullUser);
}
-} \ No newline at end of file
+}