Skip to content

Commit

Permalink
Merge pull request #16854 from UdeshAthukorala/custom-text-api
Browse files Browse the repository at this point in the history
Add Integration tests for Custom Text Management API
  • Loading branch information
UdeshAthukorala authored Oct 10, 2023
2 parents 8bc5e07 + f8ce78e commit 3b3198f
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,94 @@ public void testDeleteNotExistingBrandingPreference() {
Response response = getResponseOfDelete(BRANDING_PREFERENCE_API_BASE_PATH);
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "BPM-60002");
}

@Test
public void testAddCustomTextPreferenceWithEmptyJsonPreference() throws IOException {

String body = readResource("add-empty-custom-text-preference.json");
Response response = getResponseOfPost(CUSTOM_TEXT_API_BASE_PATH, body);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "BPM-60005");
}

@Test
public void testAddCustomTextPreferenceConflict() throws IOException {

String body = readResource("add-custom-text.json");
// Add Custom Text Preference.
Response response = getResponseOfPost(CUSTOM_TEXT_API_BASE_PATH, body);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);

// Add conflicting Custom Text Preference.
response = getResponseOfPost(CUSTOM_TEXT_API_BASE_PATH, body);
validateErrorResponse(response, HttpStatus.SC_CONFLICT, "BPM-60007");

// Delete Custom Text Preference.
response = getResponseOfDelete(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}

@Test
public void testGetNotExistingCustomTextPreference() {

Response response = getResponseOfGet(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "BPM-60006");
}

@Test
public void testUpdateNotExistingCustomTextPreference() throws IOException {

String body = readResource("update-custom-text.json");
Response response = getResponseOfPut(CUSTOM_TEXT_API_BASE_PATH, body);
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "BPM-60006");
}

@Test
public void testUpdateCustomTextPreferenceWithEmptyJsonPreference() throws IOException {

String body = readResource("add-custom-text.json");
// Add Custom Text Preference.
Response response = getResponseOfPost(CUSTOM_TEXT_API_BASE_PATH, body);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);

// Update Custom Text Preference with empty JSON preference.
body = readResource("add-empty-custom-text-preference.json");
response = getResponseOfPut(CUSTOM_TEXT_API_BASE_PATH, body);
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "BPM-60005");

// Delete Custom Text Preference.
response = getResponseOfDelete(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}

@Test
public void testDeleteNotExistingCustomTextPreference() {

Response response = getResponseOfDelete(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,124 @@ public void testDeleteBrandingPreferenceByLocaleQueryParam() throws IOException
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}

@Test
public void testAddCustomTextPreference() throws IOException, JSONException {

String body = readResource("add-custom-text.json");
Response response = getResponseOfPost(CUSTOM_TEXT_API_BASE_PATH, body);

response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);

JSONObject expectedPreference = new JSONObject(new JSONObject(body).get("preference").toString());
JSONObject receivedPreference = new JSONObject(new JSONObject(response.asString()).
get("preference").toString());
Assert.assertTrue(areJSONObjectsEqual(expectedPreference, receivedPreference),
"The custom text preference schema of the Response is incorrect.");
}

