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;
23 resource = new ResourceBuilder()
24 .setComponentType(ComponentTypeEnum.RESOURCE)
25 .setName(TEST_RESOURCE_NAME)
27 resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
31 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess(){
32 Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
36 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure(){
37 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME).isPresent());
41 public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface(){
42 resource.getInterfaces().clear();
43 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
47 public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess(){
48 Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
52 public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure(){
53 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME).isPresent());
57 public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface(){
58 resource.getInterfaces().clear();
59 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
63 public void testGetOperationFromInterfaceDefinitionSuccess(){
64 Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
68 public void testGetOperationFromInterfaceDefinitionFailure(){
69 Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME).isPresent());
73 public void testGetOperationFromInterfaceDefinitionNoOperationMap(){
74 InterfaceDefinition interfaceDefinition = InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId);
75 interfaceDefinition.getOperations().clear();
76 Optional<Map.Entry<String, Operation>> operationEntry = InterfaceOperationUtils.getOperationFromInterfaceDefinition(interfaceDefinition, TEST_RESOURCE_NAME);
77 Assert.assertFalse(operationEntry.isPresent());