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.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
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;
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;
44 public class AAIClientHelperTest extends MockTest {
46 @Mock private AAIResourcesClient aaiResourceClientMock;
47 private AAIClientHelper clientHelper;
50 public void testSetUp() {
51 MockitoAnnotations.initMocks(this);
52 AAIClientHelper aaiHelper = new AAIClientHelper();
53 clientHelper = spy(aaiHelper);
54 when(clientHelper.getClient()).thenReturn(aaiResourceClientMock);
58 public void testGetAaiOperationalEnvironmentSuccess() throws Exception {
59 clientHelper.getAaiOperationalEnvironment("123");
60 verify(aaiResourceClientMock, times(1)).get(any(AAIResourceUri.class));
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");
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));
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);
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));
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");