3 * Copyright (c) 2018 Huawei Intellectual Property.
7 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
27 * limitations under the License.
30 package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.InjectMocks;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
37 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
38 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
39 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
40 import org.openecomp.sdc.be.model.Resource;
41 import org.openecomp.sdc.be.model.Service;
42 import org.openecomp.sdc.be.model.Component;
43 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
44 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
45 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum;
49 import static org.assertj.core.api.Assertions.assertThat;
50 import static org.junit.Assert.assertSame;
51 import static org.junit.Assert.assertTrue;
53 @RunWith(MockitoJUnitRunner.class)
54 public class ModelConverterTest {
56 private ModelConverter test;
59 public void testConvertToToscaElementService()
61 Service service = new Service();
62 service.setComponentType(ComponentTypeEnum.SERVICE);
63 TopologyTemplate template = test.convertToToscaElement(service);
64 assertThat(template.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE);
68 public void testConvertToToscaElementResource()
70 Resource resource = new Resource();
71 resource.setComponentType(ComponentTypeEnum.RESOURCE);
72 NodeType nodeType = test.convertToToscaElement(resource);
73 assertThat(nodeType.getToscaType()).isEqualTo(ToscaElementTypeEnum.NODE_TYPE);
77 public void testConvertFromToscaElementService()
79 TopologyTemplate topologyTemplate = new TopologyTemplate();
80 topologyTemplate.setComponentType(ComponentTypeEnum.SERVICE);
81 Component component = test.convertFromToscaElement(topologyTemplate);
82 assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
86 public void testConvertFromToscaElementServiceWithSelfCapabilities()
88 TopologyTemplate topologyTemplate = new TopologyTemplate();
90 Map<String, MapPropertiesDataDefinition> capabilitiesProperties = CapabilityTestUtils
91 .createCapPropsForTopologyTemplate(topologyTemplate);
93 topologyTemplate.setCapabilitiesProperties(capabilitiesProperties);
95 topologyTemplate.setComponentType(ComponentTypeEnum.SERVICE);
96 Component component = test.convertFromToscaElement(topologyTemplate);
97 assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
101 public void testConvertFromToscaElementResource()
103 TopologyTemplate topologyTemplate = new TopologyTemplate();
104 topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
105 Component component = test.convertFromToscaElement(topologyTemplate);
106 assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
110 public void testConvertFromToscaElementResourceType()
112 TopologyTemplate topologyTemplate = new TopologyTemplate();
113 topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
114 topologyTemplate.setResourceType(ResourceTypeEnum.PNF);
115 Resource resource = test.convertFromToscaElement(topologyTemplate);
116 assertSame(ResourceTypeEnum.PNF, resource.getResourceType());
120 public void testIsAtomicComponent()
122 Resource component = new Resource();
123 component.setComponentType(ComponentTypeEnum.RESOURCE);
124 boolean result = test.isAtomicComponent(component);
129 public void testGetVertexType()
131 VertexTypeEnum result;
132 Resource component = new Resource();
133 component.setComponentType(ComponentTypeEnum.RESOURCE);
134 result = test.getVertexType(component);
135 assertThat(result.getName()).isEqualTo("node_type");