Documentation figure fix
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / utils / InterfaceOperationUtilsTest.java
1 package org.openecomp.sdc.be.components.utils;
2
3 import java.util.Map;
4 import java.util.Optional;
5 import org.junit.Assert;
6 import org.junit.Before;
7 import org.junit.Test;
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;
13
14 public class InterfaceOperationUtilsTest {
15
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;
20
21         @Before
22         public void setup() {
23                 resource = new ResourceBuilder()
24                         .setComponentType(ComponentTypeEnum.RESOURCE)
25                         .setName(TEST_RESOURCE_NAME)
26                         .build();
27                 resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
28         }
29
30         @Test
31         public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess(){
32                 Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
33         }
34
35         @Test
36         public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure(){
37                 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME).isPresent());
38         }
39
40         @Test
41         public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface(){
42                 resource.getInterfaces().clear();
43                 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId).isPresent());
44         }
45
46         @Test
47         public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess(){
48                 Assert.assertTrue(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
49         }
50
51         @Test
52         public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure(){
53                 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME).isPresent());
54         }
55
56         @Test
57         public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface(){
58                 resource.getInterfaces().clear();
59                 Assert.assertFalse(InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId).isPresent());
60         }
61
62         @Test
63         public void testGetOperationFromInterfaceDefinitionSuccess(){
64                 Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
65         }
66
67         @Test
68         public void testGetOperationFromInterfaceDefinitionFailure(){
69                 Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME).isPresent());
70         }
71
72         @Test
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());
78         }
79
80 }