2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright 2018 TechMahindra
\r
6 *=================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.openstack.utils;
\r
23 import static org.junit.Assert.assertNotNull;
\r
24 import static org.junit.Assert.assertNull;
\r
25 import static org.junit.Assert.assertTrue;
\r
26 import static org.mockito.Mockito.doReturn;
\r
27 import static org.mockito.Mockito.mock;
\r
29 import java.util.HashMap;
\r
30 import java.util.Map;
\r
31 import org.junit.Assert;
\r
32 import org.junit.Test;
\r
33 import org.junit.runner.RunWith;
\r
34 import org.mockito.Mock;
\r
35 import org.openecomp.mso.cloud.CloudIdentity;
\r
36 import org.openecomp.mso.cloud.CloudSite;
\r
37 import org.openecomp.mso.openstack.beans.MsoTenant;
\r
38 import org.openecomp.mso.openstack.exceptions.MsoException;
\r
39 import org.openecomp.mso.properties.MsoJavaProperties;
\r
40 import org.powermock.api.mockito.PowerMockito;
\r
41 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
42 import org.powermock.modules.junit4.PowerMockRunner;
\r
44 import com.woorea.openstack.keystone.Keystone;
\r
45 import com.woorea.openstack.keystone.model.Tenant;
\r
47 //@RunWith(PowerMockRunner.class)
\r
48 @PrepareForTest({MsoKeystoneUtils.class,CloudSite.class,CloudIdentity.class,Tenant.class,Keystone.class,MsoTenant.class,MsoJavaProperties.class})
\r
49 public class MsoKeystoneUtilsTest {
\r
55 Keystone adminClient;
\r
64 CloudIdentity cloudIdentity;
\r
67 MsoJavaProperties msoProps;
\r
70 public void testcreateTenant() throws MsoException{
\r
71 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
72 Map<String,String>metadata=new HashMap<>();
\r
73 metadata.put("1", "value");
\r
74 tenant = mock(Tenant.class);
\r
75 PowerMockito.when(tenant.getId ()).thenReturn("ID");
\r
76 doReturn(tenant.getId ()).when(msk).createTenant("tenantName", "cloudSiteId", metadata, true);
\r
77 PowerMockito.spy(tenant.getId ());
\r
78 String Id = msk.createTenant("tenantName", "cloudSiteId", metadata, true);
\r
79 Assert.assertEquals(tenant.getId (), Id);
\r
80 assert(msk.createTenant("tenantName", "cloudSiteId", metadata, true)!=null);
\r
83 public void testdeleteTenant() throws MsoException{
\r
84 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
85 doReturn(true).when(msk).deleteTenant("tenantId", "cloudSiteId");
\r
86 assertTrue(msk.deleteTenant("tenantId", "cloudSiteId"));
\r
89 public void testfindTenantByName() throws Exception{
\r
90 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
91 doReturn(null).when(msk).findTenantByName(adminClient, "tenantName");
\r
92 assertNull(msk.findTenantByName(adminClient, "tenantName"));
\r
95 public void testqueryTenant() throws MsoException{
\r
96 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
97 Map<String,String>metadata=new HashMap<>();
\r
98 metadata.put("1", "value");
\r
99 mst = mock(MsoTenant.class);
\r
100 PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
\r
101 PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
\r
102 PowerMockito.when(mst.getTenantName()).thenReturn("name");
\r
103 doReturn(mst).when(msk).queryTenant ("tenantId", "cloudSiteId");
\r
104 assertNotNull(msk.queryTenant("tenantId", "cloudSiteId"));
\r
108 public void testqueryTenantByName()throws MsoException {
\r
109 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
110 Map<String,String>metadata=new HashMap<>();
\r
111 metadata.put("1", "value");
\r
112 mst = mock(MsoTenant.class);
\r
113 PowerMockito.when(mst.getTenantId()).thenReturn("tenantId");
\r
114 PowerMockito.when(mst.getMetadata()).thenReturn(metadata);
\r
115 PowerMockito.when(mst.getTenantName()).thenReturn("name");
\r
116 doReturn(mst).when(msk).queryTenantByName ("tenantId", "cloudSiteId");
\r
117 assertNotNull(msk.queryTenantByName("tenantId", "cloudSiteId"));
\r
122 public void testgetKeystoneAdminClient() throws MsoException{
\r
123 cloudIdentity = mock(CloudIdentity.class);
\r
124 Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl ("region", "msoPropID"));
\r
125 MsoKeystoneUtils msk = PowerMockito.spy(new MsoKeystoneUtils("ID"));
\r
126 doReturn(keystone).when(msk).getKeystoneAdminClient(cs);
\r
127 assertNotNull(msk.getKeystoneAdminClient(cs));
\r