Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / ModelTestBase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model;
22
23 import org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.JanusGraphVertex;
25 import fj.data.Either;
26 import org.openecomp.sdc.be.config.Configuration;
27 import org.openecomp.sdc.be.config.ConfigurationManager;
28 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
29 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
30 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
31 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
32 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
33 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
34 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
35 import org.openecomp.sdc.common.api.ConfigurationSource;
36 import org.openecomp.sdc.common.impl.ExternalConfiguration;
37 import org.openecomp.sdc.common.impl.FSConfigurationSource;
38
39 import java.util.HashMap;
40 import java.util.Iterator;
41 import java.util.Map;
42
43 public class ModelTestBase {
44
45     protected static ConfigurationManager configurationManager;
46     protected static final String CONTAINER_ID = "containerId";
47     protected static final String CONTAINER_NAME = "containerName";
48
49     public static void init() {
50         String appConfigDir = "src/test/resources/config";
51         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
52                 appConfigDir);
53         configurationManager = new ConfigurationManager(configurationSource);
54
55         Configuration configuration = new Configuration();
56
57         configuration.setJanusGraphInMemoryGraph(true);
58
59         Map<String, Object> deploymentRIArtifacts = new HashMap<>();
60         ArtifactDataDefinition artifactInfo = new ArtifactDataDefinition();
61         Object artifactDataObj = new HashMap<String, Object>();
62         ((HashMap) artifactDataObj).put("1", artifactInfo);
63         deploymentRIArtifacts.put("VfHeatEnv", artifactDataObj);
64
65         configurationManager.setConfiguration(configuration);
66         configurationManager.getConfiguration().setDeploymentResourceInstanceArtifacts(deploymentRIArtifacts);
67         }
68
69     protected void removeGraphVertices(Either<JanusGraph, JanusGraphOperationStatus> graphResult) {
70         JanusGraph graph = graphResult.left().value();
71         Iterable<JanusGraphVertex> vertices = graph.query().vertices();
72         if (vertices != null) {
73             Iterator<JanusGraphVertex> iterator = vertices.iterator();
74             while (iterator.hasNext()) {
75                 JanusGraphVertex vertex = iterator.next();
76                 vertex.remove();
77             }
78
79         }
80     }
81
82     protected PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
83         PropertyDefinition prop1 = new PropertyDefinition();
84         prop1.setDefaultValue(defaultValue);
85         prop1.setName(name);
86         prop1.setType(type);
87         return prop1;
88     }
89
90     protected GraphVertex createBasicContainerGraphVertex() {
91         GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
92         resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
93         resource.addMetadataProperty(GraphPropertyEnum.NAME, CONTAINER_NAME);
94         resource.setJsonMetadataField(JsonPresentationFields.NAME, CONTAINER_NAME);
95         resource.setJsonMetadataField(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
96         return resource;
97     }
98 }