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 ExpectedException thrown = ExpectedException.none()
 
  47     void init() throws IOException {
 
  48         super.init("DoCreateServiceInstance")
 
  49         MockitoAnnotations.initMocks(this)
 
  53     void testPreProcessRequest() {
 
  54         ExecutionEntity mockExecution = setupMock()
 
  55         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
 
  56         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
 
  57         when(mockExecution.getVariable("msoRequestId")).thenReturn("12345")
 
  58         when(mockExecution.getVariable("serviceInstanceId")).thenReturn("MIS/1604/0026/SW_INTERNET")
 
  59         when(mockExecution.getVariable("lcpCloudRegionId")).thenReturn("MDTWNJ21")
 
  60         when(mockExecution.getVariable("mso-request-id")).thenReturn("testRequestId-1503410089303")
 
  61         when(mockExecution.getVariable("mso.workflow.sdncadapter.callback")).thenReturn("http://localhost:28080/mso/SDNCAdapterCallbackService")
 
  62         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("MSO_dev")
 
  63         when(mockExecution.getVariable("subscriptionServiceType")).thenReturn("MSO-dev-service-type")
 
  64         when(mockExecution.getVariable("productFamilyId")).thenReturn("RDM2WAGPLCP")
 
  65         when(mockExecution.getVariable("sdnc.si.svc.types")).thenReturn("PORT-MIRROR,PPROBES")
 
  67         ServiceDecomposition decomposition = new ServiceDecomposition()
 
  68         ModelInfo modelInfo = new ModelInfo()
 
  69         ServiceInstance instance = new ServiceInstance()
 
  70         instance.instanceId = "12345"
 
  71         decomposition.modelInfo = modelInfo
 
  72         decomposition.serviceInstance = instance
 
  74         when(mockExecution.getVariable("serviceDecomposition")).thenReturn(decomposition)
 
  75         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
 
  76         when(mockExecution.getVariable("mso.workflow.default.aai.customer.version")).thenReturn("8")
 
  79         DoCreateServiceInstance obj = new DoCreateServiceInstance()
 
  80         obj.preProcessRequest(mockExecution)
 
  82         verify(mockExecution).setVariable("prefix", prefix)
 
  83         verify(mockExecution).setVariable("sdncCallbackUrl", "http://localhost:28080/mso/SDNCAdapterCallbackService")
 
  89     void testGetAAICustomerById() {
 
  90         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
 
  91         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
 
  92         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
 
  93         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
 
  94         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
 
  95         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
 
  96         StubResponseAAI.MockGetCustomer("12345", "")
 
  97         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
 
  98         when(obj.getAAIClient()).thenReturn(client)
 
  99         when(client.exists(isA(AAIResourceUri.class))).thenReturn(true)
 
 100         obj.getAAICustomerById(mockExecution)
 
 104     void testGetAAICustomerById_NoCustFound() {
 
 105         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
 
 106         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
 
 107         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
 
 108         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
 
 109         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
 
 110         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
 
 111         StubResponseAAI.MockGetCustomer("12345", "")
 
 112         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
 
 113         when(obj.getAAIClient()).thenReturn(client)
 
 114         when(client.exists(isA(AAIResourceUri.class))).thenReturn(false)
 
 115         thrown.expect(BpmnError.class)
 
 116         obj.getAAICustomerById(mockExecution)
 
 120     void testGetAAICustomerById_Exception() {
 
 121         when(mockExecution.getVariable("prefix")).thenReturn(prefix)
 
 122         when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
 
 123         when(mockExecution.getVariable("globalSubscriberId")).thenReturn("12345")
 
 124         when(mockExecution.getVariable("aai.endpoint")).thenReturn("http://localhost:28090")
 
 125         when(mockExecution.getVariable("mso.workflow.global.default.aai.namespace")).thenReturn("http://org.openecomp.aai.inventory/")
 
 126         when(mockExecution.getVariable("mso.workflow.custom.DoCreateServiceInstance.aai.version")).thenReturn('8')
 
 127         StubResponseAAI.MockGetCustomer("12345", "")
 
 128         DoCreateServiceInstance obj = spy(DoCreateServiceInstance.class)
 
 129         when(obj.getAAIClient()).thenReturn(client)
 
 130         when(client.exists(isA(AAIResourceUri.class))).thenThrow(Exception.class)
 
 131         thrown.expect(Exception.class)
 
 132         obj.getAAICustomerById(mockExecution)