Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Integration tests for Custom Text Management API #16854

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,91 @@ 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));
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "BPM-60006");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,126 @@ 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(readResource("add-custom-text.json")).
ThaminduDilshan marked this conversation as resolved.
Show resolved Hide resolved
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");
ThaminduDilshan marked this conversation as resolved.
Show resolved Hide resolved
}

@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");
ThaminduDilshan marked this conversation as resolved.
Show resolved Hide resolved
}

@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(readResource("update-custom-text.json")).
ThaminduDilshan marked this conversation as resolved.
Show resolved Hide resolved
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"
}
}