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.namingservice.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.InjectMocks;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
38 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
39 import org.onap.so.client.exception.BBObjectNotFoundException;
41 public class NamingServiceCreateTasksTest extends BaseTaskTest {
43 private NamingServiceCreateTasks namingServiceCreateTasks = new NamingServiceCreateTasks();
45 private InstanceGroup instanceGroup;
48 public void before() throws BBObjectNotFoundException {
49 instanceGroup = setInstanceGroup();
50 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID), any())).thenReturn(instanceGroup);
54 public void createInstanceGroupTest() throws Exception {
55 String policyInstanceName = "policyInstanceName";
56 String nfNamingCode = "nfNamingCode";
57 String generatedName = "generatedInstanceGroupName";
58 execution.setVariable(policyInstanceName, policyInstanceName);
59 execution.setVariable(nfNamingCode, nfNamingCode);
60 doReturn(generatedName).when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
62 namingServiceCreateTasks.createInstanceGroupName(execution);
63 verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
64 assertEquals(instanceGroup.getInstanceGroupName(), generatedName);
68 public void createInstanceGroupExceptionTest() throws Exception {
69 expectedException.expect(BBObjectNotFoundException.class);
70 lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, "notfound");
71 doThrow(BBObjectNotFoundException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.INSTANCE_GROUP_ID),eq("notfound"));
72 String policyInstanceName = "policyInstanceName";
73 String nfNamingCode = "nfNamingCode";
74 execution.setVariable(policyInstanceName, policyInstanceName);
75 execution.setVariable(nfNamingCode, nfNamingCode);
76 doReturn("").when(namingServiceResources).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);
77 namingServiceCreateTasks.createInstanceGroupName(execution);
78 verify(namingServiceResources, times(1)).generateInstanceGroupName(instanceGroup, policyInstanceName, nfNamingCode);