Skip to content

Commit

Permalink
Merge branch 'restcomm1220' of https://github.com/RestComm/Restcomm-C…
Browse files Browse the repository at this point in the history
…onnect into restcomm1220
  • Loading branch information
jaimecasero committed Feb 14, 2018
2 parents 6985817 + a8339f0 commit e009dc2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
Expand Up @@ -736,8 +736,8 @@ private void sendRVDStatusNotification(Account updatedAccount) {
*
* @param account
*/
private void switchAccountStatus(Account account) {
switch (account.getStatus()) {
private void switchAccountStatus(Account account, Account.Status status) {
switch (status) {
case CLOSED:
sendRVDStatusNotification(account);
// then proceed to dependency removal
Expand All @@ -747,8 +747,8 @@ private void switchAccountStatus(Account account) {
break;

}
// finally, set account status to closed.
account = account.setStatus(Account.Status.CLOSED);
// finally, set and persist account status
account = account.setStatus(status);
accountsDao.updateAccount(account);
}

Expand All @@ -768,15 +768,15 @@ private void switchAccountStatusTree(Account parentAccount) {
String removedSid = subAccountsToSwitch.get(i);
try {
Account subAccount = accountsDao.getAccount(new Sid(removedSid));
switchAccountStatus(subAccount);
switchAccountStatus(subAccount, parentAccount.getStatus());
} catch (Exception e) {
// if anything bad happens, log the error and continue removing the rest of the accounts.
logger.error("Failed switching status (child) account '" + removedSid + "'");
}
}
}
// close parent account too
switchAccountStatus(parentAccount);
// switch parent account too
switchAccountStatus(parentAccount, parentAccount.getStatus());
}

private void validate(final MultivaluedMap<String, String> data) throws NullPointerException {
Expand Down
Expand Up @@ -686,6 +686,75 @@ public void testGetAccountsOfASpecificOrganization() {
assertEquals(1, accountsArray.size());
}

@Test
public void testUpdateAccountStatusSuspended() {
final String sidMaster = "ACbdf00000000000000000000000000000";
final String sidChild1 = "ACbdf00000000000000000000000000001";
final String sidChild2 = "ACbdf00000000000000000000000000002";
final String sidGrandchild1 = "ACbdf00000000000000000000000000011";
final String sidGrandchild2 = "ACbdf00000000000000000000000000012";
//final String sidGreatGrandchild1 = "ACbdf00000000000000000000000000111";
//final String sidGreatGrandchild2 = "ACbdf00000000000000000000000000112";

//change master account status to suspended
JsonObject updateAccountResponse = RestcommAccountsTool.getInstance().updateAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidMaster, null, null, null, null, "suspended" );

//collect data from account tree to check status replication
JsonObject getAccountResponse1 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidChild1);
JsonObject getAccountResponse2 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidChild2);
JsonObject getAccountResponse3 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidGrandchild1);
JsonObject getAccountResponse4 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidGrandchild2);
//JsonObject getAccountResponse5 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
// adminUsername, adminAuthToken, sidGreatGrandchild1);
//JsonObject getAccountResponse6 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
// adminUsername, adminAuthToken, sidGreatGrandchild2);

//check master account status
assertEquals("Master account status is not updated", "suspended", updateAccountResponse.get("status").getAsString());

//check account tree status
assertEquals("Child 1 account status is not updated", "suspended", getAccountResponse1.get("status").getAsString());
assertEquals("Child 2 account status is not updated", "suspended", getAccountResponse2.get("status").getAsString());
assertEquals("Grandchild 1 account status is not updated", "suspended", getAccountResponse3.get("status").getAsString());
assertEquals("Grandchild 2 account status is not updated", "suspended", getAccountResponse4.get("status").getAsString());
//assertEquals("Great-grandchild 1 account status is not updated", "suspended", getAccountResponse5.get("status").getAsString());
//assertEquals("Great-grandchild 2 account status is not updated", "suspended", getAccountResponse6.get("status").getAsString());

//revert master account status to active
updateAccountResponse = RestcommAccountsTool.getInstance().updateAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidMaster, null, null, null, null, "active" );

//collect data from account tree to check status replication
getAccountResponse1 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidChild1);
getAccountResponse2 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidChild2);
getAccountResponse3 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidGrandchild1);
getAccountResponse4 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
adminUsername, adminAuthToken, sidGrandchild2);
//getAccountResponse5 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
// adminUsername, adminAuthToken, sidGreatGrandchild1);
//getAccountResponse6 = RestcommAccountsTool.getInstance().getAccount(deploymentUrl.toString(),
// adminUsername, adminAuthToken, sidGreatGrandchild2);

