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.jsongraph.JanusGraphDao;
36 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
37 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
38 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
39 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
41 import java.util.ArrayList;
42 import java.util.Iterator;
43 import java.util.List;
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertTrue;
47 import static org.mockito.Mockito.when;
49 @RunWith(MockitoJUnitRunner.class)
50 public class ToscaElementOperationCatalogTest {
52 private static final String UPDATER_ID = "m08740";
53 private ArrayList<Vertex> vertexList = new ArrayList<>();
64 JanusGraphDao janusGraphDao;
66 VertexProperty<Object> property;
68 VertexProperty<Object> updaterProperty;
71 private ToscaElementOperation toscaOperation = new TopologyTemplateOperation();
75 vertexList.add(vertex);
76 when(janusGraphDao.getCatalogOrArchiveVerticies(true)).thenReturn(Either.left(vertexList.iterator()));
77 when(janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse))
78 .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND));
79 when(vertex.property(GraphPropertiesDictionary.METADATA.getProperty())).thenReturn(property);
82 private void stubEmptyUpdater() {
83 when(vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name())).thenReturn(edges);
84 when(edges.hasNext()).thenReturn(false);
87 private void stubExistingUpdater() {
88 when(vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name())).thenReturn(edges);
89 when(edges.hasNext()).thenReturn(true);
90 when(edges.next()).thenReturn(edge);
91 when(edge.outVertex()).thenReturn(outVertex);
92 when(updaterProperty.value()).thenReturn(UPDATER_ID);
93 when(outVertex.property(GraphPropertiesDictionary.USERID.getProperty())).thenReturn(updaterProperty);
97 public void getComponentFromCatalogWhenDeleteIsTrue() {
98 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\"}";
99 when(property.value()).thenReturn(vertexJsonIsDeletedTrue);
100 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
101 assertTrue(componentList.isEmpty());
105 public void getComponentFromCatalogWhenDeleteNotFound() {
107 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\"}";
108 when(property.value()).thenReturn(vertexJsonIsDeletedNotFound);
109 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
110 assertEquals(1, componentList.size());
114 public void getComponentFromCatalogWhenDeleteIsFalse() {
115 stubExistingUpdater();
116 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\"}";
117 when(property.value()).thenReturn(vertexJsonIsDeletedFalse);
118 List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
119 assertEquals(1, componentList.size());
120 assertEquals(UPDATER_ID, componentList.get(0).getLastUpdaterUserId());