Interface operation feature enhancements
[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 =
24                 new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setName(TEST_RESOURCE_NAME).build();
25         resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId));
26     }
27
28     @Test
29     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeSuccess() {
30         Assert.assertTrue(
31                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
32                         .isPresent());
33     }
34
35     @Test
36     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeFailure() {
37         Assert.assertFalse(
38                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, TEST_RESOURCE_NAME)
39                         .isPresent());
40     }
41
42     @Test
43     public void testGetInterfaceDefinitionFromComponentByInterfaceTypeNoInterface() {
44         resource.getInterfaces().clear();
45         Assert.assertFalse(
46                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(resource, interfaceId)
47                         .isPresent());
48     }
49
50     @Test
51     public void testGetInterfaceDefinitionFromComponentByInterfaceIdSuccess() {
52         Assert.assertTrue(
53                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
54                         .isPresent());
55     }
56
57     @Test
58     public void testGetInterfaceDefinitionFromComponentByInterfaceIdFailure() {
59         Assert.assertFalse(
60                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, TEST_RESOURCE_NAME)
61                         .isPresent());
62     }
63
64     @Test
65     public void testGetInterfaceDefinitionFromComponentByInterfaceIdNoInterface() {
66         resource.getInterfaces().clear();
67         Assert.assertFalse(
68                 InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceId(resource, interfaceId)
69                         .isPresent());
70     }
71
72     @Test
73     public void testGetOperationFromInterfaceDefinitionSuccess() {
74         Assert.assertTrue(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
75                 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), operationId).isPresent());
76     }
77
78     @Test
79     public void testGetOperationFromInterfaceDefinitionFailure() {
80         Assert.assertFalse(InterfaceOperationUtils.getOperationFromInterfaceDefinition(
81                 InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId), TEST_RESOURCE_NAME)
82                                    .isPresent());
83     }
84
85     @Test
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());
93     }
94
95 }