//check master account status
assertEquals("Master account status is not updated", "active", updateAccountResponse.get("status").getAsString());

//check account tree status
assertEquals("Child 1 account status is not updated", "active", getAccountResponse1.get("status").getAsString());
assertEquals("Child 2 account status is not updated", "active", getAccountResponse2.get("status").getAsString());
assertEquals("Grandchild 1 account status is not updated", "active", getAccountResponse3.get("status").getAsString());
assertEquals("Grandchild 2 account status is not updated", "active", getAccountResponse4.get("status").getAsString());
//assertEquals("Great-grandchild 1 account status is not updated", "active", getAccountResponse5.get("status").getAsString());
//assertEquals("Great-grandchild 2 account status is not updated", "active", getAccountResponse6.get("status").getAsString());
}

@Deployment(name = "ClientsEndpointTest", managed = true, testable = false)
public static WebArchive createWebArchiveNoGw() {
logger.info("Packaging Test App");
Expand Down
Expand Up @@ -50,6 +50,13 @@ INSERT INTO "restcomm_accounts" VALUES('AC12300000000000000000000000000000','201
INSERT INTO "restcomm_accounts" VALUES('AC12300000000000000000000000000001','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','removed1@company.com','Removed (nested) 1','AC12300000000000000000000000000000','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('AC12300000000000000000000000000002','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','removed2@company.com','Removed (nested) 2','AC12300000000000000000000000000000','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('AC12300000000000000000000000000011','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','removed11@company.com','Removed (nested) 11','AC12300000000000000000000000000001','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000000','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendmaster@company.com','SuspendMaster','ACae6e420f425248d6a26948c17a9e2acf','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000000','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000001','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendchild1@company.com','SuspendChild1','ACbdf00000000000000000000000000000','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000001','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000002','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendchild2@company.com','SuspendChild2','ACbdf00000000000000000000000000000','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000002','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000011','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendgchild1@company.com','SuspendGChild1','ACbdf00000000000000000000000000001','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000011','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000012','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendgchild2@company.com','SuspendGChild2','ACbdf00000000000000000000000000001','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000012','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000111','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendggchild1@company.com','SuspendGGChild1','ACbdf00000000000000000000000000011','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000111','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_accounts" VALUES('ACbdf00000000000000000000000000112','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','suspendggchild2@company.com','SuspendGGChild2','ACbdf00000000000000000000000000011','Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACbdf00000000000000000000000000112','ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_applications" VALUES('AP00000000000000000000000000000001','2015-09-23 06:56:04.108000','2015-09-23 06:56:04.108000','rvdCollectVerbDemo','AC12300000000000000000000000000001','2012-04-24',FALSE,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Applications/AP73926e7113fa4d95981aa96b76eca854','/restcomm-rvd/services/apps/AP73926e7113fa4d95981aa96b76eca854/controller','voice')
INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PN00000000000000000000000000000001','2013-10-11 14:56:08.549000000','2013-10-11 14:56:08.549000000','This app plays the Hello World msg and requires Text-to-speech ','AC12300000000000000000000000000001','+1235','2012-04-24',FALSE,'/restcomm/demos/hello-world.xml','POST',NULL,'POST',NULL,'POST',NULL,NULL,'POST',NULL,'POST',NULL,'/restcomm/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PN146638eec1e2415d832785e30d227598',NULL,NULL,NULL,NULL, TRUE,'0.0','http://127.0.0.1:8080/restcomm/ussd-rcml.xml','GET', NULL, NULL, NULL, NULL, NULL, NULL, 'ORafbe225ad37541eba518a74248f0ac4c')
INSERT INTO "restcomm_notifications" VALUES('NO00000000000000000000000000000001','2016-09-23 10:23:29.166000','2016-09-23 10:23:29.166000','AC12300000000000000000000000000001',NULL,'2012-04-24',1,0,'http://docs.telestax.com/rvd-workspace-upgrade','Workspace migration skipped in 2016-09-23 10:23:28.935','2016-09-23 10:23:29.164000','','','',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Notifications/NO890d8e7e48f244a8be432d53b007ffd1')
Expand Down

0 comments on commit e009dc2

Please sign in to comment.