4925c87ce44bacc715359f41f06f05ad3798104d
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / jsonjanusgraph / operations / InterfaceOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.jsonjanusgraph.operations;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.junit.Assert.assertTrue;
26
27 import fj.data.Either;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import javax.annotation.Resource;
34 import org.junit.After;
35 import org.junit.Assert;
36 import org.junit.Before;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
41 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
42 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
43 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
44 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
45 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
48 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
49 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
50 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
51 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
52 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
53 import org.openecomp.sdc.be.model.Component;
54 import org.openecomp.sdc.be.model.InterfaceDefinition;
55 import org.openecomp.sdc.be.model.LifecycleStateEnum;
56 import org.openecomp.sdc.be.model.ModelTestBase;
57 import org.openecomp.sdc.be.model.Operation;
58 import org.openecomp.sdc.be.model.Service;
59 import org.openecomp.sdc.be.model.category.CategoryDefinition;
60 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
61 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
62 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
63 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils;
64 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
65 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
66 import org.openecomp.sdc.common.util.ValidationUtils;
67 import org.springframework.test.context.ContextConfiguration;
68 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
69
70 @RunWith(SpringJUnit4ClassRunner.class)
71 @ContextConfiguration("classpath:application-context-test.xml")
72 public class InterfaceOperationTest extends ModelTestBase {
73
74     private static final String RESOURCE_NAME = "Resource Name";
75     private static final String RESOURCE_ID = "resourceID";
76     private static final String SERVICE_NAME = "Service Name";
77     private static final String SERVICE_ID = "serviceID";
78     private final String categoryName = "category";
79     private final String subcategory = "mycategory";
80     private final Service service = createService();
81     private final org.openecomp.sdc.be.model.Resource resource = createResource();
82     @Resource
83     protected JanusGraphDao janusGraphDao;
84     @Resource
85     protected NodeTypeOperation nodeTypeOperation;
86     @Resource
87     protected TopologyTemplateOperation topologyTemplateOperation;
88     @Resource
89     private InterfaceOperation interfaceOperation;
90     @Resource
91     private ToscaElementLifecycleOperation lifecycleOperation;
92     private GraphVertex ownerVertex;
93
94     @BeforeClass
95     public static void initInterfacesOperation() {
96         init();
97     }
98
99     @Before
100     public void setupBefore() {
101         GraphTestUtils.clearGraph(janusGraphDao);
102         createUsers();
103         createResourceCategory();
104         createServiceCategory();
105         GraphTestUtils.createRootCatalogVertex(janusGraphDao);
106         createRootNodeType();
107         createNodeType("resource", RESOURCE_ID);
108         createNodeType("service", SERVICE_ID);
109         createTopologyTemplate("firstService");
110     }
111
112     private void createUsers() {
113         GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
114         ownerV.setUniqueId("user1");
115
116         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
117         metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
118         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
119         metadataProperties.put(GraphPropertyEnum.NAME, "user1");
120         ownerV.setMetadataProperties(metadataProperties);
121         ownerV.updateMetadataJsonWithCurrentMetadataProperties();
122         ownerV.setJson(new HashMap<>());
123         Either<GraphVertex, JanusGraphOperationStatus> createUserRes = janusGraphDao.createVertex(ownerV);
124
125         ownerVertex = createUserRes.left().value();
126
127         GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
128         modifierV.setUniqueId("user2");
129
130         metadataProperties = new HashMap<>();
131         metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
132         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
133         metadataProperties.put(GraphPropertyEnum.NAME, "user2");
134         modifierV.setMetadataProperties(metadataProperties);
135         modifierV.updateMetadataJsonWithCurrentMetadataProperties();
136         modifierV.setJson(new HashMap<>());
137         createUserRes = janusGraphDao.createVertex(modifierV);
138         createUserRes.left().value();
139
140         lifecycleOperation.findUser(ownerVertex.getUniqueId());
141     }
142
143     private void createResourceCategory() {
144         GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
145         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
146         String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
147         cat.setUniqueId(catId);
148         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
149         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
150         metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
151         metadataProperties
152                 .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
153         cat.setMetadataProperties(metadataProperties);
154         cat.updateMetadataJsonWithCurrentMetadataProperties();
155
156         GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
157         metadataProperties = new HashMap<>();
158         String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
159         subCat.setUniqueId(subCatId);
160         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
161         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
162         metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
163         metadataProperties
164                 .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
165         subCat.setMetadataProperties(metadataProperties);
166         subCat.updateMetadataJsonWithCurrentMetadataProperties();
167
168         Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
169         Either<GraphVertex, JanusGraphOperationStatus> subCatRes = janusGraphDao.createVertex(subCat);
170         janusGraphDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(),
171                 EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
172     }
173
174     private void createServiceCategory() {
175         GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
176         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
177         String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
178         cat.setUniqueId(catId);
179         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
180         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
181         metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
182         metadataProperties
183                 .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
184         cat.setMetadataProperties(metadataProperties);
185         cat.updateMetadataJsonWithCurrentMetadataProperties();
186         janusGraphDao.createVertex(cat);
187     }
188
189     private void createRootNodeType() {
190         NodeType vf = new NodeType();
191         String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
192         vf.setUniqueId(uniqueId);
193         vf.setComponentType(ComponentTypeEnum.RESOURCE);
194         vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
195         vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
196         vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
197         vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
198         vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
199         vf.getMetadata()
200                 .put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
201         vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
202         vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
203
204         List<CategoryDefinition> categories = new ArrayList<>();
205         CategoryDefinition cat = new CategoryDefinition();
206         categories.add(cat);
207         cat.setName(categoryName);
208         List<SubCategoryDefinition> subCategories = new ArrayList<>();
209         SubCategoryDefinition subCat = new SubCategoryDefinition();
210         subCat.setName(subcategory);
211         subCategories.add(subCat);
212         cat.setSubcategories(subCategories);
213         vf.setCategories(categories);
214
215         List<String> derivedFrom = new ArrayList<>();
216         vf.setDerivedFrom(derivedFrom);
217
218         Map<String, PropertyDataDefinition> properties = new HashMap<>();
219         PropertyDataDefinition prop1 = new PropertyDataDefinition();
220         prop1.setName("derived1");
221         prop1.setDefaultValue("deriveddef1");
222         properties.put("derived1", prop1);
223
224         PropertyDataDefinition prop2 = new PropertyDataDefinition();
225         prop2.setUniqueId("derived2");
226         prop2.setName("deriveddef2");
227         properties.put("derived2", prop2);
228
229         PropertyDataDefinition prop3 = new PropertyDataDefinition();
230         prop3.setName("derived3");
231         prop3.setDefaultValue("deriveddef3");
232         properties.put("derived3", prop3);
233
234         vf.setProperties(properties);
235         vf.setComponentType(ComponentTypeEnum.RESOURCE);
236         Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
237
238         Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes =
239                 janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId());
240         getNodeTyeRes.left().value();
241     }
242
243     private <T extends ToscaDataDefinition> void createNodeType(String nodeTypeName, String uniqueId) {
244         NodeType vf = new NodeType();
245         vf.setUniqueId(uniqueId);
246         vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
247         vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
248         vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
249         vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
250         vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
251         vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
252         List<CategoryDefinition> categories = new ArrayList<>();
253         CategoryDefinition cat = new CategoryDefinition();
254         categories.add(cat);
255         cat.setName(categoryName);
256         List<SubCategoryDefinition> subCategories = new ArrayList<>();
257         SubCategoryDefinition subCat = new SubCategoryDefinition();
258         subCat.setName(subcategory);
259         subCategories.add(subCat);
260         cat.setSubcategories(subCategories);
261         vf.setCategories(categories);
262
263         List<String> derivedFrom = new ArrayList<>();
264         derivedFrom.add("root");
265         vf.setDerivedFrom(derivedFrom);
266
267         vf.setComponentType(ComponentTypeEnum.RESOURCE);
268
269         List<PropertyDataDefinition> addProperties = new ArrayList<>();
270         PropertyDataDefinition prop11 = new PropertyDataDefinition();
271         prop11.setName("prop11");
272         prop11.setDefaultValue("def11");
273
274         addProperties.add(prop11);
275
276         PropertyDataDefinition prop22 = new PropertyDataDefinition();
277         prop22.setName("prop22");
278         prop22.setDefaultValue("def22");
279         addProperties.add(prop22);
280
281         Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
282         Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes =
283                 janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId());
284         GraphVertex vfVertex = getNodeTyeRes.left().value();
285         StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES,
286                 VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
287         assertSame(StorageOperationStatus.OK, status);
288
289         PropertyDataDefinition prop33 = new PropertyDataDefinition();
290         prop33.setName("prop33");
291         prop33.setDefaultValue("def33");
292
293         status = nodeTypeOperation
294                          .addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES,
295                                  prop33, JsonPresentationFields.NAME);
296         assertSame(StorageOperationStatus.OK, status);
297
298         PropertyDataDefinition prop44 = new PropertyDataDefinition();
299         prop44.setName("prop44");
300         prop44.setDefaultValue("def44");
301
302         status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES,
303                 VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
304         assertSame(StorageOperationStatus.OK, status);
305
306         PropertyDataDefinition capProp = new PropertyDataDefinition();
307         capProp.setName("capProp");
308         capProp.setDefaultValue("capPropDef");
309
310         MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
311         dataToCreate.put("capProp", capProp);
312
313         Map<String, MapDataDefinition> capProps = new HashMap<>();
314         capProps.put("capName", dataToCreate);
315
316         nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
317                 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
318
319         List<String> pathKeys = new ArrayList<>();
320         pathKeys.add("capName");
321         capProp.setDefaultValue("BBBB");
322         nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES,
323                 VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
324     }
325
326     private void createTopologyTemplate(String name) {
327         TopologyTemplate service = new TopologyTemplate();
328         String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
329         service.setUniqueId(uniqueId);
330         service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
331         service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
332         service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
333         service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
334         service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
335         service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
336         List<CategoryDefinition> categories = new ArrayList<>();
337         CategoryDefinition cat = new CategoryDefinition();
338         categories.add(cat);
339         cat.setName(categoryName);
340         service.setCategories(categories);
341
342         service.setComponentType(ComponentTypeEnum.SERVICE);
343         Either<TopologyTemplate, StorageOperationStatus> createRes =
344                 topologyTemplateOperation.createTopologyTemplate(service);
345         Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes =
346                 janusGraphDao.getVertexById(createRes.left().value().getUniqueId());
347
348         getNodeTyeRes.left().value();
349     }
350
351     @After
352     public void cleanAfter() {
353         GraphTestUtils.clearGraph(janusGraphDao);
354     }
355
356     @Test
357     public void testAddInterface_Service() {
358         testAddSingleInterface(service);
359     }
360
361     private void testAddSingleInterface(Component component) {
362         InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
363         Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
364                                                                                 .addInterfaces(component.getUniqueId(),
365                                                                                         Collections.singletonList(
366                                                                                                 interfaceDefinition));
367         Assert.assertTrue(res.isLeft());
368         Assert.assertEquals("1", res.left().value().get(0).getUniqueId());
369     }
370
371     private InterfaceDefinition buildInterfaceDefinition(String uniqueId) {
372         InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
373         interfaceDefinition.setType("tosca.interfaces.standard");
374         interfaceDefinition.setUniqueId(uniqueId);
375         interfaceDefinition.setOperationsMap(createMockOperationMap());
376         return interfaceDefinition;
377     }
378
379     private Map<String, Operation> createMockOperationMap() {
380         Map<String, Operation> operationMap = new HashMap<>();
381         operationMap.put("op1", createMockOperation());
382         return operationMap;
383     }
384
385     private Operation createMockOperation() {
386         Operation operation = new Operation();
387         operation.setDefinition(false);
388         operation.setName("create");
389         operation.setUniqueId("op1");
390         return operation;
391     }
392
393     @Test
394     public void testAddInterface_Resource() {
395         testAddMultipleInterface(resource);
396     }
397
398     private void testAddMultipleInterface(Component component) {
399         InterfaceDefinition interfaceDefinition1 = buildInterfaceDefinition("1");
400         InterfaceDefinition interfaceDefinition2 = buildInterfaceDefinition("2");
401         List<InterfaceDefinition> interfaceDefinitions = new ArrayList<>();
402         interfaceDefinitions.add(interfaceDefinition1);
403         interfaceDefinitions.add(interfaceDefinition2);
404         Either<List<InterfaceDefinition>, StorageOperationStatus> res =
405                 interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions);
406         Assert.assertTrue(res.isLeft());
407         Assert.assertEquals(2, res.left().value().size());
408     }
409
410     @Test
411     public void testUpdateInterface_Service() {
412         testUpdateInterface(service);
413     }
414
415     private void testUpdateInterface(Component component) {
416         InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
417         Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
418                                                                                 .addInterfaces(component.getUniqueId(),
419                                                                                         Collections.singletonList(
420                                                                                                 interfaceDefinition));
421         Assert.assertTrue(res.isLeft());
422         List<InterfaceDefinition> value = res.left().value();
423         InterfaceDefinition createdInterfaceDef = value.get(0);
424         String newDescription = "New Description";
425         createdInterfaceDef.setDescription(newDescription);
426         res = interfaceOperation
427                       .updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef));
428         assertTrue(res.isLeft());
429         assertEquals(newDescription, res.left().value().get(0).getDescription());
430     }
431
432     @Test
433     public void testUpdateInterface_Resource() {
434         testUpdateInterface(resource);
435     }
436
437     @Test
438     public void testDeleteInterface_Service() {
439         testDeleteInterface(service);
440     }
441
442     private void testDeleteInterface(Component component) {
443         InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1");
444         Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation
445                                                                                 .addInterfaces(component.getUniqueId(),
446                                                                                         Collections.singletonList(
447                                                                                                 interfaceDefinition));
448         Assert.assertTrue(res.isLeft());
449         List<InterfaceDefinition> value = res.left().value();
450         Either<String, StorageOperationStatus> deleteInterfaceOperationRes =
451                 interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId());
452         assertTrue(deleteInterfaceOperationRes.isLeft());
453     }
454
455     @Test
456     public void testDeleteInterface_Resource() {
457         testDeleteInterface(resource);
458     }
459
460     @Test
461     public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() {
462         Component component = createResource();
463         InterfaceDefinition interfaceDefinition = buildInterfaceDefinitionWithoutOperation();
464         interfaceDefinition.setOperationsMap(createMockOperationMap());
465         Either<List<InterfaceDefinition>, StorageOperationStatus> res = interfaceOperation.updateInterfaces(
466                 component.getUniqueId(), Collections.singletonList(interfaceDefinition));
467         Assert.assertTrue(res.isRight());
468     }
469
470     private InterfaceDefinition buildInterfaceDefinitionWithoutOperation() {
471         InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
472         interfaceDefinition.setType("tosca.interfaces.standard");
473         return interfaceDefinition;
474     }
475
476     private org.openecomp.sdc.be.model.Resource createResource() {
477         org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource();
478         resource.setUniqueId(RESOURCE_ID);
479         resource.setName(RESOURCE_NAME);
480         resource.setDescription("My short description");
481         resource.setInterfaces(createMockInterfaceDefinition());
482         return resource;
483     }
484
485     private Service createService() {
486         Service service = new Service();
487         service.setUniqueId(SERVICE_ID);
488         service.setName(SERVICE_NAME);
489         service.setDescription("My short description");
490         service.setInterfaces(createMockInterfaceDefinition());
491         return service;
492     }
493
494     private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
495         Map<String, Operation> operationMap = createMockOperationMap();
496         Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
497         interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "tosca", operationMap));
498         return interfaceDefinitionMap;
499     }
500
501     private InterfaceDefinition createInterface(String uniqueId, String description, String type,
502             String toscaResourceName, Map<String, Operation> op) {
503         InterfaceDefinition id = new InterfaceDefinition();
504         id.setType(type);
505         id.setDescription(description);
506         id.setUniqueId(uniqueId);
507         id.setToscaResourceName(toscaResourceName);
508         id.setOperationsMap(op);
509         return id;
510     }
511
512     @After
513     public void teardown() {
514         GraphTestUtils.clearGraph(janusGraphDao);
515     }
516
517 }