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