Springboot 2.0 upgrade
[so.git] / bpmn / MSOCommonBPMN / src / test / groovy / org / onap / so / bpmn / common / scripts / AaiUtilTest.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 com.github.tomakehurst.wiremock.junit.WireMockRule
24
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.*
27
28 import org.onap.so.rest.HttpHeader
29 import org.mockito.MockitoAnnotations
30 import org.mockito.runners.MockitoJUnitRunner
31 import org.mockito.internal.debugging.MockitoDebuggerImpl
32 import org.junit.Before
33 import org.onap.so.bpmn.common.scripts.AaiUtil;
34 import org.junit.Rule;
35 import org.junit.Test
36 import org.junit.rules.ExpectedException
37 import org.junit.Ignore
38 import org.junit.runner.RunWith
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.camunda.bpm.engine.ProcessEngineServices
42 import org.camunda.bpm.engine.RepositoryService
43 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
44 import org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl
45 import org.camunda.bpm.engine.repository.ProcessDefinition
46
47 class AaiUtilTest extends MsoGroovyTest {
48
49
50         @Rule
51         public WireMockRule wireMockRule = new WireMockRule(8090);
52
53         @Rule
54         public ExpectedException thrown = ExpectedException.none()
55
56
57         def aaiPaylod = "<allotted-resource xmlns=\"http://org.openecomp.aai.inventory/v9\">\n" +
58                         "\t\t\t\t<id>allottedResourceId</id>\n" +
59                         "\t\t\t\t<description></description>\n" +
60                         "\t\t\t\t<type>allottedResourceType</type>\n" +
61                         "\t\t\t\t<role>allottedResourceRole</role>\n" +
62                         "\t\t\t\t<selflink></selflink>\n" +
63                         "\t\t\t\t<model-invariant-id></model-invariant-id>\n" +
64                         "\t\t\t\t<model-version-id></model-version-id>\n" +
65                         "\t\t\t\t<model-customization-id></model-customization-id>\n" +
66                         "\t\t\t\t<orchestration-status>PendingCreate</orchestration-status>\n" +
67                         "\t\t\t\t<operation-status></operation-status>\n" +
68                         "\t\t\t\t<relationship-list>\n" +
69                         "\t\t\t\t\t<relationship>\n" +
70                         "               \t\t\t<related-to>service-instance</related-to>\n" +
71                         "               \t\t\t<related-link>CSI_resourceLink</related-link>\n" +
72                         "\t\t\t\t\t</relationship>\n" +
73                         "\t\t\t\t</relationship-list>\n" +
74                         "\t\t\t</allotted-resource>";
75
76         @Test
77         public void testGetVersionDefault() {
78                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
79                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
80                 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
81
82                 CreateAAIVfModule myproc = new CreateAAIVfModule()
83                 AaiUtil aaiUtil = new AaiUtil(myproc)
84                 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
85                 assertEquals('8', version)
86         }
87
88         @Test
89         public void testGetVersionResourceSpecific() {
90                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
91                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
92                 when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7')
93                 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
94                 CreateAAIVfModule myproc = new CreateAAIVfModule()
95                 AaiUtil aaiUtil = new AaiUtil(myproc)
96                 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
97                 assertEquals('7', version)
98         }
99
100         @Test
101         public void testGetVersionFlowSpecific() {
102                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
103                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
104                 when(mockExecution.getVariable("mso.workflow.custom.CreateAAIVfModule.aai.version")).thenReturn('6')
105                 when(mockExecution.getVariable("mso.workflow.default.aai.l3-network.version")).thenReturn('7')
106
107                 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('8')
108
109                 CreateAAIVfModule myproc = new CreateAAIVfModule()
110                 AaiUtil aaiUtil = new AaiUtil(myproc)
111                 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
112                 assertEquals('6', version)
113         }
114
115         @Test
116         public void testGetVersionNotDefined() {
117                 thrown.expect(Exception.class)
118                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
119                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
120                 CreateAAIVfModule myproc = new CreateAAIVfModule()
121                 AaiUtil aaiUtil = new AaiUtil(myproc)
122                 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn("")
123
124                 def version = aaiUtil.getVersion(mockExecution, 'l3-network', 'CreateAAIVfModule')
125
126         }
127
128         @Test
129         @Ignore
130         public void testExecuteAAIGetCall() {
131                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
132                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
133                 when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3")
134                 when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f")
135                 CreateAAIVfModule myproc = new CreateAAIVfModule()
136                 AaiUtil aaiUtil = new AaiUtil(myproc)
137                 def uri = aaiUtil.executeAAIGetCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId")
138         }
139
140
141         @Test
142         @Ignore
143         public void testExecuteAAIPutCall() {
144                 ExecutionEntity mockExecution = setupMock('CreateAAIVfModule')
145                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
146                 when(mockExecution.getVariable("aai.auth")).thenReturn("9B2278E8B8E95F256A560719055F4DF3")
147                 when(mockExecution.getVariable("mso.msoKey")).thenReturn("aa3871669d893c7fb8abbcda31b88b4f")
148                 CreateAAIVfModule myproc = new CreateAAIVfModule()
149                 AaiUtil aaiUtil = new AaiUtil(myproc)
150                 def uri = aaiUtil.executeAAIPutCall(mockExecution,"http://localhost:8090/aai/v9/business/customers/customer/CUST/service-subscriptions/service-subscription/SVC/service-instances/service-instance/NST/allotted-resources/allotted-resource/allottedResourceId",aaiPaylod)
151         }
152
153         @Test
154         public void testGetNamespaceFromUri_twoArguments() {  // (execution, uri)
155                 ExecutionEntity mockExecution = setupMock('DeleteVfModuleVolumeInfraV1')
156                 //
157                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
158                 when(mockExecution.getVariable("mso.workflow.global.default.aai.version")).thenReturn('10')
159                 when(mockExecution.getVariable("mso.workflow.default.aai.v10.l3-network.uri")).thenReturn('/aai/v10/network/l3-networks/l3-network')
160                 when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn('http://org.openecomp.aai.inventory/')
161                 //
162                 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn('true')
163                 CreateAAIVfModule myproc = new CreateAAIVfModule()
164                 AaiUtil aaiUtil = new AaiUtil(myproc)
165                 def ns = aaiUtil.getNamespaceFromUri(mockExecution, '/aai/v10/search/generic-query')
166                 assertEquals('http://org.openecomp.aai.inventory/v10', ns)
167         }
168 }