From 7c64de0a1c70f648c07c20e8c216c5c9e94d36d2 Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Mon, 8 Dec 2014 15:23:50 -0800 Subject: [PATCH] renaming ambiguously named test helper methos --- .../integrationtests/GroupTest.java | 98 +++++++++---------- .../integrationtests/common/ClientHelper.java | 14 ++- 2 files changed, 59 insertions(+), 53 deletions(-) diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java index e8ee5a10f..ab7bfa199 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/GroupTest.java @@ -5,6 +5,11 @@ */ package org.mifosplatform.integrationtests; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.util.HashMap; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -12,22 +17,15 @@ import org.mifosplatform.integrationtests.common.ClientHelper; import org.mifosplatform.integrationtests.common.GroupHelper; import org.mifosplatform.integrationtests.common.StaffHelper; import org.mifosplatform.integrationtests.common.Utils; +import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; +import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.builder.ResponseSpecBuilder; import com.jayway.restassured.http.ContentType; import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.ResponseSpecification; -import org.mifosplatform.integrationtests.common.accounting.Account; -import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; -import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; -import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; - -import java.util.HashMap; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; /** * Group Test for checking Group: Creation, Activation, Client Association, @@ -38,11 +36,10 @@ public class GroupTest { private ResponseSpecification responseSpec; private RequestSpecification requestSpec; private LoanTransactionHelper loanTransactionHelper; - private String principal = "10000.00"; - private String accountingRule = "1"; - private String numberOfRepayments = "5"; - private String interestRatePerPeriod = "18"; - + private final String principal = "10000.00"; + private final String accountingRule = "1"; + private final String numberOfRepayments = "5"; + private final String interestRatePerPeriod = "18"; @Before public void setup() { @@ -73,29 +70,32 @@ public class GroupTest { groupID = GroupHelper.updateGroup(this.requestSpec, this.responseSpec, updatedGroupName, groupID.toString()); GroupHelper.verifyGroupDetails(this.requestSpec, this.responseSpec, groupID, "name", updatedGroupName); - // NOTE: removed as consistently provides false positive result on cloudbees server. -// groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec); -// GroupHelper.deleteGroup(this.requestSpec, this.responseSpec, groupID.toString()); -// GroupHelper.verifyGroupDeleted(this.requestSpec, this.responseSpec, groupID); + // NOTE: removed as consistently provides false positive result on + // cloudbees server. + // groupID = GroupHelper.createGroup(this.requestSpec, + // this.responseSpec); + // GroupHelper.deleteGroup(this.requestSpec, this.responseSpec, + // groupID.toString()); + // GroupHelper.verifyGroupDeleted(this.requestSpec, this.responseSpec, + // groupID); } @Test - public void assignStaffToGroup(){ + public void assignStaffToGroup() { Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec); GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID); - final String updateGroupName = Utils.randomNameGenerator("Savings Group Help_",5); + final String updateGroupName = Utils.randomNameGenerator("Savings Group Help_", 5); groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString()); - Integer updateGroupId = GroupHelper.updateGroup(this.requestSpec,this.responseSpec,updateGroupName,groupID.toString()); + Integer updateGroupId = GroupHelper.updateGroup(this.requestSpec, this.responseSpec, updateGroupName, groupID.toString()); - //create client and add client to group + // create client and add client to group final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString()); GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupID, clientID); - - //create staff - Integer createStaffId1 = StaffHelper.createStaff(this.requestSpec, this.responseSpec) ; + // create staff + Integer createStaffId1 = StaffHelper.createStaff(this.requestSpec, this.responseSpec); System.out.println("--------------creating first staff with id-------------" + createStaffId1); Assert.assertNotNull(createStaffId1); @@ -103,45 +103,43 @@ public class GroupTest { System.out.println("--------------creating second staff with id-------------" + createStaffId2); Assert.assertNotNull(createStaffId2); - //assign staff "createStaffId1" to group - HashMap assignStaffGroupId = (HashMap)GroupHelper.assignStaff(this.requestSpec,this.responseSpec,groupID.toString(),createStaffId1.longValue()); - assertEquals("Verify assigned staff id is the same as id sent",assignStaffGroupId.get("staffId"),createStaffId1); - - - - //assign staff "createStaffId2" to client - final HashMap assignStaffToClientChanges = (HashMap)ClientHelper.assignStaffToClient(this.requestSpec,this.responseSpec,clientID.toString(),createStaffId2.toString()); - assertEquals("Verify assigned staff id is the same as id sent", assignStaffToClientChanges.get("staffId"),createStaffId2); + // assign staff "createStaffId1" to group + HashMap assignStaffGroupId = (HashMap) GroupHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(), + createStaffId1.longValue()); + assertEquals("Verify assigned staff id is the same as id sent", assignStaffGroupId.get("staffId"), createStaffId1); + // assign staff "createStaffId2" to client + final HashMap assignStaffToClientChanges = (HashMap) ClientHelper.assignStaffToClient(this.requestSpec, this.responseSpec, + clientID.toString(), createStaffId2.toString()); + assertEquals("Verify assigned staff id is the same as id sent", assignStaffToClientChanges.get("staffId"), createStaffId2); final Integer loanProductId = this.createLoanProduct(); - final Integer loanId = this.applyForLoanApplication(clientID,loanProductId,this.principal); + final Integer loanId = this.applyForLoanApplication(clientID, loanProductId, this.principal); - this.loanTransactionHelper.approveLoan("20 September 2014",loanId); - this.loanTransactionHelper.disburseLoan("20 September 2014",loanId); + this.loanTransactionHelper.approveLoan("20 September 2014", loanId); + this.loanTransactionHelper.disburseLoan("20 September 2014", loanId); - final HashMap assignStaffAndInheritStaffForClientAccounts = (HashMap)GroupHelper.assignStaffInheritStaffForClientAccounts(this.requestSpec,this.responseSpec,groupID.toString(),createStaffId1.toString()); - final Integer getClientStaffId = ClientHelper.getClient(this.requestSpec,this.responseSpec,clientID.toString()); + final HashMap assignStaffAndInheritStaffForClientAccounts = (HashMap) GroupHelper.assignStaffInheritStaffForClientAccounts( + this.requestSpec, this.responseSpec, groupID.toString(), createStaffId1.toString()); + final Integer getClientStaffId = ClientHelper.getClientsStaffId(this.requestSpec, this.responseSpec, clientID.toString()); - //assert if client staff officer has change Note client was assigned staff with createStaffId2 + // assert if client staff officer has change Note client was assigned + // staff with createStaffId2 assertNotEquals("Verify if client stuff has changed", assignStaffAndInheritStaffForClientAccounts.get("staffId"), createStaffId2); - assertEquals("Verify if client inherited staff assigned above", assignStaffAndInheritStaffForClientAccounts.get("staffId"), getClientStaffId); + assertEquals("Verify if client inherited staff assigned above", assignStaffAndInheritStaffForClientAccounts.get("staffId"), + getClientStaffId); - //assert if clients loan officer has changed + // assert if clients loan officer has changed final Integer loanOfficerId = this.loanTransactionHelper.getLoanOfficerId(loanId.toString()); assertEquals("Verify if client loan inherited staff", assignStaffAndInheritStaffForClientAccounts.get("staffId"), loanOfficerId); - } private Integer createLoanProduct() { - final String loanProductJSON = new LoanProductTestBuilder() - .withPrincipal(this.principal) - .withNumberOfRepayments(this.numberOfRepayments) - .withinterestRatePerPeriod(this.interestRatePerPeriod) - .withInterestRateFrequencyTypeAsYear() - .build(null); + final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(this.principal) + .withNumberOfRepayments(this.numberOfRepayments).withinterestRatePerPeriod(this.interestRatePerPeriod) + .withInterestRateFrequencyTypeAsYear().build(null); return this.loanTransactionHelper.getLoanProductId(loanProductJSON); } diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java index 66d2b5e89..255270198 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java @@ -23,7 +23,7 @@ public class ClientHelper { private static final String CLOSE_CLIENT_COMMAND = "close"; private static final String REACTIVATE_CLIENT_COMMAND = "reactivate"; private static final String REJECT_CLIENT_COMMAND = "reject"; - private static final String ACTIVATE_CLIENT_COMMAND ="activate"; + private static final String ACTIVATE_CLIENT_COMMAND = "activate"; private static final String WITHDRAW_CLIENT_COMMAND = "withdraw"; public static final String CREATED_DATE = "27 November 2014"; @@ -62,7 +62,8 @@ public class ClientHelper { return Utils.performServerPost(requestSpec, responseSpec, CLIENT_ASSIGN_STAFF_URL, assignStaffToClientAsJson(staffId), "changes"); } - public static Integer getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String clientId) { + public static Integer getClientsStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String clientId) { return (Integer) getClient(requestSpec, responseSpec, clientId, "staffId"); } @@ -124,6 +125,7 @@ public class ClientHelper { return clientJson; } + private String getReactivateClientAsJSON() { final HashMap map = new HashMap<>(); map.put("locale", CommonConstants.locale); @@ -134,6 +136,7 @@ public class ClientHelper { return clientJson; } + private String getRejectClientAsJSON() { final HashMap map = new HashMap<>(); map.put("locale", CommonConstants.locale); @@ -145,6 +148,7 @@ public class ClientHelper { return clientJson; } + private String getActivateClientAsJSON() { final HashMap map = new HashMap<>(); map.put("locale", CommonConstants.locale); @@ -167,6 +171,7 @@ public class ClientHelper { return clientJson; } + public HashMap closeClient(final Integer clientId) { System.out.println("--------------------------------- CLOSE CLIENT -------------------------------"); return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId); @@ -176,19 +181,22 @@ public class ClientHelper { System.out.println("--------------------------------- REACTIVATE CLIENT -------------------------------"); return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId); } + public HashMap rejectClient(final Integer clientId) { System.out.println("--------------------------------- REJECT CLIENT -------------------------------"); return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId); } - + public HashMap activateClient(final Integer clientId) { System.out.println("--------------------------------- ACTIVATE CLIENT -------------------------------"); return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(), clientId); } + public HashMap withdrawClient(final Integer clientId) { System.out.println("--------------------------------- WITHDRAWN CLIENT -------------------------------"); return performClientActions(createClientOperationURL(WITHDRAW_CLIENT_COMMAND, clientId), getWithdrawClientAsJSON(), clientId); } + private String createClientOperationURL(final String command, final Integer clientId) { return CLIENT_URL + "/" + clientId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER; }