Make Service base type optional
[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     static Configuration.EnvironmentContext environmentContext = new Configuration.EnvironmentContext();
49     static Configuration.HeatDeploymentArtifactTimeout heatDeploymentArtifactTimeout = new Configuration.HeatDeploymentArtifactTimeout();
50
51     public static void init() {
52         String appConfigDir = "src/test/resources/config";
53         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
54                 appConfigDir);
55         configurationManager = new ConfigurationManager(configurationSource);
56
57         Configuration configuration = configurationManager.getConfiguration();
58         configuration.setCassandraConfig(null);
59
60         configuration.setJanusGraphInMemoryGraph(true);
61                 environmentContext.setDefaultValue("General_Revenue-Bearing");
62                 configuration.setEnvironmentContext(environmentContext);
63
64                 heatDeploymentArtifactTimeout.setDefaultMinutes(30);
65                 configuration.setHeatArtifactDeploymentTimeout(heatDeploymentArtifactTimeout);
66         Map<String, Object> deploymentRIArtifacts = new HashMap<>();
67         ArtifactDataDefinition artifactInfo = new ArtifactDataDefinition();
68         HashMap<String, Object> artifactDataObj = new HashMap<>();
69         artifactDataObj.put("1", artifactInfo);
70         deploymentRIArtifacts.put("VfHeatEnv", artifactDataObj);
71
72         configurationManager.getConfiguration().setDeploymentResourceInstanceArtifacts(deploymentRIArtifacts);
73         }
74
75     protected void removeGraphVertices(Either<JanusGraph, JanusGraphOperationStatus> graphResult) {
76         JanusGraph graph = graphResult.left().value();
77         Iterable<JanusGraphVertex> vertices = graph.query().vertices();
78         if (vertices != null) {
79             Iterator<JanusGraphVertex> iterator = vertices.iterator();
80             while (iterator.hasNext()) {
81                 JanusGraphVertex vertex = iterator.next();
82                 vertex.remove();
83             }
84
85         }
86     }
87
88     protected PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
89         PropertyDefinition prop1 = new PropertyDefinition();
90         prop1.setDefaultValue(defaultValue);
91         prop1.setName(name);
92         prop1.setType(type);
93         return prop1;
94     }
95
96     protected GraphVertex createBasicContainerGraphVertex() {
97         GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
98         resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
99         resource.addMetadataProperty(GraphPropertyEnum.NAME, CONTAINER_NAME);
100         resource.setJsonMetadataField(JsonPresentationFields.NAME, CONTAINER_NAME);
101         resource.setJsonMetadataField(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
102         return resource;
103     }
104 }