2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
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
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
38 import static org.mockito.Mockito.*
40 class DoCreateServiceInstanceTest extends MsoGroovyTest{
41 def prefix = "DCRESI_"
44 public WireMockRule wireMockRule = new WireMockRule(28090)
47 public ExpectedException thrown = ExpectedException.none()
50 void init() throws IOException {
51 super.init("DoCreateServiceInstance")
52 MockitoAnnotations.initMocks(this)
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")
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
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")
82 DoCreateServiceInstance obj = new DoCreateServiceInstance()
83 obj.preProcessRequest(mockExecution)
85 verify(mockExecution).setVariable("prefix", prefix)
86 verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:28080/mso/SDNCAdapterCallbackService")
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)
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)
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)