Skip to content

Commit

Permalink
body may be read only once
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecasero committed Jan 23, 2018
1 parent 8e9cc09 commit c75973b
Showing 1 changed file with 65 additions and 63 deletions.
Expand Up @@ -44,7 +44,7 @@ public class ProfilesEndpointTest extends EndpointTest {
private final static Logger logger = Logger.getLogger(ProfilesEndpointTest.class.getName());

private static final String version = Version.getVersion();

@ArquillianResource
private Deployer deployer;
@ArquillianResource
Expand All @@ -60,7 +60,7 @@ public class ProfilesEndpointTest extends EndpointTest {
private static final String ORGANIZATION_SID = "ORafbe225ad37541eba518a74248f0ac4c";
private static final String UNKNOWN_ACCOUNT_SID = "AC1111225ad37541eba518a74248f0ac4d";
private static final String UNKNOWN_ORGANIZATION_SID = "OR1111225ad37541eba518a74248f0ac4d";

private static final String PROFILE_DOCUMENT="{ \"featureEnablement\": { \"DIDPurchase\": { \"allowedCountries\": [\"US\", \"CA\"] }, \"destinations\": { \"allowedPrefixes\": [\"+1\"] }, \"outboundPSTN\": { }, \"inboundPSTN\": { }, \"outboundSMS\": { }, \"inboundSMS\": { } }, \"sessionThrottling\": { \"PSTNCallsPerTime\": { \"events\" : 300, \"time\" : 30, \"timeUnit\" : \"days\" } } }";
private static final String UPDATE_PROFILE_DOCUMENT="{ \"featureEnablement\": { \"DIDPurchase\": { \"allowedCountries\": [\"PK\", \"CA\"] }, \"destinations\": { \"allowedPrefixes\": [\"+1\"] }, \"outboundPSTN\": { }, \"inboundPSTN\": { }, \"outboundSMS\": { }, \"inboundSMS\": { } }, \"sessionThrottling\": { \"PSTNCallsPerTime\": { \"events\" : 300, \"time\" : 30, \"timeUnit\" : \"days\" } } }";
private static final String INVALID_PROFILE_DOCUMENT="{ \"featureEnablement\": { \"DIDPurchase\": { \"allowedCountries\": [\"PKeuietue\", \"CA\"] }, \"destinations\": { \"allowedPrefixes\": [\"+1\"] }, \"outboundPSTN\": { }, \"inboundPSTN\": { }, \"outboundSMS\": { }, \"inboundSMS\": { } }, \"sessionThrottling\": { \"PSTNCallsPerTime\": { \"events\" : 300, \"time\" : 30, \"timeUnit\" : \"days\" } } }";
Expand All @@ -75,10 +75,11 @@ public void before() {
@Test
public void getProfile(){
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID);
logger.info("profile: "+clientResponse);
String responseBody = clientResponse.getEntity(String.class)
logger.info("profile: "+responseBody);
assertEquals(200, clientResponse.getStatus());
JsonObject jsonResponse = new JsonParser().parse(clientResponse.getEntity(String.class)).getAsJsonObject();

JsonObject jsonResponse = new JsonParser().parse(responseBody).getAsJsonObject();
assertNotNull(jsonResponse);
}

Expand All @@ -88,11 +89,12 @@ public void getProfile(){
@Test
public void getProfileList() {
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileListClientResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN);
logger.info("profile list: "+clientResponse.getEntity(String.class));
String responseBody = clientResponse.getEntity(String.class)
logger.info("profile list: "+responseBody);
assertNotNull(clientResponse);
assertEquals(200, clientResponse.getStatus());
JsonArray jsonArray = new JsonParser().parse(clientResponse.getEntity(String.class)).getAsJsonArray();

JsonArray jsonArray = new JsonParser().parse(responseBody).getAsJsonArray();
assertNotNull(jsonArray);
assertEquals(1, jsonArray.size());
}
Expand All @@ -117,7 +119,7 @@ public void getProfilePermissionTest(){
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID);
assertNotNull(clientResponse);
assertEquals(403, clientResponse.getStatus());


clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), DEVELOPER_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID);
assertNotNull(clientResponse);
Expand All @@ -131,46 +133,46 @@ public void getProfilePermissionTest(){
@Test
public void createReadUpdateDeleteProfileTest(){
/*
* create a profile
* create a profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, PROFILE_DOCUMENT);
assertEquals(201, clientResponse.getStatus());
assertEquals(PROFILE_DOCUMENT, 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];

/*
* read newly created profile
* read newly created profile
*/
clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid);
assertEquals(200, clientResponse.getStatus());
assertEquals(PROFILE_DOCUMENT, clientResponse.getEntity(String.class));

/*
* update the profile
* update the profile
*/
clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid, UPDATE_PROFILE_DOCUMENT);
assertEquals(200, clientResponse.getStatus());
assertEquals(UPDATE_PROFILE_DOCUMENT, clientResponse.getEntity(String.class));

