use of org.apache.cloudstack.api.response.ConfigurationResponse in project cloudstack by apache.
the class ListCfgCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
Configuration cfg = Mockito.mock(Configuration.class);
listCfgsByCmd._mgr = mgr;
listCfgsByCmd._responseGenerator = responseGenerator;
List<Configuration> configList = new ArrayList<Configuration>();
configList.add(cfg);
Pair<List<? extends Configuration>, Integer> result = new Pair<List<? extends Configuration>, Integer>(configList, 1);
try {
Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result);
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
ConfigurationResponse cfgResponse = new ConfigurationResponse();
cfgResponse.setName("Test case");
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
listCfgsByCmd.execute();
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
}
use of org.apache.cloudstack.api.response.ConfigurationResponse in project cloudstack by apache.
the class ListCfgsByCmd method execute.
@Override
public void execute() {
Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
ListResponse<ConfigurationResponse> response = new ListResponse<ConfigurationResponse>();
List<ConfigurationResponse> configResponses = new ArrayList<ConfigurationResponse>();
for (Configuration cfg : result.first()) {
ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
cfgResponse.setObjectName("configuration");
if (getZoneId() != null) {
cfgResponse.setScope("zone");
}
if (getClusterId() != null) {
cfgResponse.setScope("cluster");
}
if (getStoragepoolId() != null) {
cfgResponse.setScope("storagepool");
}
if (getAccountId() != null) {
cfgResponse.setScope("account");
}
if (getImageStoreId() != null) {
cfgResponse.setScope("imagestore");
}
configResponses.add(cfgResponse);
}
response.setResponses(configResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of org.apache.cloudstack.api.response.ConfigurationResponse in project cloudstack by apache.
the class ApiResponseHelper method createConfigurationResponse.
@Override
public ConfigurationResponse createConfigurationResponse(Configuration cfg) {
ConfigurationResponse cfgResponse = new ConfigurationResponse();
cfgResponse.setCategory(cfg.getCategory());
cfgResponse.setDescription(cfg.getDescription());
cfgResponse.setName(cfg.getName());
cfgResponse.setValue(cfg.getValue());
cfgResponse.setObjectName("configuration");
return cfgResponse;
}
use of org.apache.cloudstack.api.response.ConfigurationResponse in project cloudstack by apache.
the class UpdateCfgCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
Configuration cfg = Mockito.mock(Configuration.class);
updateCfgCmd._configService = configService;
updateCfgCmd._responseGenerator = responseGenerator;
updateCfgCmd.setCfgName("some.cfg");
try {
Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(cfg);
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
ConfigurationResponse response = new ConfigurationResponse();
response.setName("Test case");
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(response);
updateCfgCmd.execute();
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
ConfigurationResponse actualResponse = (ConfigurationResponse) updateCfgCmd.getResponseObject();
Assert.assertEquals(response, actualResponse);
Assert.assertEquals("updateconfigurationresponse", response.getResponseName());
}
use of org.apache.cloudstack.api.response.ConfigurationResponse in project cloudstack by apache.
the class UpdateCfgCmd method execute.
@Override
public void execute() {
if (Strings.isNullOrEmpty(getCfgName())) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Empty configuration name provided");
}
if (getCfgName().equalsIgnoreCase(RoleService.EnableDynamicApiChecker.key())) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Restricted configuration update not allowed");
}
Configuration cfg = _configService.updateConfiguration(this);
if (cfg != null) {
ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg);
response.setResponseName(getCommandName());
if (getZoneId() != null) {
response.setScope("zone");
}
if (getClusterId() != null) {
response.setScope("cluster");
}
if (getStoragepoolId() != null) {
response.setScope("storagepool");
}
if (getAccountId() != null) {
response.setScope("account");
}
response.setValue(value);
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update config");
}
}
Aggregations