2 * ============LICENSE_START=======================================================
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
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;
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;
38 import java.util.Iterator;
40 public class ModelTestBase {
42 protected static ConfigurationManager configurationManager;
43 protected static final String CONTAINER_ID = "containerId";
44 protected static final String CONTAINER_NAME = "containerName";
46 public static void init() {
47 String appConfigDir = "src/test/resources/config";
48 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
50 configurationManager = new ConfigurationManager(configurationSource);
52 Configuration configuration = new Configuration();
54 configuration.setTitanInMemoryGraph(true);
56 configurationManager.setConfiguration(configuration);
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();
72 protected PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
73 PropertyDefinition prop1 = new PropertyDefinition();
74 prop1.setDefaultValue(defaultValue);
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());