Skip to content

Commit

Permalink
Merge branch 'restcomm-1543' of https://github.com/RestComm/Restcomm-…
Browse files Browse the repository at this point in the history
…Connect into restcomm-1543
  • Loading branch information
jaimecasero committed Jan 23, 2018
2 parents a0ef400 + f883fae commit 60763be
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 27 deletions.
Expand Up @@ -6,6 +6,8 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -59,21 +61,21 @@ public class ProfilesEndpointTest extends EndpointTest {
private String authToken = "77f8c12cc7b8f8423e5c38b035249166";

private final String profileSid = "PRafbe225ad37541eba518a74248f0ac4c";
private final String unknownProfileSid = "PRafbe225ad37541eba518a74248f0ac4d";
private final String organizationSid = "ORafbe225ad37541eba518a74248f0ac4c";

@Before
public void before() {
}

/**
* SuperAdmin is allowed to read any profile
* this test will try to Read single profile
*/
@Test
public void getProfile(){
JsonObject profileJsonObject = RestcommProfilesTool.getInstance().getProfile(deploymentUrl.toString(), superAdminAccountSid, authToken, profileSid);
assertNotNull(profileJsonObject);
logger.info("profile: "+profileJsonObject);
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, profileSid);
logger.info("profile: "+clientResponse);
assertEquals(200, clientResponse.getStatus());
// TODO Read and verify further response
}

Expand All @@ -82,12 +84,21 @@ public void getProfile(){
*/
@Test
public void getProfileList(){
JsonArray jsonArray = null;
jsonArray = RestcommProfilesTool.getInstance().getProfileListJsonResponse(deploymentUrl.toString(), superAdminAccountSid, authToken);
logger.info("profile list: "+jsonArray);
assertNotNull(jsonArray);
assertEquals(0,jsonArray.size());
// TODO Add default list in DB script, Read and verify further response
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileListClientResponse(deploymentUrl.toString(), superAdminAccountSid, authToken);
logger.info("profile list: "+clientResponse.getEntity(String.class));
assertNotNull(clientResponse);
assertEquals(200, clientResponse.getStatus());
}

/**
* this test will try to Read single profile with an unknown profile Sid
*/
@Test
@Category(FeatureExpTests.class)
public void getProfileUnknownSid(){
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, unknownProfileSid);
assertNotNull(clientResponse);
assertEquals(404, clientResponse.getStatus());
}

/**
Expand All @@ -108,24 +119,42 @@ public void getProfilePermissionTest(){
}

/**
* createAndUpdateProfileTest
* Create, Read And Update Profile Test
*/
@Test
public void createProfileTest(){
public void createReadAndUpdateProfileTest(){
/*
* create a profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, profileDocument);
logger.info("clientResponse: "+clientResponse);
assertEquals(201, clientResponse.getStatus());
assertEquals(profileDocument, clientResponse.getEntity(String.class));

//extract profileSid of newly created profile Sid.
URI location = clientResponse.getLocation();
assertNotNull(location);
String profileLocation = location.toString();
String[] profileUriElements = profileLocation.split("/");
assertNotNull(profileUriElements);
String newlyCreatedProfileSid = profileUriElements[profileUriElements.length-1];
logger.info("newlyCreatedProfileSid: "+newlyCreatedProfileSid);

/*
* read newly created profile
*/
clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, newlyCreatedProfileSid);
logger.info("profile: "+clientResponse);
assertEquals(200, clientResponse.getStatus());
assertEquals(profileDocument, clientResponse.getEntity(String.class));

/*
* update the profile
*/
//TODO extract profileSid of newly created profile.
clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, profileSid, updatedProfileDocument);
logger.info("clientResponse: "+clientResponse);
clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, newlyCreatedProfileSid, updatedProfileDocument);
logger.info("clientResponse for update: "+clientResponse);
assertEquals(200, clientResponse.getStatus());
assertEquals(updatedProfileDocument, clientResponse.getEntity(String.class));
}

