2 * ============LICENSE_START=======================================================
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
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.components.utils;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.Optional;
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;
37 public class InterfaceOperationUtilsTest {
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;
50 new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setName(TEST_RESOURCE_NAME).build();
51 resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
56 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess() {
58 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
63 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure() {
65 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME)
70 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface() {
71 resource.getInterfaces().clear();
73 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
78 public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess() {
80 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
85 public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure() {
87 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME)
92 public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface() {
93 resource.getInterfaces().clear();
95 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
100 public void testGetOperationFromInterfaceDefinitionSuccess() {
101 Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
102 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), operationId).isPresent());
106 public void testGetOperationFromInterfaceDefinitionFailure() {
107 Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
108 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName), TEST_RESOURCE_NAME)
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());
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)
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)
140 public void testGetInterfaceDefinitionFromOperationIdFailureInterfacesEmpty() {
141 List<InterfaceDefinition> interfaces = new ArrayList<>();
142 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromOperationId(interfaces, operationId)
147 public void testIsArtifactInUse() {
148 Assert.assertTrue(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId"));
149 Assert.assertFalse(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId1"));
153 public void testCreateMappedCapabilityPropertyDefaultValue() {
154 Assert.assertTrue(!InterfaceOperationUtils
155 .createMappedCapabilityPropertyDefaultValue("capName", "propName").isEmpty());