2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.jsonjanusgraph.operations;
23 import fj.data.Either;
24 import org.apache.tinkerpop.gremlin.structure.Direction;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
27 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
36 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
37 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
38 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
40 import java.util.ArrayList;
41 import java.util.Iterator;
42 import java.util.List;
44 import static org.junit.Assert.assertEquals;
45 import static org.junit.Assert.assertTrue;
46 import static org.mockito.Mockito.when;
48 @RunWith(MockitoJUnitRunner.class)
49 public class ToscaElementOperationCatalogTest {
51 private static final String UPDATER_ID = "m08740";
52 private ArrayList<Vertex> vertexList = new ArrayList<>();
63 JanusGraphDao janusGraphDao;
65 VertexProperty<Object> property;
67 VertexProperty<Object> updaterProperty;
70 private ToscaElementOperation toscaOperation = new TopologyTemplateOperation();
74 vertexList.add(vertex);
75 when(janusGraphDao.getCatalogOrArchiveVertices(true)).thenReturn(Either.left(vertexList.iterator()));
76 when(janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY))
77 .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
78 when(vertex.property(GraphPropertiesDictionary.METADATA.getProperty())).thenReturn(property);
81 private void stubEmptyUpdater() {
82 when(vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name())).thenReturn(edges);
83 when(edges.hasNext()).thenReturn(false);
86 private void stubExistingUpdater() {
87 when(vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name())).thenReturn(edges);
88 when(edges.hasNext()).thenReturn(true);
89 when(edges.next()).thenReturn(edge);
90 when(edge.outVertex()).thenReturn(outVertex);
91 when(updaterProperty.value()).thenReturn(UPDATER_ID);
92 when(outVertex.property(GraphPropertiesDictionary.USERID.getProperty())).thenReturn(updaterProperty);
96 public void getComponentFromCatalogWhenDeleteIsTrue() {
97 final String vertexJsonIsDeletedTrue = "{\"lifecycleState\":\"CERTIFIED\",\"componentType\":\"RESOURCE\",\"vendorRelease\":\"1\",\"contactId\":\"ah7840\",\"lastUpdateDate\":1496119811038,\"icon\":\"att\",\"description\":\"Cloud\",\"creationDate\":1459432094781,\"vendorName\":\"AT&T\",\"mandatory\":false,\"version\":\"1.0\",\"tags\":[\"Cloud\"],\"highestVersion\":true,\"systemName\":\"Cloud\",\"name\":\"Cloud\",\"isDeleted\":true,\"invariantUuid\":\"ab5263fd-115c-41f2-8d0c-8b9279bce2b2\",\"UUID\":\"208cf7df-68a1-4ae7-afc9-409ea8012332\",\"normalizedName\":\"cloud\",\"toscaResourceName\":\"org.openecomp.resource.Endpoint.Cloud\",\"uniqueId\":\"9674e7e1-bc1a-41fe-b503-fbe996801475\",\"resourceType\":\"VFC\"}";
98 when(property.value()).thenReturn(vertexJsonIsDeletedTrue);
99 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
100 assertTrue(componentList.isEmpty());
104 public void getComponentFromCatalogWhenDeleteNotFound() {
106 final String vertexJsonIsDeletedNotFound = "{\"lifecycleState\":\"CERTIFIED\",\"componentType\":\"RESOURCE\",\"vendorRelease\":\"1\",\"contactId\":\"ah7840\",\"lastUpdateDate\":1496119811038,\"icon\":\"att\",\"description\":\"Cloud\",\"creationDate\":1459432094781,\"vendorName\":\"AT&T\",\"mandatory\":false,\"version\":\"1.0\",\"tags\":[\"Cloud\"],\"highestVersion\":true,\"systemName\":\"Cloud\",\"name\":\"Cloud\",\"invariantUuid\":\"ab5263fd-115c-41f2-8d0c-8b9279bce2b2\",\"UUID\":\"208cf7df-68a1-4ae7-afc9-409ea8012332\",\"normalizedName\":\"cloud\",\"toscaResourceName\":\"org.openecomp.resource.Endpoint.Cloud\",\"uniqueId\":\"9674e7e1-bc1a-41fe-b503-fbe996801475\",\"resourceType\":\"VFC\"}";
107 when(property.value()).thenReturn(vertexJsonIsDeletedNotFound);
108 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
109 assertEquals(1, componentList.size());
113 public void getComponentFromCatalogWhenDeleteIsFalse() {
114 stubExistingUpdater();
115 final String vertexJsonIsDeletedFalse = "{\"lifecycleState\":\"CERTIFIED\",\"componentType\":\"RESOURCE\",\"vendorRelease\":\"1\",\"contactId\":\"ah7840\",\"lastUpdateDate\":1496119811038,\"icon\":\"att\",\"description\":\"Cloud\",\"creationDate\":1459432094781,\"vendorName\":\"AT&T\",\"mandatory\":false,\"version\":\"1.0\",\"tags\":[\"Cloud\"],\"highestVersion\":true,\"systemName\":\"Cloud\",\"name\":\"Cloud\",\"isDeleted\":false,\"invariantUuid\":\"ab5263fd-115c-41f2-8d0c-8b9279bce2b2\",\"UUID\":\"208cf7df-68a1-4ae7-afc9-409ea8012332\",\"normalizedName\":\"cloud\",\"toscaResourceName\":\"org.openecomp.resource.Endpoint.Cloud\",\"uniqueId\":\"9674e7e1-bc1a-41fe-b503-fbe996801475\",\"resourceType\":\"VFC\"}";
116 when(property.value()).thenReturn(vertexJsonIsDeletedFalse);
117 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
118 assertEquals(1, componentList.size());
119 assertEquals(UPDATER_ID, componentList.get(0).getLastUpdaterUserId());