unit tests - asdctool 10/94110/2
authorTomasz Golabek <tomasz.golabek@nokia.com>
Thu, 22 Aug 2019 13:03:50 +0000 (15:03 +0200)
committerTomasz Golabek <tomasz.golabek@nokia.com>
Thu, 22 Aug 2019 14:22:43 +0000 (14:22 +0000)
Additional junit tests

Change-Id: I889772efaccbc6f1555d50cd47a02d868348d310
Issue-ID: SDC-2326
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
asdctool/pom.xml
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRow.java [new file with mode: 0644]
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentRow.java [new file with mode: 0644]
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFixTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRowTest.java [new file with mode: 0644]
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentRowTest.java [new file with mode: 0644]

index 56d822e..ced840d 100644 (file)
                        <scope>test</scope>
                </dependency>
 
+               <dependency>
+                       <groupId>com.google.code.bean-matchers</groupId>
+                       <artifactId>bean-matchers</artifactId>
+                       <version>${bean-matchers.version}</version>
+                       <scope>test</scope>
+               </dependency>
+
                <dependency>
                        <groupId>com.github.stefanbirkner</groupId>
                        <artifactId>system-rules</artifactId>
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRow.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRow.java
new file mode 100644 (file)
index 0000000..f2ee154
--- /dev/null
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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.openecomp.sdc.asdctool.impl;
+
+public class ComponentInstanceRow {
+    private String uniqueId;
+    private String name;
+    private String originUid;
+    private String originType;
+    private String containerUid;
+
+    public String getContainerUid() {
+        return containerUid;
+    }
+
+    public void setContainerUid(String containerUid) {
+        this.containerUid = containerUid;
+    }
+
+    public String getUniqueId() {
+        return uniqueId;
+    }
+
+    public void setUniqueId(String uniqueId) {
+        this.uniqueId = uniqueId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getOriginUid() {
+        return originUid;
+    }
+
+    public void setOriginUid(String componentUid) {
+        this.originUid = componentUid;
+    }
+
+    public String getOriginType() {
+        return originType;
+    }
+
+    public void setOriginType(String originType) {
+        this.originType = originType;
+    }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentRow.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ComponentRow.java
new file mode 100644 (file)
index 0000000..795810c
--- /dev/null
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.asdctool.impl;
+
+public class ComponentRow {
+    private String uniqueId;
+    private String type;
+    private String name;
+    private String toscaResourceName;
+    private String resourceType;
+    private String version;
+    private Boolean isDeleted;
+    private Boolean hasNonCalculatedReqCap;
+
+    public Boolean getHasNonCalculatedReqCap() {
+        return hasNonCalculatedReqCap;
+    }
+
+    public void setHasNonCalculatedReqCap(Boolean hasNonCalculatedReqCap) {
+        this.hasNonCalculatedReqCap = hasNonCalculatedReqCap;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getUniqueId() {
+        return uniqueId;
+    }
+
+    public void setUniqueId(String uniqueId) {
+        this.uniqueId = uniqueId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getToscaResourceName() {
+        return toscaResourceName;
+    }
+
+    public void setToscaResourceName(String toscaResourceName) {
+        this.toscaResourceName = toscaResourceName;
+    }
+
+    public String getResourceType() {
+        return resourceType;
+    }
+
+    public void setResourceType(String resourceType) {
+        this.resourceType = resourceType;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public Boolean getIsDeleted() {
+        return isDeleted;
+    }
+
+    public void setIsDeleted(Boolean deleted) {
+        this.isDeleted = deleted;
+    }
+}
index 2aed83c..1b065c2 100644 (file)
@@ -241,127 +241,4 @@ public class GraphMLDataAnalyzer {
                return res;
        }
 
-       private class ComponentRow {
-
-               private String uniqueId;
-               private String type;
-               private String name;
-               private String toscaResourceName;
-               private String resourceType;
-               private String version;
-               private Boolean isDeleted;
-               private Boolean hasNonCalculatedReqCap;
-
-               public Boolean getHasNonCalculatedReqCap() {
-                       return hasNonCalculatedReqCap;
-               }
-
-               public void setHasNonCalculatedReqCap(Boolean hasNonCalculatedReqCap) {
-                       this.hasNonCalculatedReqCap = hasNonCalculatedReqCap;
-               }
-
-               public String getType() {
-                       return type;
-               }
-
-               public void setType(String type) {
-                       this.type = type;
-               }
-
-               public String getUniqueId() {
-                       return uniqueId;
-               }
-
-               public void setUniqueId(String uniqueId) {
-                       this.uniqueId = uniqueId;
-               }
-
-               public String getName() {
-                       return name;
-               }
-
-               public void setName(String name) {
-                       this.name = name;
-               }
-
-               public String getToscaResourceName() {
-                       return toscaResourceName;
-               }
-
-               public void setToscaResourceName(String toscaResourceName) {
-                       this.toscaResourceName = toscaResourceName;
-               }
-
-               public String getResourceType() {
-                       return resourceType;
-               }
-
-               public void setResourceType(String resourceType) {
-                       this.resourceType = resourceType;
-               }
-
-               public String getVersion() {
-                       return version;
-               }
-
-               public void setVersion(String version) {
-                       this.version = version;
-               }
-
-               public Boolean getIsDeleted() {
-                       return isDeleted;
-               }
-
-               public void setIsDeleted(Boolean deleted) {
-                       this.isDeleted = deleted;
-               }
-       }
-
-       private class ComponentInstanceRow {
-               private String uniqueId;
-               private String name;
-               private String originUid;
-               private String originType;
-               private String containerUid;
-
-               public String getContainerUid() {
-                       return containerUid;
-               }
-
-               public void setContainerUid(String containerUid) {
-                       this.containerUid = containerUid;
-               }
-
-               public String getUniqueId() {
-                       return uniqueId;
-               }
-
-               public void setUniqueId(String uniqueId) {
-                       this.uniqueId = uniqueId;
-               }
-
-               public String getName() {
-                       return name;
-               }
-
-               public void setName(String name) {
-                       this.name = name;
-               }
-
-               public String getOriginUid() {
-                       return originUid;
-               }
-
-               public void setOriginUid(String componentUid) {
-                       this.originUid = componentUid;
-               }
-
-               public String getOriginType() {
-                       return originType;
-               }
-
-               public void setOriginType(String originType) {
-                       this.originType = originType;
-               }
-       }
 }
index 8a6c9af..0ea4484 100644 (file)
@@ -27,11 +27,14 @@ import org.junit.runner.RunWith;
 import org.mockito.ArgumentMatchers;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -58,6 +61,9 @@ public class ArtifactUuidFixTest {
        @InjectMocks
        private ArtifactUuidFix test;
 
+       @Mock
+       private Component component;
+
        @Mock
        private JanusGraphDao janusGraphDao;
 
@@ -214,4 +220,79 @@ public class ArtifactUuidFixTest {
                result = test.doFix(fixComponent, runMode);
                assertEquals(false,result);
        }
+
+
+       @Test
+       public void testDoFixVfWithFixMode() {
+               String fixComponent = "";
+               String runMode = "fix";
+               String uniqueId = "uniqueId";
+               boolean result;
+               fixComponent = "vf_only";
+               Map<GraphPropertyEnum, Object> hasProps1 = new HashMap<>();
+               hasProps1.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+               hasProps1.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+               List<GraphVertex> list = new ArrayList<>();
+               GraphVertex graphVertex = new GraphVertex();
+               graphVertex.setVertex(vertex);
+               graphVertex.setUniqueId(uniqueId);
+               graphVertex.setMetadataProperties(hasProps1);
+               list.add(graphVertex);
+               when(janusGraphDao.getByCriteria(VertexTypeEnum.NODE_TYPE, hasProps1)).thenReturn(Either.left(list));
+
+               Map<GraphPropertyEnum, Object> hasProps2 = new HashMap<>();
+               hasProps2.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+               hasProps2.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
+               hasProps2.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+               when(janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps2)).thenReturn(Either.left(list));
+
+               Map<GraphPropertyEnum, Object> hasProps3 = new HashMap<>();
+               hasProps3.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+               hasProps3.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+               when(janusGraphDao.getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps3)).thenReturn(Either.left(list));
+
+               Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+               hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+               hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
+               Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
+               hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
+               when(janusGraphDao
+                       .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps, hasNotProps, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(list));
+               Resource resource = new Resource();
+               resource.setName(uniqueId);
+               Map<String, ArtifactDefinition> deployArtifact = new HashMap<>();
+               ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+               artifactDefinition.setArtifactType(ArtifactTypeEnum.VF_MODULES_METADATA.getType());
+               artifactDefinition.setUniqueId("one.two");
+               artifactDefinition.setArtifactUUID("one.two");
+               deployArtifact.put("two", artifactDefinition);
+               resource.setDeploymentArtifacts(deployArtifact);
+               List<GroupDefinition> groups = new ArrayList<>();
+               GroupDefinition groupDefinition = new GroupDefinition();
+               groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE);
+               List<String> artifacts = new ArrayList<>();
+               artifacts.add("one.two");
+               groupDefinition.setArtifacts(artifacts);
+               groupDefinition.setArtifactsUuid(artifacts);
+               groups.add(groupDefinition);
+               resource.setGroups(groups);
+               resource.setUniqueId(uniqueId);
+               resource.setComponentType(ComponentTypeEnum.SERVICE_INSTANCE);
+
+               when(toscaOperationFacade.getToscaElement(graphVertex.getUniqueId())).thenReturn(Either.left(resource));
+               when(toscaOperationFacade.getToscaFullElement(Mockito.anyString())).thenReturn(Either.left(component));
+               when(component.getUniqueId()).thenReturn(uniqueId);
+               when(toscaOperationFacade.getToscaElement(Mockito.anyString(), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(component));
+               when(janusGraphDao.getVertexById(uniqueId, JsonParseFlagEnum.NoParse)).thenReturn(Either.left(graphVertex));
+               when(janusGraphDao.getChildVertex(graphVertex, EdgeLabelEnum.GROUPS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+               when(janusGraphDao.getChildVertex(graphVertex, EdgeLabelEnum.DEPLOYMENT_ARTIFACTS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+               when(janusGraphDao.getChildVertex(graphVertex, EdgeLabelEnum.TOSCA_ARTIFACTS, JsonParseFlagEnum.ParseJson)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
+
+               List<Service> serviceList = new ArrayList<>();
+               serviceList.add(service);
+
+               result = test.doFix(fixComponent, runMode);
+               assertEquals(true, result);
+       }
+
 }
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRowTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentInstanceRowTest.java
new file mode 100644 (file)
index 0000000..8b8f989
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.asdctool.impl;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ComponentInstanceRowTest {
+    @Test
+    public void shouldHaveValidGettersAndSetters() {
+        assertThat(ComponentInstanceRow.class,
+            hasValidGettersAndSetters());
+    }
+}
\ No newline at end of file
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentRowTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/ComponentRowTest.java
new file mode 100644 (file)
index 0000000..e5c139c
--- /dev/null
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia. 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.openecomp.sdc.asdctool.impl;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+public class ComponentRowTest {
+    @Test
+    public void shouldHaveValidGettersAndSetters() {
+        assertThat(ComponentRow.class,
+            hasValidGettersAndSetters());
+    }
+}
\ No newline at end of file