/*
* delete the profile
* delete the profile
*/
clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid);
assertEquals(200, clientResponse.getStatus());

/*
* read again
* read again
*/
clientResponse = RestcommProfilesTool.getInstance().getProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid);
assertEquals(404, clientResponse.getStatus());

}

/**
Expand All @@ -193,7 +195,7 @@ public void createProfileTestInvalidSchema(){
@Category(FeatureExpTests.class)
public void updateProfileUnknownSidTest(){
/*
* update a profile
* update a profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().updateProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, UNKNOWN_PROFILE_SID, UPDATE_PROFILE_DOCUMENT);
assertEquals(404, clientResponse.getStatus());
Expand Down Expand Up @@ -239,7 +241,7 @@ public void updateDefaultProfileTest(){
@Category(FeatureExpTests.class)
public void deleteDefaultProfileTest(){
/*
* delete default profile
* delete default profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID);
assertEquals(403, clientResponse.getStatus());
Expand Down Expand Up @@ -270,13 +272,13 @@ public void deleteProfilePermissionTest(){
@Category(FeatureExpTests.class)
public void deleteProfileUnknownSidTest(){
/*
* delete a profile with unknown sid
* delete a profile with unknown sid
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, UNKNOWN_PROFILE_SID);
assertEquals(404, clientResponse.getStatus());
}

@Test
@Test
@Category(FeatureExpTests.class)
public void createProfilePermissionTest(){
//admin tries to create profile
Expand All @@ -289,20 +291,20 @@ public void createProfilePermissionTest(){

/**
* link/unlink a give Profile To an Account
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
@Test
public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOException, URISyntaxException{
/*
* link a profile to an account
* link a profile to an account
*/
HttpResponse response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, SUPER_ADMIN_ACCOUNT_SID, RestcommProfilesTool.AssociatedResourceType.ACCOUNT);
logger.info("HttpResponse: "+response);
assertEquals(200, response.getStatusLine().getStatusCode());
/*

/*
* Get associated profile
* from Accounts endpoint:
* to verify association establishment.
Expand All @@ -317,15 +319,15 @@ public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOExcep
assertTrue(linkHeader.getUri().toString().contains(DEFAULT_PROFILE_SID));

/*
* unlink a profile from an account
* unlink a profile from an account
*/
response = RestcommProfilesTool.getInstance().unLinkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, SUPER_ADMIN_ACCOUNT_SID, RestcommProfilesTool.AssociatedResourceType.ACCOUNT);
logger.info("HttpResponse: "+response);
assertEquals(200, response.getStatusLine().getStatusCode());
/*

/*
* Get associated profile
* from Accounts endpoint:
* from Accounts endpoint:
* to verify association removal
*/
accountEndopintResponse = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, SUPER_ADMIN_ACCOUNT_SID);
Expand All @@ -338,20 +340,20 @@ public void linkUnLinkProfileToAccount() throws ClientProtocolException, IOExcep

