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.common.scripts
23 import org.junit.rules.ExpectedException
25 import static org.mockito.Mockito.*
27 import javax.ws.rs.NotFoundException
29 import org.camunda.bpm.engine.delegate.BpmnError
30 import org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity
31 import org.junit.Before
34 import org.mockito.ArgumentCaptor
35 import org.mockito.Captor
36 import org.mockito.MockitoAnnotations
37 import org.mockito.Spy
38 import org.onap.so.client.aai.AAIObjectType
39 import org.onap.so.client.aai.entities.uri.AAIResourceUri
40 import org.onap.so.client.aai.entities.uri.AAIUriFactory
41 import org.onap.aai.domain.yang.VfModule
43 import com.github.tomakehurst.wiremock.junit.WireMockRule
45 class UpdateAAIVfModuleTest extends MsoGroovyTest {
46 def prefix = "UAAIVfMod_"
49 public ExpectedException thrown = ExpectedException.none();
51 UpdateAAIVfModule updateAAIVfModule;
54 static ArgumentCaptor<ExecutionEntity> captor = ArgumentCaptor.forClass(ExecutionEntity.class)
57 void init() throws IOException {
58 super.init("UpdateAAIVfModule")
59 when(updateAAIVfModule.getAAIClient()).thenReturn(client)
63 void testGetVfModule() {
64 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
65 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
66 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
67 VfModule vfModule = new VfModule()
68 vfModule.setVfModuleId("supercool")
69 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "skask", "supercool");
70 when(client.get(VfModule.class,resourceUri)).thenReturn(Optional.of(vfModule))
71 updateAAIVfModule.getVfModule(mockExecution)
72 verify(mockExecution).setVariable(prefix + "getVfModuleResponseCode", 200)
73 verify(mockExecution).setVariable(prefix + "getVfModuleResponse", vfModule)
77 void testGetVfModuleNotFound() {
78 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
79 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
80 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
81 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "skask", "supercool");
82 when(client.get(VfModule.class,resourceUri)).thenReturn(Optional.empty())
83 updateAAIVfModule.getVfModule(mockExecution)
84 verify(mockExecution).setVariable(prefix + "getVfModuleResponseCode", 404)
85 verify(mockExecution).setVariable(prefix + "getVfModuleResponse", "VF Module not found in AAI")
89 void testGetVfModuleException() {
90 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
91 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
92 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
93 AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "skask", "supercool");
94 when(client.get(VfModule.class,resourceUri)).thenThrow(new NullPointerException("Error from AAI client"))
95 updateAAIVfModule.getVfModule(mockExecution)
96 verify(mockExecution).setVariable(prefix + "getVfModuleResponseCode", 500)
97 verify(mockExecution).setVariable(prefix + "getVfModuleResponse", "AAI GET Failed:"+"Error from AAI client")
102 void testUpdateVfModule() {
103 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
104 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
105 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
106 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
107 VfModule vfModule = new VfModule()
108 vfModule.setVfModuleId("supercool")
109 vfModule.setResourceVersion("12345")
110 when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule)
111 doNothing().when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject())
112 updateAAIVfModule.updateVfModule(mockExecution)
113 verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 200)
117 void testUpdateVfModuleNotFound() throws BpmnError {
118 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
119 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
120 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
121 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
122 VfModule vfModule = new VfModule()
123 vfModule.setVfModuleId("supercool")
124 vfModule.setResourceVersion("12345")
125 when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule)
126 doThrow(new NotFoundException("Vf Module not found")).when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject())
127 thrown.expect(BpmnError.class)
128 updateAAIVfModule.updateVfModule(mockExecution)
129 verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 404)
134 void testUpdateVfModuleException() {
135 when(mockExecution.getVariable("prefix")).thenReturn(prefix)
136 when(mockExecution.getVariable("isDebugLogEnabled")).thenReturn("true")
137 when(mockExecution.getVariable(prefix + "vnfId")).thenReturn("skask")
138 when(mockExecution.getVariable(prefix + "vfModuleId")).thenReturn("supercool")
139 VfModule vfModule = new VfModule()
140 vfModule.setVfModuleId("supercool")
141 vfModule.setResourceVersion("12345")
142 when(mockExecution.getVariable(prefix + "getVfModuleResponse")).thenReturn(vfModule)
143 doThrow(new IllegalStateException("Error in AAI client")).when(client).update(isA(AAIResourceUri.class) as AAIResourceUri, anyObject())
144 thrown.expect(BpmnError.class)
145 updateAAIVfModule.updateVfModule(mockExecution)
146 verify(mockExecution).setVariable("UAAIVfMod_updateVfModuleResponseCode", 500)