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.jsontitan.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.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.model.Resource;
39 import org.openecomp.sdc.be.model.Service;
40 import org.openecomp.sdc.be.model.Component;
41 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
42 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
43 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElementTypeEnum;
44 import static org.assertj.core.api.Assertions.assertThat;
45 import static org.junit.Assert.assertTrue;
47 @RunWith(MockitoJUnitRunner.class)
48 public class ModelConverterTest {
50 private ModelConverter test;
53 public void testConvertToToscaElementService()
55 Service service = new Service();
56 service.setComponentType(ComponentTypeEnum.SERVICE);
57 TopologyTemplate template = test.convertToToscaElement(service);
58 assertThat(template.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE);
62 public void testConvertToToscaElementResource()
64 Resource resource = new Resource();
65 resource.setComponentType(ComponentTypeEnum.RESOURCE);
66 NodeType nodeType = test.convertToToscaElement(resource);
67 assertThat(nodeType.getToscaType()).isEqualTo(ToscaElementTypeEnum.NODE_TYPE);
71 public void testConvertFromToscaElementService()
73 TopologyTemplate topologyTemplate = new TopologyTemplate();
74 topologyTemplate.setComponentType(ComponentTypeEnum.SERVICE);
75 Component component = test.convertFromToscaElement(topologyTemplate);
76 assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
80 public void testConvertFromToscaElementResource()
82 TopologyTemplate topologyTemplate = new TopologyTemplate();
83 topologyTemplate.setComponentType(ComponentTypeEnum.RESOURCE);
84 Component component = test.convertFromToscaElement(topologyTemplate);
85 assertThat(component.getToscaType()).isEqualTo(ToscaElementTypeEnum.TOPOLOGY_TEMPLATE.getValue());
89 public void testIsAtomicComponent()
91 Resource component = new Resource();
92 component.setComponentType(ComponentTypeEnum.RESOURCE);
93 boolean result = test.isAtomicComponent(component);
98 public void testGetVertexType()
100 VertexTypeEnum result;
101 Resource component = new Resource();
102 component.setComponentType(ComponentTypeEnum.RESOURCE);
103 result = test.getVertexType(component);
104 assertThat(result.getName()).isEqualTo("node_type");