MIFOSX-1875 Adding test cases and API docs for Password Preferences.
This commit is contained in:
+33
-21
@@ -30887,21 +30887,34 @@ Request Body:
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">
|
||||
GET https://DomainName/api/v1/passwordpreferences
|
||||
GET https://DomainName/api/v1/passwordpreferences/template
|
||||
</code>
|
||||
<code class="method-response">
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
]
|
||||
</code>
|
||||
</div>
|
||||
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">
|
||||
GET https://DomainName/api/v1/passwordpreferences/
|
||||
</code>
|
||||
<code class="method-response">
|
||||
{
|
||||
"id": 1,
|
||||
"description": "Password most be at least 1 character and not more that 50 characters long",
|
||||
"active": true
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
@@ -30913,16 +30926,15 @@ Request Body:
|
||||
</div>
|
||||
<div class="method-example">
|
||||
<code class="method-declaration">
|
||||
PUT https://DomainName/api/v1/passwordpreferences/
|
||||
PUT https://DomainName/api/v1/passwordpreferences/
|
||||
</code>
|
||||
<code class="method-request">
|
||||
PUT passwordpreferences
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"validationPolicyId" : 1,
|
||||
"locale" : "en"
|
||||
}
|
||||
PUT passwordpreferences
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"validationPolicyId" : 1,
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+65
@@ -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<HashMap> 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"));
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -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<String, Object> map = new HashMap<>();
|
||||
map.put("validationPolicyId", validationPolicyId);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updatePreferencesWithInvalidId(String invalidValidationPolicyId) {
|
||||
final HashMap<String, Object> 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<String, Object> getAllPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
|
||||
return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "/template" + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user