/**
* link/unlink a give Profile To an Organization
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
*/
@Test
public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IOException, URISyntaxException{
/*
* link a profile to an organizations
* link a profile to an organizations
*/
HttpResponse response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, ORGANIZATION_SID, RestcommProfilesTool.AssociatedResourceType.ORGANIZATION);
logger.info("HttpResponse: "+response);
assertEquals(200, response.getStatusLine().getStatusCode());
/*

/*
* Get associated profile
* from Organizations endpoint:
* to verify association establishment.
Expand All @@ -366,13 +368,13 @@ public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IO
assertTrue(linkHeader.getUri().toString().contains(DEFAULT_PROFILE_SID));

/*
* unlink a profile from an organization
* unlink a profile from an organization
*/
response = RestcommProfilesTool.getInstance().unLinkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, ORGANIZATION_SID, RestcommProfilesTool.AssociatedResourceType.ORGANIZATION);
logger.info("HttpResponse: "+response);
assertEquals(200, response.getStatusLine().getStatusCode());
/*

/*
* Get associated profile
* from Organizations endpoint:
* to verify association removal.
Expand All @@ -384,7 +386,7 @@ public void linkUnLinkProfileToOrganization() throws ClientProtocolException, IO
logger.info("orgEndopintResponse WebResourceLinkHeaders linkHeader: "+linkHeader);
assertNull(linkHeader);
}


/**
* @throws ClientProtocolException
Expand All @@ -405,7 +407,7 @@ public void linkUnLinkProfilePermissionTest() throws ClientProtocolException, IO
response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), DEVELOPER_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, ORGANIZATION_SID, RestcommProfilesTool.AssociatedResourceType.ORGANIZATION);
assertEquals(403, response.getStatusLine().getStatusCode());
}

/**
* @throws ClientProtocolException
* @throws IOException
Expand All @@ -425,7 +427,7 @@ public void linkUnLinkProfileUnknownProfileSidTest() throws ClientProtocolExcept
response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, UNKNOWN_PROFILE_SID, ORGANIZATION_SID, RestcommProfilesTool.AssociatedResourceType.ORGANIZATION);
assertEquals(404, response.getStatusLine().getStatusCode());
}

/**
* @throws ClientProtocolException
* @throws IOException
Expand All @@ -445,7 +447,7 @@ public void linkUnLinkProfileUnknownAccountSidTest() throws ClientProtocolExcept
response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, UNKNOWN_ACCOUNT_SID, RestcommProfilesTool.AssociatedResourceType.ACCOUNT);
assertEquals(404, response.getStatusLine().getStatusCode());
}

/**
* @throws ClientProtocolException
* @throws IOException
Expand All @@ -465,55 +467,55 @@ public void linkUnLinkProfileUnknownOrganizationSidTest() throws ClientProtocolE
response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, DEFAULT_PROFILE_SID, UNKNOWN_ORGANIZATION_SID, RestcommProfilesTool.AssociatedResourceType.ORGANIZATION);
assertEquals(404, response.getStatusLine().getStatusCode());
}

/**
* test removal of association onnce we delete a profile
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
* @throws URISyntaxException
* @throws IOException
* @throws ClientProtocolException
*/
@Test
@Category(FeatureAltTests.class)
public void testRemovalOfAssociationOnDeleteProfile() throws ClientProtocolException, IOException, URISyntaxException{
/*
* create a profile
* create a profile
*/
ClientResponse clientResponse = RestcommProfilesTool.getInstance().createProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, PROFILE_DOCUMENT);
assertEquals(201, clientResponse.getStatus());
assertEquals(PROFILE_DOCUMENT, 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];

/*
* link this profile to an account
* link this profile to an account
*/
HttpResponse response = RestcommProfilesTool.getInstance().linkProfile(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid, ADMIN_ACCOUNT_SID, RestcommProfilesTool.AssociatedResourceType.ACCOUNT);
assertEquals(200, response.getStatusLine().getStatusCode());


/*
* delete the profile
* delete the profile
*/
clientResponse = RestcommProfilesTool.getInstance().deleteProfileResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, newlyCreatedProfileSid);
assertEquals(200, clientResponse.getStatus());
/*

/*
* Get associated profile
* from Accounts endpoint:
* to verify association was removed.
*/
ClientResponse accountEndopintResponse = RestcommAccountsTool.getInstance().getAccountResponse(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN, ADMIN_ACCOUNT_SID);
WebResourceLinkHeaders linkHeaders = accountEndopintResponse.getLinks();
LinkHeader linkHeader = linkHeaders.getLink(RestcommProfilesTool.PROFILE_REL_TYPE);
assertNull(linkHeader);
assertNotNull(linkHeader);
}

@Test
public void getProfileSchemaTest() {
ClientResponse clientResponse = RestcommProfilesTool.getInstance().getProfileSchema(deploymentUrl.toString(), SUPER_ADMIN_ACCOUNT_SID, AUTH_TOKEN);
Expand All @@ -522,12 +524,12 @@ public void getProfileSchemaTest() {

String str = clientResponse.getEntity(String.class);
logger.info("profile schema str: "+str);

JsonObject jsonResponse = new JsonParser().parse(str).getAsJsonObject();
logger.info("jsonResponse: "+jsonResponse);
assertNotNull(jsonResponse);
}

@Deployment(name = "ProfilesEndpointTest", managed = true, testable = false)
public static WebArchive createWebArchiveNoGw() {
logger.info("Packaging Test App");
Expand Down

0 comments on commit c75973b

Please sign in to comment.