cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DaanHoogland <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-8687: Prepare template only on...
Date Wed, 05 Aug 2015 10:08:04 GMT
Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/635#discussion_r36286725
  
    --- Diff: server/test/com/cloud/template/TemplateManagerImplTest.java ---
    @@ -18,20 +18,369 @@
     
     package com.cloud.template;
     
    -import org.junit.Test;
     
    +import com.cloud.agent.AgentManager;
    +import com.cloud.api.query.dao.UserVmJoinDao;
    +import com.cloud.dc.dao.DataCenterDao;
    +import com.cloud.domain.dao.DomainDao;
    +import com.cloud.event.dao.UsageEventDao;
     import com.cloud.exception.InvalidParameterValueException;
    +import com.cloud.host.Status;
    +import com.cloud.host.dao.HostDao;
    +import com.cloud.projects.ProjectManager;
    +import com.cloud.storage.StorageManager;
    +import com.cloud.storage.StoragePool;
    +import com.cloud.storage.VMTemplateStoragePoolVO;
    +import com.cloud.storage.VMTemplateStorageResourceAssoc;
    +import com.cloud.storage.VMTemplateVO;
    +import com.cloud.storage.dao.GuestOSDao;
    +import com.cloud.storage.dao.LaunchPermissionDao;
    +import com.cloud.storage.dao.SnapshotDao;
    +import com.cloud.storage.dao.StoragePoolHostDao;
    +import com.cloud.storage.dao.VMTemplateDao;
    +import com.cloud.storage.dao.VMTemplatePoolDao;
    +import com.cloud.storage.dao.VMTemplateZoneDao;
    +import com.cloud.storage.dao.VolumeDao;
    +import com.cloud.user.AccountManager;
    +import com.cloud.user.ResourceLimitService;
    +import com.cloud.user.dao.AccountDao;
    +import com.cloud.utils.component.ComponentContext;
    +import com.cloud.utils.exception.CloudRuntimeException;
    +import com.cloud.vm.dao.UserVmDao;
    +import com.cloud.vm.dao.VMInstanceDao;
    +import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
    +import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
    +import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
    +import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
    +import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
    +import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
    +import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
    +import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
    +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
    +import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
    +import org.apache.cloudstack.framework.messagebus.MessageBus;
    +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
    +import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
    +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
    +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
    +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
    +import org.apache.cloudstack.test.utils.SpringUtils;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.mockito.Mockito;
    +import org.springframework.context.annotation.Bean;
    +import org.springframework.context.annotation.ComponentScan;
    +import org.springframework.context.annotation.Configuration;
    +import org.springframework.context.annotation.FilterType;
    +import org.springframework.core.type.classreading.MetadataReader;
    +import org.springframework.core.type.classreading.MetadataReaderFactory;
    +import org.springframework.core.type.filter.TypeFilter;
    +import org.springframework.test.context.ContextConfiguration;
    +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    +import org.springframework.test.context.support.AnnotationConfigContextLoader;
    +
    +import javax.inject.Inject;
    +import java.io.IOException;
     
    +import static org.junit.Assert.assertTrue;
    +import static org.mockito.Matchers.anyBoolean;
    +import static org.mockito.Matchers.anyLong;
    +import static org.mockito.Mockito.doNothing;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.when;
    +
    +@RunWith(SpringJUnit4ClassRunner.class)
    +@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
     public class TemplateManagerImplTest {
     
    -    TemplateManagerImpl tmgr = new TemplateManagerImpl();
    +    @Inject
    +    TemplateManagerImpl templateManager = new TemplateManagerImpl();
    +
    +    @Inject
    +    DataStoreManager dataStoreManager;
    +
    +    @Inject
    +    VMTemplateDao vmTemplateDao;
    +
    +    @Inject
    +    VMTemplatePoolDao vmTemplatePoolDao;
    +
    +    @Inject
    +    TemplateDataStoreDao templateDataStoreDao;
    +
    +    @Inject
    +    StoragePoolHostDao storagePoolHostDao;
    +
    +    @Before
    +    public void setUp() {
    +        ComponentContext.initComponentsLifeCycle();
    +    }
     
         @Test(expected = InvalidParameterValueException.class)
         public void testVerifyTemplateIdOfSystemTemplate() {
    -        tmgr.verifyTemplateId(1L);
    +        templateManager.verifyTemplateId(1L);
         }
     
         public void testVerifyTemplateIdOfNonSystemTemplate() {
    -        tmgr.verifyTemplateId(1L);
    +        templateManager.verifyTemplateId(1L);
    +    }
    +
    +    @Test
    +    public void testPrepareTemplateIsSeeded() {
    +        VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
    +        when(mockTemplate.getId()).thenReturn(202l);
    +
    +        StoragePoolVO mockPool = mock(StoragePoolVO.class);
    +        when(mockPool.getId()).thenReturn(2l);
    +
    +        PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
    +        when(mockPrimaryDataStore.getId()).thenReturn(2l);
    +
    +        VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
    +        when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
    +
    +        when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
    +        when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
    +        when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
    +
    +        doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
    +
    +        VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate,
(StoragePool) mockPrimaryDataStore);
    --- End diff --
    
    You are testing another method then the ones you changed. Why?
    The test seems to make sense and please keep it but it doesn't test
    prepareTemplate(long templateId, long zoneId, Long storageId)
    or
    prepareTemplateInOneStoragePool(final VMTemplateVO template, final StoragePoolVO pool)
    which are the one you changed and the one you added.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message