re base code
[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 com.thinkaurelius.titan.core.TitanGraph;
24 import com.thinkaurelius.titan.core.TitanVertex;
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.jsongraph.GraphVertex;
29 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
30 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
33 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
34 import org.openecomp.sdc.common.api.ConfigurationSource;
35 import org.openecomp.sdc.common.impl.ExternalConfiguration;
36 import org.openecomp.sdc.common.impl.FSConfigurationSource;
37
38 import java.util.Iterator;
39
40 public class ModelTestBase {
41
42     protected static ConfigurationManager configurationManager;
43     protected static final String CONTAINER_ID = "containerId";
44     protected static final String CONTAINER_NAME = "containerName";
45
46     public static void init() {
47                 String appConfigDir = "src/test/resources/config";
48                 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
49                                 appConfigDir);
50                 configurationManager = new ConfigurationManager(configurationSource);
51
52                 Configuration configuration = new Configuration();
53
54                 configuration.setTitanInMemoryGraph(true);
55
56                 configurationManager.setConfiguration(configuration);
57         }
58
59     protected void removeGraphVertices(Either<TitanGraph, TitanOperationStatus> graphResult) {
60         TitanGraph graph = graphResult.left().value();
61         Iterable<TitanVertex> vertices = graph.query().vertices();
62         if (vertices != null) {
63             Iterator<TitanVertex> iterator = vertices.iterator();
64             while (iterator.hasNext()) {
65                 TitanVertex vertex = iterator.next();
66                 vertex.remove();
67             }
68
69         }
70     }
71
72     protected PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
73         PropertyDefinition prop1 = new PropertyDefinition();
74         prop1.setDefaultValue(defaultValue);
75         prop1.setName(name);
76         prop1.setType(type);
77         return prop1;
78     }
79
80     protected GraphVertex createBasicContainerGraphVertex() {
81         GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE);
82         resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID);
83         resource.addMetadataProperty(GraphPropertyEnum.NAME, CONTAINER_NAME);
84         resource.setJsonMetadataField(JsonPresentationFields.NAME, CONTAINER_NAME);
85         resource.setJsonMetadataField(JsonPresentationFields.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
86         return resource;
87     }
88 }