Search in sources :

Example 1 with StorageService

use of com.cloud.storage.StorageService in project cloudstack by apache.

the class AddSecondaryStorageCmdTest method testExecuteForNullResult.

@Test
public void testExecuteForNullResult() throws Exception {
    StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map) anyObject())).thenReturn(null);
    try {
        addImageStoreCmd.execute();
    } catch (ServerApiException exception) {
        assertEquals("Failed to add secondary storage", exception.getDescription());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageService(com.cloud.storage.StorageService) Test(org.junit.Test)

Example 2 with StorageService

use of com.cloud.storage.StorageService in project cloudstack by apache.

the class AddSecondaryStorageCmdTest method testExecuteForResult.

@Test
public void testExecuteForResult() throws Exception {
    StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    ImageStore store = Mockito.mock(ImageStore.class);
    Mockito.when(resourceService.discoverImageStore(isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(store);
    ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    addImageStoreCmd._responseGenerator = responseGenerator;
    ImageStoreResponse responseHost = new ImageStoreResponse();
    responseHost.setName("Test");
    Mockito.doReturn(responseHost).when(responseGenerator).createImageStoreResponse(store);
    addImageStoreCmd.execute();
    Mockito.verify(responseGenerator).createImageStoreResponse(store);
    ImageStoreResponse actualResponse = (ImageStoreResponse) addImageStoreCmd.getResponseObject();
    assertEquals(responseHost, actualResponse);
    assertEquals("addimagestoreresponse", actualResponse.getResponseName());
}
Also used : ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) ImageStoreResponse(org.apache.cloudstack.api.response.ImageStoreResponse) StorageService(com.cloud.storage.StorageService) ImageStore(com.cloud.storage.ImageStore) Test(org.junit.Test)

Example 3 with StorageService

use of com.cloud.storage.StorageService in project cosmic by MissionCriticalCloud.

the class AddSecondaryStorageCmdTest method testExecuteForNullResult.

@Test
public void testExecuteForNullResult() throws Exception {
    final StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map) anyObject())).thenReturn(null);
    try {
        addImageStoreCmd.execute();
    } catch (final ServerApiException exception) {
        Assert.assertEquals("Failed to add secondary storage", exception.getDescription());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) StorageService(com.cloud.storage.StorageService) Test(org.junit.Test)

Example 4 with StorageService

use of com.cloud.storage.StorageService in project cosmic by MissionCriticalCloud.

the class AddSecondaryStorageCmdTest method testExecuteForResult.

@Test
public void testExecuteForResult() throws Exception {
    final StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    final ImageStore store = Mockito.mock(ImageStore.class);
    Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map) anyObject())).thenReturn(store);
    final ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    addImageStoreCmd._responseGenerator = responseGenerator;
    final ImageStoreResponse responseHost = new ImageStoreResponse();
    responseHost.setName("Test");
    Mockito.when(responseGenerator.createImageStoreResponse(store)).thenReturn(responseHost);
    addImageStoreCmd.execute();
    Mockito.verify(responseGenerator).createImageStoreResponse(store);
    final ImageStoreResponse actualResponse = (ImageStoreResponse) addImageStoreCmd.getResponseObject();
    Assert.assertEquals(responseHost, actualResponse);
    Assert.assertEquals("addimagestoreresponse", actualResponse.getResponseName());
}
Also used : ResponseGenerator(com.cloud.api.ResponseGenerator) ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) StorageService(com.cloud.storage.StorageService) ImageStore(com.cloud.storage.ImageStore) Test(org.junit.Test)

Aggregations

StorageService (com.cloud.storage.StorageService)4 Test (org.junit.Test)4 ImageStore (com.cloud.storage.ImageStore)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 ServerApiException (com.cloud.api.ServerApiException)1 ImageStoreResponse (com.cloud.api.response.ImageStoreResponse)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ImageStoreResponse (org.apache.cloudstack.api.response.ImageStoreResponse)1