@Test(dependsOnMethods = {"testAddCustomTextPreference"})
public void testGetCustomTextPreference() throws IOException, JSONException {

Response response = getResponseOfGet(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("type", equalTo(ORGANIZATION_TYPE))
.body("name", equalTo(tenant))
.body("screen", equalTo(LOGIN_SCREEN))
.body("locale", equalTo(DEFAULT_LOCALE));

JSONObject expectedPreference = new JSONObject(new JSONObject(readResource("add-custom-text.json")).
get("preference").toString());
JSONObject receivedPreference = new JSONObject(new JSONObject(response.asString()).
get("preference").toString());
Assert.assertTrue(areJSONObjectsEqual(expectedPreference, receivedPreference),
"The custom text preference schema of the Response is incorrect.");
}

@Test(dependsOnMethods = {"testGetCustomTextPreference"})
public void testGetCustomTextPreferenceByQueryParams() throws IOException, JSONException {

Response response = getResponseOfGet(CUSTOM_TEXT_API_BASE_PATH + String.format
(CUSTOM_TEXT_COMPONENT_WITH_QUERY_PARAM, ORGANIZATION_TYPE, tenant, LOGIN_SCREEN, DEFAULT_LOCALE));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("type", equalTo(ORGANIZATION_TYPE))
.body("name", equalTo(tenant))
.body("screen", equalTo(LOGIN_SCREEN))
.body("locale", equalTo(DEFAULT_LOCALE));

JSONObject expectedPreference = new JSONObject(new JSONObject(readResource("add-custom-text.json")).
get("preference").toString());
JSONObject receivedPreference = new JSONObject(new JSONObject(response.asString()).
get("preference").toString());
Assert.assertTrue(areJSONObjectsEqual(expectedPreference, receivedPreference),
"The custom text preference schema of the Response is incorrect");
}

@Test(dependsOnMethods = {"testGetCustomTextPreferenceByQueryParams"})
public void testUpdateCustomTextPreference() throws IOException, JSONException {

String body = readResource("update-custom-text.json");
Response response = getResponseOfPut(CUSTOM_TEXT_API_BASE_PATH, body);

response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("type", equalTo(ORGANIZATION_TYPE))
.body("name", equalTo(tenant))
.body("screen", equalTo(LOGIN_SCREEN))
.body("locale", equalTo(DEFAULT_LOCALE));

JSONObject expectedPreference = new JSONObject(new JSONObject(body).get("preference").toString());
JSONObject receivedPreference = new JSONObject(new JSONObject(response.asString()).
get("preference").toString());
Assert.assertTrue(areJSONObjectsEqual(expectedPreference, receivedPreference),
"The custom text preference schema of the Response is incorrect");
}

@Test(dependsOnMethods = {"testUpdateCustomTextPreference"})
public void testGetCustomTextPreferenceAfterUpdate() throws IOException, JSONException {

Response response = getResponseOfGet(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("type", equalTo(ORGANIZATION_TYPE))
.body("name", equalTo(tenant))
.body("screen", equalTo(LOGIN_SCREEN))
.body("locale", equalTo(DEFAULT_LOCALE));

JSONObject expectedPreference = new JSONObject(new JSONObject(readResource("update-custom-text.json")).
get("preference").toString());
JSONObject receivedPreference = new JSONObject(new JSONObject(response.asString()).
get("preference").toString());
Assert.assertTrue(areJSONObjectsEqual(expectedPreference, receivedPreference),
"The custom text preference schema of the Response is incorrect");
}

@Test(dependsOnMethods = {"testGetCustomTextPreferenceAfterUpdate"})
public void testDeleteCustomTextPreference() {

Response response = getResponseOfDelete(CUSTOM_TEXT_API_BASE_PATH + QUERY_PARAM_SEPARATOR +
String.format(SCREEN_QUERY_PARAM, LOGIN_SCREEN));
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ public class BrandingPreferenceManagementTestBase extends RESTAPIServerTestBase
public static final String API_PACKAGE_NAME =
"org.wso2.carbon.identity.api.server.branding.preference.management.v1";
public static final String BRANDING_PREFERENCE_API_BASE_PATH = "/branding-preference";
public static final String CUSTOM_TEXT_API_BASE_PATH = "/branding-preference/text";
public static final String PATH_SEPARATOR = "/";
public static final String QUERY_PARAM_SEPARATOR = "?";
public static final String ORGANIZATION_TYPE = "ORG";
public static final String APPLICATION_TYPE = "APP";
public static final String CUSTOM_TYPE = "CUSTOM";
public static final String DEFAULT_LOCALE = "en-US";
public static final String LOGIN_SCREEN = "login";
public static final String PREFERENCE_COMPONENT_WITH_QUERY_PARAM = "?type=%s&name=%s&locale=%s";
public static final String CUSTOM_TEXT_COMPONENT_WITH_QUERY_PARAM = "?type=%s&name=%s&screen=%s&locale=%s";
public static final String TYPE_QUERY_PARAM = "type=%s";
public static final String LOCALE_QUERY_PARAM = "locale=%s";
public static final String SCREEN_QUERY_PARAM = "screen=%s";

protected static String swaggerDefinition;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "ORG",
"name": "WSO2",
"locale": "en-US",
"screen": "login",
"preference": {
"login": "Sign In",
"welcome": "Welcome",
"account.linking": "Account Linking",
"username": "Username",
"email.username": "Email address",
"back.to.sign.in": "Back to Sign In",
"or": "Or",
"dont.have.an.account": "Don't have an account?"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "ORG",
"name": "organization-name",
"locale": "en-US",
"screen": "login",
"preference": { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "ORG",
"name": "WSO2",
"locale": "en-US",
"screen": "login",
"preference": {
"login": "Sign In",
"welcome": "Welcome",
"account.linking": "Account Linking",
"username": "Username",
"email.username": "Email address",
"back.to.sign.in": "Back to Sign In",
"or": "Or",
"dont.have.an.account": "Don't have an account?",
"password": "Password",
"confirm.password": "Confirm Password",
"email": "Email",
"enter.your.email": "Enter your email",
"enter.your.username": "Enter your username",
"enter.your.password": "Enter your password"
}
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@
<properties>

<!--Carbon Identity Framework Version-->
<carbon.identity.framework.version>5.25.375</carbon.identity.framework.version>
<carbon.identity.framework.version>5.25.378</carbon.identity.framework.version>
<carbon.identity.framework.version.range>[5.14.67, 6.0.0]</carbon.identity.framework.version.range>

<!--SAML Common Utils Version-->
Expand Down Expand Up @@ -2414,12 +2414,12 @@
<hashprovider.pbkdf2.version>0.1.4</hashprovider.pbkdf2.version>

<!-- Identity Branding Preference Management Versions -->
<identity.branding.preference.management.version>1.0.7</identity.branding.preference.management.version>
<identity.branding.preference.management.version>1.0.8</identity.branding.preference.management.version>

<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.13</identity.api.dispatcher.version>
<identity.user.api.version>1.3.22</identity.user.api.version>
<identity.server.api.version>1.2.86</identity.server.api.version>
<identity.server.api.version>1.2.87</identity.server.api.version>

<identity.agent.sso.version>5.5.9</identity.agent.sso.version>
<identity.tool.samlsso.validator.version>5.5.7</identity.tool.samlsso.validator.version>
Expand Down

0 comments on commit 3b3198f

Please sign in to comment.