From 7b8bd5fa21d8da244c38898b111eea17736129d6 Mon Sep 17 00:00:00 2001 From: Guilherme Humberto Jansen Date: Tue, 13 Feb 2018 21:58:54 -0200 Subject: [PATCH 1/2] RESTCOMM-1220 #Turn account status switching into dynamic (use new status received instead of always CLOSED) [skip ci] --- .../restcomm/connect/http/AccountsEndpoint.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java index 8153f2a6b4..3ab6e7c1a1 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/AccountsEndpoint.java @@ -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 @@ -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); } @@ -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 data) throws NullPointerException { From a8339f0a1c7bcf2df1e0b025cd2ab15486614619 Mon Sep 17 00:00:00 2001 From: Guilherme Humberto Jansen Date: Tue, 13 Feb 2018 22:00:46 -0200 Subject: [PATCH 2/2] RESTCOMM-1220 #Integration tests for switching status to suspended --- .../testsuite/http/AccountsEndpointTest.java | 69 +++++++++++++++++++ .../resources/restcomm.script_accounts_test | 7 ++ 2 files changed, 76 insertions(+) diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java index 23809d954b..cb984b7719 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/http/AccountsEndpointTest.java @@ -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"); diff --git a/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_accounts_test b/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_accounts_test index 762bd1a66a..33258d8373 100644 --- a/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_accounts_test +++ b/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_accounts_test @@ -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')