1 package org.openecomp.sdc.be.components.utils;
4 import java.util.Optional;
5 import org.junit.Assert;
6 import org.junit.Before;
8 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
9 import org.openecomp.sdc.be.model.InterfaceDefinition;
10 import org.openecomp.sdc.be.model.Operation;
11 import org.openecomp.sdc.be.model.Resource;
12 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
14 public class InterfaceOperationUtilsTest {
16 private static final String TEST_RESOURCE_NAME = "TestResource";
17 private static final String operationId = "operationId";
18 private static final String interfaceId = "interfaceId";
19 private static Resource resource;
24 new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setName(TEST_RESOURCE_NAME).build();
25 resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
29 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess() {
31 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
36 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure() {
38 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME)
43 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface() {
44 resource.getInterfaces().clear();
46 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
51 public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess() {
53 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
58 public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure() {
60 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME)
65 public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface() {
66 resource.getInterfaces().clear();
68 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
73 public void testGetOperationFromInterfaceDefinitionSuccess() {
74 Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
75 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
79 public void testGetOperationFromInterfaceDefinitionFailure() {
80 Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
81 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME)
86 public void testGetOperationFromInterfaceDefinitionNoOperationMap() {
87 InterfaceDefinition interfaceDefinition =
88 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId);
89 interfaceDefinition.getOperations().clear();
90 Optional<Map.Entry<String, Operation>> operationEntry =
91 InterfaceOperationUtils.getOperationFromInterfaceDefinition(interfaceDefinition, TEST_RESOURCE_NAME);
92 Assert.assertFalse(operationEntry.isPresent());