From cf0f5440a9a4ff076092bef296950e5dfe388569 Mon Sep 17 00:00:00 2001 From: Chandrika Date: Tue, 31 Mar 2015 12:17:15 -0400 Subject: [PATCH] MIFOSX-1875 Adding test cases and API docs for Password Preferences. --- api-docs/apiLive.htm | 54 +++++++++------ .../PasswordPreferencesIntegrationTest.java | 65 +++++++++++++++++++ .../common/PasswordPreferencesHelper.java | 57 ++++++++++++++++ 3 files changed, 155 insertions(+), 21 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PasswordPreferencesIntegrationTest.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PasswordPreferencesHelper.java diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 31ca702c4..06003c97c 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -30887,21 +30887,34 @@ Request Body:
- GET https://DomainName/api/v1/passwordpreferences +GET https://DomainName/api/v1/passwordpreferences/template - [ - { - "id": 1, - "description": "Password most be at least 1 character and not more that 50 characters long", - "active": true - }, - { - "id": 2, - "description": "Password must be at least 6 characters, no more than 50 characters long, must include at least one upper case letter, one lower case letter, one numeric digit and no space", - "active": false - } - ] +[ +{ +"id": 1, +"description": "Password most be at least 1 character and not more that 50 characters long", +"active": true +}, +{ +"id": 2, +"description": "Password must be at least 6 characters, no more than 50 characters long, must include at least one upper case letter, one lower case letter, one numeric digit and no space", +"active": false +} +] + +
+ +
+ +GET https://DomainName/api/v1/passwordpreferences/ + + +{ +"id": 1, +"description": "Password most be at least 1 character and not more that 50 characters long", +"active": true +}
@@ -30913,16 +30926,15 @@ Request Body:
- PUT https://DomainName/api/v1/passwordpreferences/ +PUT https://DomainName/api/v1/passwordpreferences/ - PUT passwordpreferences - Content-Type: application/json - Request Body: - { - "validationPolicyId" : 1, - "locale" : "en" - } +PUT passwordpreferences +Content-Type: application/json +Request Body: +{ + "validationPolicyId" : 1, +}
diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PasswordPreferencesIntegrationTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PasswordPreferencesIntegrationTest.java new file mode 100644 index 000000000..78c06aafd --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/PasswordPreferencesIntegrationTest.java @@ -0,0 +1,65 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.integrationtests; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.mifosplatform.integrationtests.common.CommonConstants; +import org.mifosplatform.integrationtests.common.PasswordPreferencesHelper; +import org.mifosplatform.integrationtests.common.Utils; + +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; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class PasswordPreferencesIntegrationTest { + + private ResponseSpecification responseSpec; + private RequestSpecification requestSpec; + private ResponseSpecification generalResponseSpec; + + @Before + public void setUp() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.generalResponseSpec = new ResponseSpecBuilder().build(); + + } + + @Test + public void updatePasswordPreferences() { + String validationPolicyId = "2"; + PasswordPreferencesHelper.updatePasswordPreferences(requestSpec, responseSpec, validationPolicyId); + this.validateIfThePasswordIsUpdated(validationPolicyId); + } + + private void validateIfThePasswordIsUpdated(String validationPolicyId){ + Integer id = PasswordPreferencesHelper.getActivePasswordPreference(requestSpec, responseSpec); + assertEquals(validationPolicyId, id.toString()); + System.out.println("---------------------------------PASSWORD PREFERENCE VALIDATED SUCCESSFULLY-----------------------------------------"); + + } + + @Test + public void updateWithInvalidPolicyId() { + String invalidValidationPolicyId = "2000"; + final List error = (List) PasswordPreferencesHelper.updateWithInvalidValidationPolicyId(requestSpec, generalResponseSpec, invalidValidationPolicyId, + CommonConstants.RESPONSE_ERROR); + assertEquals("Password Validation Policy with identifier 2000 does not exist", "error.msg.password.validation.policy.id.invalid", + error.get(0).get("userMessageGlobalisationCode")); + } + +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PasswordPreferencesHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PasswordPreferencesHelper.java new file mode 100644 index 000000000..b3be1d8ca --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/PasswordPreferencesHelper.java @@ -0,0 +1,57 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package org.mifosplatform.integrationtests.common; + +import java.util.HashMap; + +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class PasswordPreferencesHelper { + + private static final String PASSWORD_PREFERENCES_URL = "/mifosng-provider/api/v1/passwordpreferences"; + + public static Object updatePasswordPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + String validationPolicyId) { + final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out.println("---------------------------------UPDATE PASSWORD PREFERENCE---------------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesAsJson(validationPolicyId), ""); + } + + public static Object updateWithInvalidValidationPolicyId(final RequestSpecification requestSpec, + final ResponseSpecification responseSpec,String invalidValidationPolicyId, String jsonAttributeToGetback) { + final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER; + System.out + .println("---------------------------------UPDATE PASSWORD PREFERENCES WITH INVALID ID-----------------------------------------"); + return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesWithInvalidId(invalidValidationPolicyId), + jsonAttributeToGetback); + } + + public static String updatePreferencesAsJson(String validationPolicyId) { + final HashMap map = new HashMap<>(); + map.put("validationPolicyId", validationPolicyId); + return new Gson().toJson(map); + } + + public static String updatePreferencesWithInvalidId(String invalidValidationPolicyId) { + final HashMap map = new HashMap<>(); + map.put("validationPolicyId", invalidValidationPolicyId); + return new Gson().toJson(map); + } + + + public static int getActivePasswordPreference(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER, "id"); + } + + public static HashMap getAllPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + + return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "/template" + "?" + Utils.TENANT_IDENTIFIER, ""); + + } + +}