Search in sources :

Example 6 with ResponseGenerator

use of org.apache.cloudstack.api.ResponseGenerator in project cloudstack by apache.

the class ScaleVMCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    UserVm userVm = Mockito.mock(UserVm.class);
    try {
        Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(userVm);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    scaleVMCmd._responseGenerator = responseGenerator;
    UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    //List<UserVmResponse> list = Mockito.mock(UserVmResponse.class);
    //list.add(userVmResponse);
    //LinkedList<UserVmResponse> mockedList = Mockito.mock(LinkedList.class);
    //Mockito.when(mockedList.get(0)).thenReturn(userVmResponse);
    List<UserVmResponse> list = new LinkedList<UserVmResponse>();
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    scaleVMCmd._userVmService = userVmService;
    scaleVMCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) ExpectedException(org.junit.rules.ExpectedException) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with ResponseGenerator

use of org.apache.cloudstack.api.ResponseGenerator in project cloudstack by apache.

the class AddClusterCmdTest method testExecuteForResult.

@Test
public void testExecuteForResult() throws Exception {
    resourceService = Mockito.mock(ResourceService.class);
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    addClusterCmd._resourceService = resourceService;
    addClusterCmd._responseGenerator = responseGenerator;
    Cluster cluster = Mockito.mock(Cluster.class);
    Cluster[] clusterArray = new Cluster[] { cluster };
    Mockito.doReturn(Arrays.asList(clusterArray)).when(resourceService).discoverCluster(addClusterCmd);
    addClusterCmd.execute();
}
Also used : ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) ResourceService(com.cloud.resource.ResourceService) Cluster(com.cloud.org.Cluster) Test(org.junit.Test)

Example 8 with ResponseGenerator

use of org.apache.cloudstack.api.ResponseGenerator in project cloudstack by apache.

the class UpdateCfgCmdTest method setUp.

@Override
@Before
public void setUp() {
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    configService = Mockito.mock(ConfigurationService.class);
    updateCfgCmd = new UpdateCfgCmd();
}
Also used : ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) UpdateCfgCmd(org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd) ConfigurationService(com.cloud.configuration.ConfigurationService) Before(org.junit.Before)

Example 9 with ResponseGenerator

use of org.apache.cloudstack.api.ResponseGenerator in project cloudstack by apache.

the class UpdateVmNicIpTest method testSuccess.

@Test
public void testSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    UserVmService userVmService = Mockito.mock(UserVmService.class);
    updateVmNicIpCmd = Mockito.mock(UpdateVmNicIpCmd.class);
    UserVm userVm = Mockito.mock(UserVm.class);
    Mockito.when(userVmService.updateNicIpForVirtualMachine(Mockito.any(UpdateVmNicIpCmd.class))).thenReturn(userVm);
    updateVmNicIpCmd._userVmService = userVmService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    List<UserVmResponse> list = new LinkedList<UserVmResponse>();
    UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
    list.add(userVmResponse);
    Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
    updateVmNicIpCmd._responseGenerator = responseGenerator;
    updateVmNicIpCmd.execute();
}
Also used : UserVm(com.cloud.uservm.UserVm) UserVmService(com.cloud.vm.UserVmService) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with ResponseGenerator

use of org.apache.cloudstack.api.ResponseGenerator in project cloudstack by apache.

the class AddIpToVmNicTest method testCreateSuccess.

@Test
public void testCreateSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    NetworkService networkService = Mockito.mock(NetworkService.class);
    AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
    NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class);
    Mockito.when(networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.anyString())).thenReturn(secIp);
    ipTonicCmd._networkService = networkService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class);
    Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres);
    ipTonicCmd._responseGenerator = responseGenerator;
    ipTonicCmd.execute();
}
Also used : NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) AddIpToVmNicCmd(org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) NetworkService(com.cloud.network.NetworkService) Test(org.junit.Test)

Aggregations

ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)11 Test (org.junit.Test)7 Before (org.junit.Before)4 ResourceService (com.cloud.resource.ResourceService)3 ManagementService (com.cloud.server.ManagementService)2 UserVm (com.cloud.uservm.UserVm)2 UserVmService (com.cloud.vm.UserVmService)2 LinkedList (java.util.LinkedList)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)2 ExpectedException (org.junit.rules.ExpectedException)2 ConfigurationService (com.cloud.configuration.ConfigurationService)1 NetworkService (com.cloud.network.NetworkService)1 Cluster (com.cloud.org.Cluster)1 ImageStore (com.cloud.storage.ImageStore)1 Snapshot (com.cloud.storage.Snapshot)1 StorageService (com.cloud.storage.StorageService)1 VolumeApiService (com.cloud.storage.VolumeApiService)1 Account (com.cloud.user.Account)1 AccountService (com.cloud.user.AccountService)1