a22fd1186dab40defac06c619cc916baaa0e4be4
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / ToscaParserInterfaceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc-tosca
4  * ================================================================================
5  * Copyright (C) 2017 - 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.sdc.impl;
22
23 import static org.testng.Assert.assertEquals;
24 import static org.testng.Assert.assertNotNull;
25
26 import java.util.List;
27 import java.util.Map;
28 import org.mockito.internal.util.collections.Sets;
29 import org.onap.sdc.toscaparser.api.NodeTemplate;
30 import org.onap.sdc.toscaparser.api.elements.InterfacesDef;
31 import org.testng.annotations.BeforeClass;
32 import org.testng.annotations.Test;
33
34 public class ToscaParserInterfaceTest extends SdcToscaParserBasicTest {
35
36     List<NodeTemplate> vfs;
37
38     @BeforeClass
39     public void setup(){
40         vfs = csarHelperVfInterfaces.getServiceVfList();
41     }
42
43     @Test
44     public void testGetInterfaceOf() {
45         Map<String, List<InterfacesDef>> interfaceDetails = csarHelperVfInterfaces.getInterfacesOf(vfs.get(0));
46         assertNotNull(interfaceDetails);
47         assertEquals(interfaceDetails.size(), 2);
48     }
49
50     @Test
51     public void testGetInterfaces() {
52         List<String> interfaceNames = csarHelperVfInterfaces.getInterfaces(vfs.get(0));
53         assertNotNull(interfaceNames);
54         assertEquals(interfaceNames, Sets.newSet("org.openecomp.interfaces.node.lifecycle.CxVnf1", "tosca.interfaces.node.lifecycle.Standard"));
55     }
56
57     @Test
58     public void testGetInterfaceDetails() {
59         List<InterfacesDef> interfaceDetails = csarHelperVfInterfaces.getInterfaceDetails(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1");
60         assertNotNull(interfaceDetails);
61         assertEquals(interfaceDetails.get(0).getOperationName(), "instantiate");
62         assertEquals(interfaceDetails.get(1).getOperationName(), "upgrade");
63     }
64
65     @Test
66     public void testGetAllInterfaceOperations() {
67         List<String> operations = csarHelperVfInterfaces.getAllInterfaceOperations(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1");
68         assertNotNull(operations);
69         assertEquals(operations, Sets.newSet("instantiate", "upgrade", "create", "configure", "start", "stop", "delete"));
70     }
71
72     @Test
73     public void testGetInterfaceOperationDetails() {
74         InterfacesDef interfaceDef = csarHelperVfInterfaces.getInterfaceOperationDetails(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1", "instantiate");
75         assertNotNull(interfaceDef);
76         assertEquals(interfaceDef.getOperationName(), "instantiate");
77     }
78
79     @Test
80     public void testGetInterfaceOperationImplementationDetails() {
81         InterfacesDef interfaceDef = csarHelperVfInterfaces.getInterfaceOperationDetails(vfs.get(0), "org.openecomp.interfaces.node.lifecycle.CxVnf1", "upgrade");
82         assertNotNull(interfaceDef);
83         assertNotNull(interfaceDef.getImplementation());
84         assertEquals(((Map)interfaceDef.getImplementation()).get("primary"), "Artifacts/Deployment/WORKFLOW/CreateWorkFlow.json");
85         assertEquals(((Map)interfaceDef.getImplementation()).get("dependencies"), "TestDependency1");
86     }
87
88 }