Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / InterfaceOperationUtilsTest.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.components.utils;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Optional;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.model.InterfaceDefinition;
33 import org.openecomp.sdc.be.model.Operation;
34 import org.openecomp.sdc.be.model.Resource;
35 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
36
37 public class InterfaceOperationUtilsTest {
38
39     private static final String TEST_RESOURCE_NAME = "TestResource";
40     private static final String operationId = "operationId";
41     private static final String operationName = "createOperation";
42     private static final String interfaceId = "interfaceId";
43     private static final String operationId1 = "operationId1";
44     private static final String interfaceId1 = "interfaceId1";
45     private static Resource resource;
46
47     @Before
48     public void setup() {
49         resource =
50                 new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setName(TEST_RESOURCE_NAME).build();
51         resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
52                 operationName));
53     }
54
55     @Test
56     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess() {
57         Assert.assertTrue(
58                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
59                         .isPresent());
60     }
61
62     @Test
63     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure() {
64         Assert.assertFalse(
65                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME)
66                         .isPresent());
67     }
68
69     @Test
70     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface() {
71         resource.getInterfaces().clear();
72         Assert.assertFalse(
73                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
74                         .isPresent());
75     }
76
77     @Test
78     public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess() {
79         Assert.assertTrue(
80                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
81                         .isPresent());
82     }
83
84     @Test
85     public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure() {
86         Assert.assertFalse(
87                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME)
88                         .isPresent());
89     }
90
91     @Test
92     public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface() {
93         resource.getInterfaces().clear();
94         Assert.assertFalse(
95                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
96                         .isPresent());
97     }
98
99     @Test
100     public void testGetOperationFromInterfaceDefinitionSuccess() {
101         Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
102                 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), operationId).isPresent());
103     }
104
105     @Test
106     public void testGetOperationFromInterfaceDefinitionFailure() {
107         Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
108                 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), TEST_RESOURCE_NAME)
109                                    .isPresent());
110     }
111
112     @Test
113     public void testGetOperationFromInterfaceDefinitionNoOperationMap() {
114         InterfaceDefinition interfaceDefinition =
115                 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName);
116         interfaceDefinition.getOperations().clear();
117         Optional<Map.Entry<String, Operation>> operationEntry =
118                 InterfaceOperationUtils.getOperationFromInterfaceDefinition(interfaceDefinition, TEST_RESOURCE_NAME);
119         Assert.assertFalse(operationEntry.isPresent());
120     }
121
122     @Test
123     public void testGetInterfaceDefinitionFromOperationIdSuccess() {
124         List<InterfaceDefinition> interfaces = new ArrayList<>();
125         interfaces.add(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName));
126         interfaces.add(InterfaceOperationTestUtils.createMockInterface(interfaceId1, operationId1, operationName));
127         Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromOperationId(interfaces, operationId)
128                                   .isPresent());
129     }
130
131     @Test
132     public void testGetInterfaceDefinitionFromOperationIdFailure() {
133         List<InterfaceDefinition> interfaces = new ArrayList<>();
134         interfaces.add(InterfaceOperationTestUtils.createMockInterface(interfaceId1, operationId1, operationName));
135         Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromOperationId(interfaces, operationId)
136                                   .isPresent());
137     }
138
139     @Test
140     public void testGetInterfaceDefinitionFromOperationIdFailureInterfacesEmpty() {
141         List<InterfaceDefinition> interfaces = new ArrayList<>();
142         Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromOperationId(interfaces, operationId)
143                                    .isPresent());
144     }
145
146     @Test
147     public void testIsArtifactInUse() {
148         Assert.assertTrue(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId"));
149         Assert.assertFalse(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId1"));
150     }
151
152     @Test
153     public void testCreateMappedCapabilityPropertyDefaultValue() {
154         Assert.assertTrue(!InterfaceOperationUtils
155                 .createMappedCapabilityPropertyDefaultValue("capName", "propName").isEmpty());
156     }
157
158 }