Springboot 2.0 upgrade
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / groovy / org / onap / so / bpmn / infrastructure / scripts / DoCreateServiceInstanceTest.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.infrastructure.scripts
22
23 import com.github.tomakehurst.wiremock.junit.WireMockRule
24 import org.camunda.bpm.engine.delegate.BpmnError
25 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
26 import org.junit.Before
27 import org.junit.Rule
28 import org.junit.Test
29 import org.junit.rules.ExpectedException
30 import org.mockito.MockitoAnnotations
31 import org.onap.so.bpmn.common.scripts.MsoGroovyTest
32 import org.onap.so.bpmn.core.domain.ModelInfo
33 import org.onap.so.bpmn.core.domain.ServiceDecomposition
34 import org.onap.so.bpmn.core.domain.ServiceInstance
35 import org.onap.so.bpmn.mock.StubResponseAAI
36 import org.onap.so.client.aai.entities.uri.AAIResourceUri
37
38 import static org.mockito.Mockito.*
39
40 class DoCreateServiceInstanceTest extends MsoGroovyTest{
41     def prefix = "DCRESI_"
42
43     @Rule
44     public WireMockRule wireMockRule = new WireMockRule(28090)
45
46     @Rule
47     public ExpectedException thrown = ExpectedException.none()
48
49     @Before
50     void init() throws IOException {
51         super.init("DoCreateServiceInstance")
52         MockitoAnnotations.initMocks(this)
53     }
54
55     @Test
56     void testPreProcessRequest() {
57         ExecutionEntity mockExecution = setupMock()
58         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
59         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
60         when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
61         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
62         when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("MDTWNJ21")
63         when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
64         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:28080/mso/SDNCAdapterCallbackService")
65         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
66         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("MSO-dev-service-type")
67         when(mockExecution.getVariable("productFamilyId")).thenReturn("RDM2WAGPLCP")
68         when(mockExecution.getVariable("sdnc.si.svc.types")).thenReturn("PORT-MIRROR,PPROBES")
69
70         ServiceDecomposition decomposition = new ServiceDecomposition()
71         ModelInfo modelInfo = new ModelInfo()
72         ServiceInstance instance = new ServiceInstance()
73         instance.instanceId = "12345"
74         decomposition.modelInfo = modelInfo
75         decomposition.serviceInstance = instance
76
77         when(mockExecution.getVariable("serviceDecomposition")).thenReturn(decomposition)
78         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
79         when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
80
81
82         DoCreateServiceInstance obj = new DoCreateServiceInstance()
83         obj.preProcessRequest(mockExecution)
84
85         verify(mockExecution).setVariable("prefix", prefix)
86         verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:28080/mso/SDNCAdapterCallbackService")
87     }
88
89
90
91     @Test
92     void testGetAAICustomerById() {
93         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
94         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
95         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
96         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
97         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
98         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
99         StubResponseAAI.MockGetCustomer("12345", "")
100         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
101         when(obj.getAAIClient()).thenReturn(client)
102         when(client.exists(isA(AAIResourceUri.class))).thenReturn(true)
103         obj.getAAICustomerById(mockExecution)
104     }
105
106     @Test
107     void testGetAAICustomerById_NoCustFound() {
108         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
109         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
110         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
111         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
112         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
113         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
114         StubResponseAAI.MockGetCustomer("12345", "")
115         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
116         when(obj.getAAIClient()).thenReturn(client)
117         when(client.exists(isA(AAIResourceUri.class))).thenReturn(false)
118         thrown.expect(BpmnError.class)
119         obj.getAAICustomerById(mockExecution)
120     }
121
122     @Test
123     void testGetAAICustomerById_Exception() {
124         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
125         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
126         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
127         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
128         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
129         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
130         StubResponseAAI.MockGetCustomer("12345", "")
131         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
132         when(obj.getAAIClient()).thenReturn(client)
133         when(client.exists(isA(AAIResourceUri.class))).thenThrow(Exception.class)
134         thrown.expect(Exception.class)
135         obj.getAAICustomerById(mockExecution)
136     }
137 }