AT&T 1712 and 1802 release code
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / openecomp / mso / apihandlerinfra / tenantisolation / helpers / AAIClientHelperTest.java
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.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27
28 import static org.mockito.Mockito.when;
29 import static org.mockito.Mockito.spy;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.any;
33 import static org.mockito.Mockito.eq;
34 import static org.mockito.Mockito.doThrow;
35
36
37 import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed;
38 import org.openecomp.mso.apihandlerinfra.tenantisolation.mock.MockTest;
39 import org.openecomp.mso.client.aai.AAIResourcesClient;
40 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
41 import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
42
43
44 public class AAIClientHelperTest extends MockTest {
45     
46         @Mock private AAIResourcesClient aaiResourceClientMock;
47         private AAIClientHelper clientHelper;
48         
49         @Before
50         public void testSetUp() {
51                 MockitoAnnotations.initMocks(this);
52                 AAIClientHelper aaiHelper  = new AAIClientHelper();
53                 clientHelper = spy(aaiHelper);
54                 when(clientHelper.getClient()).thenReturn(aaiResourceClientMock);
55         }
56         
57         @Test
58         public void testGetAaiOperationalEnvironmentSuccess() throws Exception { 
59                 clientHelper.getAaiOperationalEnvironment("123");
60                 verify(aaiResourceClientMock, times(1)).get(any(AAIResourceUri.class));
61         }
62         
63         @Test(expected = AAIClientCallFailed.class) 
64         public void testGetAaiOperationalEnvironmentRainyDay() throws Exception {
65                 when(aaiResourceClientMock.get(any(AAIResourceUri.class))).thenThrow(new RuntimeException());
66                 clientHelper.getAaiOperationalEnvironment("123");
67         }
68         
69         @Test
70         public void testCreateOperationalEnvironmentSuccess() throws Exception { 
71                 AAIOperationalEnvironment env = AAIClientObjectBuilder.createAAIOperationalEnvironment("123", "Test Env", "ECOMP", "ACTIVE", "Test", "PVT");
72                 clientHelper.createOperationalEnvironment(env);
73                 verify(aaiResourceClientMock, times(1)).create(any(AAIResourceUri.class), eq(env));
74         }
75         
76         @Test(expected = AAIClientCallFailed.class) 
77         public void testCreateOperationalEnvironmentRainyDay() throws Exception { 
78                 AAIOperationalEnvironment env = AAIClientObjectBuilder.createAAIOperationalEnvironment("123", "Test Env", "ECOMP", "ACTIVE", "Test", "PVT");
79                 doThrow(RuntimeException.class).when(aaiResourceClientMock).create(any(AAIResourceUri.class), eq(env));
80                 clientHelper.createOperationalEnvironment(env);
81         }
82         
83         @Test
84         public void testCreateRelationshipSuccess() throws Exception { 
85                 clientHelper.createRelationship("VOE-001", "MEOE-002");
86                 verify(aaiResourceClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
87         }
88         
89         @Test(expected = AAIClientCallFailed.class) 
90         public void testCreateRelationshipRainyDay() throws Exception { 
91                 doThrow(RuntimeException.class).when(aaiResourceClientMock).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
92                 clientHelper.createRelationship("VOE-001", "MEOE-002");
93         }
94 }