Containerization feature of SO
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / NetworkUtilsTest.groovy
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
4  * ================================================================================ 
5  * Copyright (C) 2017 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.so.bpmn.common.scripts
22
23 import org.junit.Before
24 import org.mockito.MockitoAnnotations
25
26 import static org.mockito.Mockito.*
27 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
28 import static org.junit.Assert.*;
29 import org.junit.Test;
30
31 class NetworkUtilsTest {
32
33         def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema">
34    <request-info>
35       <action>CREATE_VF_MODULE_VOL</action>
36       <source>VID</source>
37       <service-instance-id/>
38    </request-info>
39    <volume-inputs>
40       <volume-group-id/>
41       <volume-group-name>MSOTESTVOL101a-vSAMP12_base_vol_module-0</volume-group-name>
42       <vnf-type>Test/vSAMP12</vnf-type>
43       <vf-module-model-name>vSAMP12::base::module-0</vf-module-model-name>
44       <asdc-service-model-version>2.0</asdc-service-model-version>
45       <aic-cloud-region>mdt1</aic-cloud-region>
46       <tenant-id>88a6ca3ee0394ade9403f075db23167e</tenant-id>
47       <service-id>a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb</service-id>
48       <backout-on-failure></backout-on-failure>
49    </volume-inputs>
50    <volume-params>
51       <param name="vnf_name">STMTN5MMSC20</param>
52       <param name="vnf_name2">US1117MTSNJVBR0246</param>
53     </volume-params>
54 </volume-request>"""
55
56
57         @Test
58         public void testIsRollbackEnabled() {
59                 
60                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
61                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
62                 when(mockExecution.getVariable("mso.rollback")).thenReturn(true)
63
64                 NetworkUtils networkUtils = new NetworkUtils()
65                 def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml)
66                 
67                 assertEquals(true, rollbackEnabled)
68
69         }
70         
71         @Test
72         public void testIsRollbackEnabled2() {
73                 
74                 ExecutionEntity mockExecution = mock(ExecutionEntity.class)
75                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
76                 when(mockExecution.getVariable("mso.rollback")).thenReturn(false)
77
78                 NetworkUtils networkUtils = new NetworkUtils()
79                 def rollbackEnabled = networkUtils.isRollbackEnabled(mockExecution, volumeRequestXml)
80                 
81                 assertEquals(false, rollbackEnabled)
82
83         }
84
85         @Test
86         public void testGetIpvVersion() {
87                 
88                 NetworkUtils networkUtils = new NetworkUtils()
89                 println "test: ipv4"
90                 String version4 = networkUtils.getIpvVersion("ipv4")
91                 assertEquals("4", version4)
92                 println "test: ipv6"
93                 String version6 = networkUtils.getIpvVersion("ipv6")
94                 assertEquals("6", version6)
95                 println "test: 4"
96                 String versionDigit4 = networkUtils.getIpvVersion("4")
97                 assertEquals("4", versionDigit4)
98
99         }
100         
101 }