2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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.openstack.utils;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.so.StubOpenStack;
27 import org.onap.so.BaseTest;
28 import org.onap.so.openstack.beans.MsoTenant;
29 import org.onap.so.openstack.exceptions.MsoException;
30 import org.springframework.beans.factory.annotation.Autowired;
32 import java.io.IOException;
33 import java.util.HashMap;
35 public class MsoKeystoneUtilsTest extends BaseTest {
38 private MsoKeystoneUtils msoKeystoneUtils;
41 public void before() throws IOException {
42 StubOpenStack.mockOpenStackResponseAccess(wireMockPort);
46 public void createTenantTest() throws Exception {
47 StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
49 StubOpenStack.mockOpenStackGetUserById("john");
50 StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
51 String response = msoKeystoneUtils.createTenant("tenant", "MTN13", new HashMap<>(), true);
53 Assert.assertEquals("tenantId", response);
57 public void createTenantTest_FindUserByName() throws Exception {
58 StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
60 StubOpenStack.mockOpenStackGetUserByName("john");
61 StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
62 String response = msoKeystoneUtils.createTenant("tenant", "MTN13", new HashMap<>(), true);
63 Assert.assertEquals("tenantId", response);
68 public void createTenantTest_Exception() throws Exception {
69 expectedException.expect(MsoException.class);
70 StubOpenStack.mockOpenStackPostTenantWithBodyFile_200();
71 StubOpenStack.mockOpenStackGetUserByName_500("john");
72 StubOpenStack.mockOpenStackGetRoles_200("OS-KSADM");
73 msoKeystoneUtils.createTenant("tenant", "Test", new HashMap<>(), true);
77 public void queryTenantTest() throws Exception {
78 StubOpenStack.mockOpenStackGetTenantById("tenantId");
80 MsoTenant msoTenant = msoKeystoneUtils.queryTenant("tenantId", "MTN13");
82 Assert.assertEquals("testingTenantName", msoTenant.getTenantName());
86 public void queryTenantByNameTest() throws Exception {
87 StubOpenStack.mockOpenStackGetTenantByName("tenant");
89 MsoTenant msoTenant = msoKeystoneUtils.queryTenantByName("tenant", "MTN13");
91 Assert.assertEquals("testingTenantName", msoTenant.getTenantName());
95 public void deleteTenantTest() throws Exception {
96 StubOpenStack.mockOpenStackGetTenantById("tenantId");
97 StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId");
98 boolean result = msoKeystoneUtils.deleteTenant("tenantId", "MTN13");
100 Assert.assertTrue(result);
104 public void deleteTenantByNameTest() throws Exception {
105 StubOpenStack.mockOpenStackGetTenantByName("tenant");
106 StubOpenStack.mockOpenStackDeleteTenantById_200("tenantId");
107 boolean result = msoKeystoneUtils.deleteTenantByName("tenant", "MTN13");
109 Assert.assertTrue(result);