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 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;
39 import java.util.HashMap;
40 import java.util.Iterator;
43 public class ModelTestBase {
45 protected static ConfigurationManager configurationManager;
46 protected static final String CONTAINER_ID = "containerId";
47 protected static final String CONTAINER_NAME = "containerName";
49 public static void init() {
50 String appConfigDir = "src/test/resources/config";
51 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
53 configurationManager = new ConfigurationManager(configurationSource);
55 Configuration configuration = new Configuration();
57 configuration.setJanusGraphInMemoryGraph(true);
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);
65 configurationManager.setConfiguration(configuration);
66 configurationManager.getConfiguration().setDeploymentResourceInstanceArtifacts(deploymentRIArtifacts);
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();
82 protected PropertyDefinition createSimpleProperty(String defaultValue, String name, String type) {
83 PropertyDefinition prop1 = new PropertyDefinition();
84 prop1.setDefaultValue(defaultValue);
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());