Skip to content

Commit

Permalink
list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maria Farooq committed Sep 28, 2017
1 parent 7105d24 commit bcd6f51
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ public Account setRole(final String role) {
role, uri, organizationSid);
}

public Account setOrganization(final Sid organizationSid) {
return new Account(sid, dateCreated, DateTime.now(), emailAddress, friendlyName, parentSid, type, status, authToken,
role, uri, organizationSid);
}

public enum Status {
ACTIVE("active"), CLOSED("closed"), SUSPENDED("suspended"), INACTIVE("inactive"), UNINITIALIZED("uninitialized");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.junit.runner.RunWith;
import org.restcomm.connect.commons.Version;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.sun.jersey.api.client.Client;
Expand Down Expand Up @@ -612,12 +614,18 @@ public void testGetAccountsOfASpecificOrganization() {
assertEquals(200, response.getStatus());

//getAccounts with null Filter
response = RestcommAccountsTool.getInstance().getAccountsWithFilterResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, null, null, null);
String responseStr = RestcommAccountsTool.getInstance().getAccountsWithFilterStringResponse(deploymentUrl.toString(), adminUsername, adminAuthToken, null, null);
if(logger.isDebugEnabled())
logger.debug("getAccounts With null Filter Response: "+response);
assertEquals(200, response.getStatus());


logger.debug("getAccounts With null Filter Response: "+responseStr);
//should be 6 accounts
JsonElement jsonElement = new JsonParser().parse(responseStr);
if(jsonElement.isJsonArray()) {
JsonArray accountsArray = jsonElement.getAsJsonArray();
assertEquals(6, accountsArray.size());
} else {
logger.info("JsonElement: " + jsonElement.toString());
Assert.fail();
}
}

@Deployment(name = "ClientsEndpointTest", managed = true, testable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.restcomm.connect.testsuite.http;

import java.util.logging.Logger;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

Expand All @@ -12,8 +14,6 @@
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;

import java.util.logging.Logger;

/**
* @author <a href="mailto:gvagenas@gmail.com">gvagenas</a>
* @author <a href="mailto:lyhungthinh@gmail.com">Thinh Ly</a>
Expand Down Expand Up @@ -181,29 +181,73 @@ public ClientResponse getAccountsResponse (String deploymentUrl, String username
return response;
}

public ClientResponse getAccountsWithFilterResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName, String baseAccount) {
public ClientResponse removeAccountResponse (String deploymentUrl, String operatingUsername, String operatingAuthToken, String removedAccountSid) {
Client jerseyClient = Client.create();
jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken));
jerseyClient.addFilter(new HTTPBasicAuthFilter(operatingUsername, operatingAuthToken));
WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl));

MultivaluedMap<String, String> params = new MultivaluedMapImpl();
if(organizationSid != null && !(organizationSid.trim().isEmpty()))
params.add("OrganizationSid", organizationSid);
if(domainName != null && !(domainName.trim().isEmpty()))
params.add("DomainName", domainName);
if(baseAccount != null && !(baseAccount.trim().isEmpty()))
params.add("BaseAccount", baseAccount);
ClientResponse response = webResource.path(removedAccountSid).delete(ClientResponse.class);
return response;
}

ClientResponse response = webResource.queryParams(params).accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
/**
* @param deploymentUrl
* @param username
* @param authtoken
* @param organizationSid
* @param domainName
* @return
*/
public ClientResponse getAccountsWithFilterClientResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName) {
WebResource webResource = prepareAccountListWebResource(deploymentUrl, username, authtoken);

ClientResponse response = webResource.queryParams(prepareAccountListFilter(organizationSid, domainName))
.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
.get(ClientResponse.class);
return response;
}

public ClientResponse removeAccountResponse (String deploymentUrl, String operatingUsername, String operatingAuthToken, String removedAccountSid) {
/**
* @param deploymentUrl
* @param username
* @param authtoken
* @param organizationSid
* @param domainName
* @return
*/
public String getAccountsWithFilterStringResponse (String deploymentUrl, String username, String authtoken, String organizationSid, String domainName) {
WebResource webResource = prepareAccountListWebResource(deploymentUrl, username, authtoken);

String response = webResource.queryParams(prepareAccountListFilter(organizationSid, domainName))
.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML)
.get(String.class);
return response;
}

/**
* @param deploymentUrl
* @param username
* @param authtoken
* @return
*/
private WebResource prepareAccountListWebResource(String deploymentUrl, String username, String authtoken){
Client jerseyClient = Client.create();
jerseyClient.addFilter(new HTTPBasicAuthFilter(operatingUsername, operatingAuthToken));
jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authtoken));
WebResource webResource = jerseyClient.resource(getAccountsUrl(deploymentUrl));
ClientResponse response = webResource.path(removedAccountSid).delete(ClientResponse.class);
return response;
return webResource;
}

/**
* @param organizationSid
* @param domainName
* @return
*/
private MultivaluedMap<String, String> prepareAccountListFilter(String organizationSid, String domainName){
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
if(organizationSid != null && !(organizationSid.trim().isEmpty()))
params.add("OrganizationSid", organizationSid);
if(domainName != null && !(domainName.trim().isEmpty()))
params.add("DomainName", domainName);

return params;
}
}

0 comments on commit bcd6f51

Please sign in to comment.