Search in sources :

Example 1 with CreateTemplateCmd

use of com.cloud.api.command.user.template.CreateTemplateCmd in project cosmic by MissionCriticalCloud.

the class TemplateManagerImplTest method testCreatePrivateTemplateRecordForRegionStore.

@Test
public void testCreatePrivateTemplateRecordForRegionStore() throws ResourceAllocationException {
    final CreateTemplateCmd mockCreateCmd = mock(CreateTemplateCmd.class);
    when(mockCreateCmd.getTemplateName()).thenReturn("test");
    when(mockCreateCmd.getTemplateTag()).thenReturn(null);
    when(mockCreateCmd.getBits()).thenReturn(64);
    when(mockCreateCmd.getRequiresHvm()).thenReturn(true);
    when(mockCreateCmd.isPasswordEnabled()).thenReturn(false);
    when(mockCreateCmd.isPublic()).thenReturn(false);
    when(mockCreateCmd.isFeatured()).thenReturn(false);
    when(mockCreateCmd.isDynamicallyScalable()).thenReturn(false);
    when(mockCreateCmd.getVolumeId()).thenReturn(null);
    when(mockCreateCmd.getSnapshotId()).thenReturn(1L);
    when(mockCreateCmd.getOsTypeId()).thenReturn(1L);
    when(mockCreateCmd.getEventDescription()).thenReturn("test");
    when(mockCreateCmd.getDetails()).thenReturn(null);
    final Account mockTemplateOwner = mock(Account.class);
    final SnapshotVO mockSnapshot = mock(SnapshotVO.class);
    when(snapshotDao.findById(anyLong())).thenReturn(mockSnapshot);
    when(mockSnapshot.getVolumeId()).thenReturn(1L);
    when(mockSnapshot.getState()).thenReturn(Snapshot.State.BackedUp);
    when(mockSnapshot.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.template));
    doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.secondary_storage), anyLong());
    final GuestOSVO mockGuestOS = mock(GuestOSVO.class);
    when(guestOSDao.findById(anyLong())).thenReturn(mockGuestOS);
    when(tmpltDao.getNextInSequence(eq(Long.class), eq("id"))).thenReturn(1L);
    final List<ImageStoreVO> mockRegionStores = new ArrayList<>();
    final ImageStoreVO mockRegionStore = mock(ImageStoreVO.class);
    mockRegionStores.add(mockRegionStore);
    when(imgStoreDao.findRegionImageStores()).thenReturn(mockRegionStores);
    when(tmpltDao.persist(any(VMTemplateVO.class))).thenAnswer(new Answer<VMTemplateVO>() {

        @Override
        public VMTemplateVO answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final Object[] args = invocationOnMock.getArguments();
            return (VMTemplateVO) args[0];
        }
    });
    final VMTemplateVO template = templateManager.createPrivateTemplateRecord(mockCreateCmd, mockTemplateOwner);
    assertTrue("Template in a region store should have cross zones set", template.isCrossZones());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) GuestOSVO(com.cloud.storage.GuestOSVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyLong(org.mockito.Matchers.anyLong) CreateTemplateCmd(com.cloud.api.command.user.template.CreateTemplateCmd) ImageStoreVO(com.cloud.storage.datastore.db.ImageStoreVO) Test(org.junit.Test)

Aggregations

CreateTemplateCmd (com.cloud.api.command.user.template.CreateTemplateCmd)1 GuestOSVO (com.cloud.storage.GuestOSVO)1 SnapshotVO (com.cloud.storage.SnapshotVO)1 VMTemplateVO (com.cloud.storage.VMTemplateVO)1 ImageStoreVO (com.cloud.storage.datastore.db.ImageStoreVO)1 Account (com.cloud.user.Account)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1