/**
Expand All @@ -151,11 +180,9 @@ public void updateProfileUnknownSidTest(){
/*
* update a profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, profileSid, updatedProfileDocument);
ClientResponse clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, unknownProfileSid, updatedProfileDocument);
logger.info("clientResponse: "+clientResponse);
assertEquals(404, clientResponse.getStatus());

// TODO Read and verify further response
}

/**
Expand Down Expand Up @@ -213,6 +240,20 @@ public void deleteProfilePermissionTest(){
assertEquals(403, clientResponse.getStatus());
}

/**
* deleteProfileUnknownSidTest
*/
@Test
@Category(FeatureExpTests.class)
public void deleteProfileUnknownSidTest(){
/*
* delete a profile with unknown sid
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), superAdminAccountSid, authToken, unknownProfileSid);
logger.info("clientResponse: "+clientResponse);
assertEquals(404, clientResponse.getStatus());
}

@Test
@Category(FeatureExpTests.class)
public void createProfilePermissionTest(){
Expand All @@ -230,9 +271,10 @@ public void createProfilePermissionTest(){
* link/unlink a give Profile To an Account
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
@Test
public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOException{
public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOException, URISyntaxException{
/*
* link a profile to an account
*/
Expand Down Expand Up @@ -278,9 +320,10 @@ public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOExcep
* link/unlink a give Profile To an Organization
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
@Test
public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IOException{
public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IOException, URISyntaxException{
/*
* link a profile to an organizations
*/
Expand Down Expand Up @@ -326,10 +369,11 @@ public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IO
/**
* @throws ClientProtocolException
* @throws IOException
* @throws URISyntaxException
*/
@Test
@Category(FeatureExpTests.class)
public void linkUnLinkProfilePermissionTest() throws ClientProtocolException, IOException{
public void linkUnLinkProfilePermissionTest() throws ClientProtocolException, IOException, URISyntaxException{
/*
* link a profile by admin account
*/
Expand Down
@@ -1,10 +1,11 @@
package org.restcomm.connect.testsuite.http;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.logging.Logger;

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

import org.apache.commons.codec.binary.Base64;
Expand All @@ -26,6 +27,7 @@
import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.header.LinkHeader;

/**
* @author maria farooq
Expand Down Expand Up @@ -284,8 +286,9 @@ public ClientResponse deleteProfileResponse (String deploymentUrl, String operat
* @return
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
public HttpResponse linkProfile (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type) throws ClientProtocolException, IOException {
public HttpResponse linkProfile (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type) throws ClientProtocolException, IOException, URISyntaxException {
String url = getProfilesEndpointUrl(deploymentUrl) + "/" + profileSid;

HttpLink request = new HttpLink(url);
Expand All @@ -307,8 +310,9 @@ public HttpResponse linkProfile (String deploymentUrl, String operatorUsername,
* @return
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
public HttpResponse unLinkProfile (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type) throws ClientProtocolException, IOException {
public HttpResponse unLinkProfile (String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type) throws ClientProtocolException, IOException, URISyntaxException {
String url = getProfilesEndpointUrl(deploymentUrl) + "/" + profileSid;

HttpUnLink request = new HttpUnLink(url);
Expand All @@ -328,16 +332,17 @@ public HttpResponse unLinkProfile (String deploymentUrl, String operatorUsername
* @param targetResourceSid
* @param type
* @return
* @throws URISyntaxException
*/
private HttpRequestBase addLinkUnlinkRequiredHeaders(HttpRequestBase request, String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type){
private HttpRequestBase addLinkUnlinkRequiredHeaders(HttpRequestBase request, String deploymentUrl, String operatorUsername, String operatorAuthtoken, String profileSid, String targetResourceSid, AssociatedResourceType type) throws URISyntaxException{
request.addHeader(getAuthHeader(deploymentUrl, operatorUsername, operatorAuthtoken));
request.addHeader(getjsonAcceptHeader());
request.addHeader(getLinkHeaderOfTargetResource(deploymentUrl, targetResourceSid, type));
return request;
}

private BasicHeader getLinkHeaderOfTargetResource(String deploymentUrl, String targetResourceSid, AssociatedResourceType type){
String targetResourceLinkstr = Link.fromUri(getTargetResourceUrl(deploymentUrl, targetResourceSid, type)).rel(PROFILE_REL_TYPE).build().toString();
private BasicHeader getLinkHeaderOfTargetResource(String deploymentUrl, String targetResourceSid, AssociatedResourceType type) throws URISyntaxException{
String targetResourceLinkstr = LinkHeader.uri(new URI(getTargetResourceUrl(deploymentUrl, targetResourceSid, type))).rel(PROFILE_REL_TYPE).build().toString();
return new BasicHeader("Link", targetResourceLinkstr);
}

Expand Down
Expand Up @@ -29,6 +29,7 @@ CREATE USER SA PASSWORD ""
GRANT DBA TO SA
SET WRITE_DELAY 10
SET SCHEMA PUBLIC
INSERT INTO "restcomm_profiles" VALUES('PR56a4dac6a2ed40bca065fb8f10363532', [B@34a7bb4d, '2018-01-23 13:52:20.011', '2018-01-23 13:52:20.011')
INSERT INTO "restcomm_organizations" VALUES('ORafbe225ad37541eba518a74248f0ac4c', 'default.restcomm.com', '2017-04-19 00:00:00.000000000','2017-04-19 00:00:00.000000000', 'active')
INSERT INTO "restcomm_organizations" VALUES('ORafbe225ad37541eba518a74248f0ac4d', 'org1.restcomm.com', '2017-04-19 00:00:00.000000000','2017-04-19 00:00:00.000000000', 'active')
INSERT INTO "restcomm_organizations" VALUES('ORafbe225ad37541eba518a74248f0ac4e', 'org2.restcomm.com', '2017-04-19 00:00:00.000000000','2017-04-19 00:00:00.000000000', 'closed')
Expand Down

0 comments on commit 60763be

Please sign in to comment.