cloudstack-mirror/server/src/test/java/com/cloud/metadata/ResourceMetaDataManagerTest.java
Pearl Dsilva 3f827ef22b
UI: Support to upload resource icons (#5157)
* Resource Icon support - backend

* Add API support for resourceicon

* update reponse params + ui support

* Add exclusive list api for icons and UI changes

* refactor upload view

* UI changes to support resource icon wherever necessary

* convert api to POST + refactor icon view

* Add response name to list API + cosmetic changes in UI

* Added support for the following:
resource icon support for vpcs, networks, domains, and projects
add icons to list view if reosurces support icons to be added
support for showing project icons in the project switching drop-down menu

* List resourceicon cmds to be allowed for user role too
Users to inherit account icon if present (in listUsers response)
Move common code to plugin.js
Add icon to project list view - while switching between projects - Dashboard page
Show icons against zones - Capacity Dashboard view
Show user / account icon at the login button if present

* cosmetic changes

* optimize ui code

* fix reload issue for domain view

* add access check for delete operation

* ui-related changes to show iso icons

* iso image in uservm response

* add icons to custom form's list resources

* some more custom forms aligned to show icon for resources

* conmitic changes + add listing of icons to listdomainchildren cmd

* Add backend/server-side validation for base64 string passed for image

* change preview border

* preselect zone if there's only one

* add default icon

* show icon for network list in deploy vm view

* add custom icons if any to the import-export VM view

* preselect zone persistence on clearing cache

* prevent root vol from inheriting template/iso icon

* show tempalte icon in the info card details

* fix icon not being show on hard-refresh / initial traversal

* fx success message
2021-09-15 00:50:42 -03:00

100 lines
3.7 KiB
Java

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.metadata;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import java.util.Map;
import javax.naming.ConfigurationException;
import com.cloud.server.ResourceManagerUtil;
import org.apache.commons.collections.map.HashedMap;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.server.ResourceTag;
import com.cloud.server.TaggedResourceService;
import com.cloud.storage.dao.VolumeDetailsDao;
import com.cloud.vm.dao.NicDetailsDao;
public class ResourceMetaDataManagerTest {
@Spy
ResourceMetaDataManagerImpl _resourceMetaDataMgr = new ResourceMetaDataManagerImpl();
@Mock
VolumeDetailsDao _volumeDetailDao;
@Mock
NicDetailsDao _nicDetailDao;
@Mock
TaggedResourceService _taggedResourceMgr;
@Mock
ResourceManagerUtil resourceManagerUtil;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
try {
_resourceMetaDataMgr.configure(null, null);
} catch (ConfigurationException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
_resourceMetaDataMgr._volumeDetailDao = _volumeDetailDao;
_resourceMetaDataMgr._taggedResourceMgr = _taggedResourceMgr;
_resourceMetaDataMgr._nicDetailDao = _nicDetailDao;
}
// Test removing details
//@Test
public void testResourceDetails() throws ResourceAllocationException {
//when(_resourceMetaDataMgr.getResourceId(anyString(), eq(ResourceTag.TaggedResourceType.Volume))).thenReturn(1L);
doReturn(1L).when(resourceManagerUtil).getResourceId(anyString(), eq(ResourceTag.ResourceObjectType.Volume));
// _volumeDetailDao.removeDetails(id, key);
doNothing().when(_volumeDetailDao).removeDetail(anyLong(), anyString());
doNothing().when(_nicDetailDao).removeDetail(anyLong(), anyString());
_resourceMetaDataMgr.deleteResourceMetaData(anyString(), eq(ResourceTag.ResourceObjectType.Volume), anyString());
}
// Test adding details
public void testAddResourceDetails() throws ResourceAllocationException {
doReturn(1L).when(resourceManagerUtil).getResourceId("1", ResourceTag.ResourceObjectType.Volume);
// _volumeDetailDao.removeDetails(id, key);
doNothing().when(_volumeDetailDao).removeDetail(anyLong(), anyString());
doNothing().when(_nicDetailDao).removeDetail(anyLong(), anyString());
Map<String, String> map = new HashedMap();
map.put("key", "value");
_resourceMetaDataMgr.addResourceMetaData("1", ResourceTag.ResourceObjectType.Volume, map, true);
}
}