From e7cdcc7b23b2cfbf770546d72bfe46f023b90297 Mon Sep 17 00:00:00 2001 From: Thumimku Date: Mon, 8 Jan 2024 13:46:00 +0530 Subject: [PATCH] update the model --- .../rules/v1/ValidationRulesSuccessTest.java | 42 ++++++------ .../rules/v1/default-response-positive.json | 9 +++ ...ail-type-username-validation-positive.json | 66 ------------------- ...t-password-validation-update-positive.json | 15 ++++- .../src/test/resources/testng.xml | 1 - 5 files changed, 41 insertions(+), 92 deletions(-) delete mode 100644 modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-enable-email-type-username-validation-positive.json diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/ValidationRulesSuccessTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/ValidationRulesSuccessTest.java index 8a3df17821d..57902416006 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/ValidationRulesSuccessTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/ValidationRulesSuccessTest.java @@ -79,29 +79,8 @@ public void testDefaultResponse() throws Exception { "Response of the get /validation-rules doesn't match."); } - @Test (description = "test put email type user name validation update", dependsOnMethods = "testDefaultResponse") - public void testEnableEmailTypeUserNameValidation() throws Exception { - - ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); - String emailTypeValidationRequestBody - = readResource("put-enable-email-type-username-validation-positive.json"); - - Response responseOfPut = getResponseOfPut(VALIDATION_RULES_PATH, emailTypeValidationRequestBody); - responseOfPut.then() - .log().ifValidationFails() - .assertThat() - .statusCode(HttpStatus.SC_OK); - List retrievedValidationConfigModels = - Arrays.asList(jsonWriter.readValue(responseOfPut.asString(), ValidationConfigModel[].class)); - Assert.assertEquals(retrievedValidationConfigModels.get(1).getField(), "username", - "Response of the put /validation-rules doesn't contain username filed."); - Assert.assertEquals(retrievedValidationConfigModels.get(1).getRules().get(0).getValidator(), - "EmailFormatValidator", - "Response of the put /validation-rules doesn't contain email as username validator."); - } - @Test (description = "test for put /validation-rules/password end point", - dependsOnMethods = "testEnableEmailTypeUserNameValidation") + dependsOnMethods = "testDefaultResponse") public void testUpdatePasswordValidation() throws Exception { ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); @@ -121,8 +100,27 @@ public void testUpdatePasswordValidation() throws Exception { RuleModel ruleModel = new RuleModel(); ruleModel.setValidator("LengthValidator"); ruleModel.addPropertiesItem(new MappingModel().key("min.length").value("10")); + ruleModel.addPropertiesItem(new MappingModel().key("max.length").value("30")); Assert.assertTrue(retrievedValidationConfigModel.getRules().contains(ruleModel), "Response of the put /validation-rules/password doesn't contain 10 as min length."); + + ruleModel = new RuleModel(); + ruleModel.setValidator("UpperCaseValidator"); + ruleModel.addPropertiesItem(new MappingModel().key("min.length").value("0")); + Assert.assertTrue(retrievedValidationConfigModel.getRules().contains(ruleModel), + "Response of the put /validation-rules/password doesn't contain 0 as UpperCaseValidator."); + + ruleModel = new RuleModel(); + ruleModel.setValidator("LowerCaseValidator"); + ruleModel.addPropertiesItem(new MappingModel().key("min.length").value("0")); + Assert.assertTrue(retrievedValidationConfigModel.getRules().contains(ruleModel), + "Response of the put /validation-rules/password doesn't contain 0 as LowerCaseValidator."); + + ruleModel = new RuleModel(); + ruleModel.setValidator("SpecialCharacterValidator"); + ruleModel.addPropertiesItem(new MappingModel().key("min.length").value("0")); + Assert.assertTrue(retrievedValidationConfigModel.getRules().contains(ruleModel), + "Response of the put /validation-rules/password doesn't contain 0 as SpecialCharacterValidator."); } @Test (description = "Test to set configuration to default.",dependsOnMethods = "testUpdatePasswordValidation") diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/default-response-positive.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/default-response-positive.json index 68619c5e540..b247606e8e2 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/default-response-positive.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/default-response-positive.json @@ -11,6 +11,15 @@ } ] }, + { + "validator": "LengthValidator", + "properties": [ + { + "key": "max.length", + "value": "30" + } + ] + }, { "validator": "NumeralValidator", "properties": [ diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-enable-email-type-username-validation-positive.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-enable-email-type-username-validation-positive.json deleted file mode 100644 index b97687ec80e..00000000000 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-enable-email-type-username-validation-positive.json +++ /dev/null @@ -1,66 +0,0 @@ -[ - { - "field": "password", - "rules": [ - { - "validator": "NumeralValidator", - "properties": [ - { - "key": "min.length", - "value": "1" - } - ] - }, - { - "validator": "LengthValidator", - "properties": [ - { - "key": "min.length", - "value": "8" - } - ] - }, - { - "validator": "UpperCaseValidator", - "properties": [ - { - "key": "min.length", - "value": "1" - } - ] - }, - { - "validator": "LowerCaseValidator", - "properties": [ - { - "key": "min.length", - "value": "1" - } - ] - }, - { - "validator": "SpecialCharacterValidator", - "properties": [ - { - "key": "min.length", - "value": "1" - } - ] - } - ] - }, - { - "field": "username", - "rules": [ - { - "validator": "EmailFormatValidator", - "properties": [ - { - "key": "enable.validator", - "value": "true" - } - ] - } - ] - } -] diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-password-validation-update-positive.json b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-password-validation-update-positive.json index b214e789ae9..acc313d86dd 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-password-validation-update-positive.json +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/org/wso2/identity/integration/test/rest/api/server/validation/rules/v1/put-password-validation-update-positive.json @@ -9,6 +9,15 @@ } ] }, + { + "validator": "LengthValidator", + "properties": [ + { + "key": "max.length", + "value": "30" + } + ] + }, { "validator": "NumeralValidator", "properties": [ @@ -23,7 +32,7 @@ "properties": [ { "key": "min.length", - "value": "1" + "value": "0" } ] }, @@ -32,7 +41,7 @@ "properties": [ { "key": "min.length", - "value": "1" + "value": "0" } ] }, @@ -41,7 +50,7 @@ "properties": [ { "key": "min.length", - "value": "1" + "value": "0" } ] } diff --git a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml index 9b108600607..575c4aa19fe 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml +++ b/modules/integration/tests-integration/tests-backend/src/test/resources/testng.xml @@ -215,7 +215,6 @@ -