use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.
the class ListCfgCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
final Configuration cfg = Mockito.mock(Configuration.class);
listCfgsByCmd._mgr = mgr;
listCfgsByCmd._responseGenerator = responseGenerator;
final List<Configuration> configList = new ArrayList<>();
configList.add(cfg);
final Pair<List<? extends Configuration>, Integer> result = new Pair<>(configList, 1);
try {
Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result);
} catch (final Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
final ConfigurationResponse cfgResponse = new ConfigurationResponse();
cfgResponse.setName("Test case");
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
listCfgsByCmd.execute();
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
final ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
}
use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.
the class ListApisCmd method execute.
@Override
public void execute() throws ServerApiException {
if (_apiDiscoveryService != null) {
final User user = CallContext.current().getCallingUser();
final ListResponse<ApiDiscoveryResponse> response = (ListResponse<ApiDiscoveryResponse>) _apiDiscoveryService.listApis(user, name);
if (response == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Api Discovery plugin was unable to find an api by that name or process any apis");
}
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}
use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.
the class LDAPConfigCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
if (getListAll()) {
// return the existing conf
final LdapListConfigurationCmd listConfigurationCmd = new LdapListConfigurationCmd(_ldapManager);
final Pair<List<? extends LdapConfigurationVO>, Integer> result = _ldapManager.listConfigurations(listConfigurationCmd);
final ListResponse<LDAPConfigResponse> response = new ListResponse<>();
final List<LDAPConfigResponse> responses = new ArrayList<>();
if (result.second() > 0) {
final boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
final String searchBaseConfig = _ldapConfiguration.getBaseDn();
final String bindDnConfig = _ldapConfiguration.getBindPrincipal();
for (final LdapConfigurationVO ldapConfigurationVO : result.first()) {
responses.add(createLDAPConfigResponse(ldapConfigurationVO.getHostname(), ldapConfigurationVO.getPort(), useSSlConfig, null, searchBaseConfig, bindDnConfig));
}
}
response.setResponses(responses);
response.setResponseName(getCommandName());
setResponseObject(response);
} else if (getHostname() == null || getPort() == null) {
throw new InvalidParameterValueException("You need to provide hostname, port to configure your LDAP server");
} else {
final boolean result = updateLDAP();
if (result) {
final LDAPConfigResponse lr = createLDAPConfigResponse(getHostname(), getPort(), getUseSSL(), getQueryFilter(), getSearchBase(), getBindDN());
lr.setResponseName(getCommandName());
setResponseObject(lr);
}
}
}
use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.
the class ApiDiscoveryServiceImpl method listApis.
@Override
public ListResponse<? extends BaseResponse> listApis(final User user, final String name) {
final ListResponse<ApiDiscoveryResponse> response = new ListResponse<>();
final List<ApiDiscoveryResponse> responseList = new ArrayList<>();
if (user == null) {
return null;
}
if (name != null) {
if (!s_apiNameDiscoveryResponseMap.containsKey(name)) {
return null;
}
for (final APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, name);
} catch (final Exception ex) {
s_logger.debug("API discovery access check failed for " + name + " with " + ex.getMessage());
return null;
}
}
responseList.add(s_apiNameDiscoveryResponseMap.get(name));
} else {
for (final String apiName : s_apiNameDiscoveryResponseMap.keySet()) {
boolean isAllowed = true;
for (final APIChecker apiChecker : _apiAccessCheckers) {
try {
apiChecker.checkAccess(user, apiName);
} catch (final Exception ex) {
isAllowed = false;
}
}
if (isAllowed) {
responseList.add(s_apiNameDiscoveryResponseMap.get(apiName));
}
}
}
response.setResponses(responseList);
return response;
}
use of com.cloud.api.response.ListResponse in project cosmic by MissionCriticalCloud.
the class ApiDiscoveryTest method verifyListApis.
@Test
public void verifyListApis() throws Exception {
final ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) s_discoveryService.listApis(testUser, null);
if (responses != null) {
assertTrue("No. of response items > 1", responses.getCount().intValue() == 1);
for (final ApiDiscoveryResponse response : responses.getResponses()) {
assertFalse("API name is empty", response.getName().isEmpty());
assertFalse("API description is empty", response.getDescription().isEmpty());
}
}
}
Aggregations