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