Skip to content

Commit

Permalink
Merge pull request #17215 from bhagyasakalanka/sms-provider
Browse files Browse the repository at this point in the history
Fix integration tests to support crud operations on sms provider configurations in super tenant
  • Loading branch information
bhagyasakalanka authored Oct 26, 2023
2 parents 09aaf0c + 00c0e90 commit bd80548
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,14 @@ public void testAddSmsSenderConflict() throws IOException {
String body = readResource("add-sms-sender.json");
Response response =
getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
smsNotificationSenderName = location.substring(location.lastIndexOf("/") + 1);
assertNotNull(smsNotificationSenderName);
response = getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
validateErrorResponse(response, HttpStatus.SC_CONFLICT, "NSM-60002");
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
smsNotificationSenderName = location.substring(location.lastIndexOf("/") + 1);
assertNotNull(smsNotificationSenderName);
response = getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
validateErrorResponse(response, HttpStatus.SC_CONFLICT, "NSM-60002");
}

@Test
Expand All @@ -195,14 +185,8 @@ public void testAddSmsSenderWithNonExistingEventPublisherName() throws IOExcepti
String body = readResource("add-sms-sender-2.json");
Response response =
getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60001");
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}

validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60001");
}

@Test
Expand All @@ -211,14 +195,8 @@ public void testAddSmsSenderWithUndefinedSmsProvider() throws IOException {
String body = readResource("add-sms-sender-invalid-provider.json");
Response response =
getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "NSM-60004");
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}

validateErrorResponse(response, HttpStatus.SC_BAD_REQUEST, "NSM-60004");
}

@Test
Expand All @@ -227,14 +205,7 @@ public void testGetSmsSenderByInvalidName() {
Response response = getResponseOfGet(
NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH + PATH_SEPARATOR +
"randomName");
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60006");
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60006");
}

@Test
Expand All @@ -243,13 +214,6 @@ public void testDeleteSmsSenderByInvalidName() {
Response response = getResponseOfDelete(
NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH + PATH_SEPARATOR +
"randomName");
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60006");
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
validateErrorResponse(response, HttpStatus.SC_NOT_FOUND, "NSM-60006");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,12 @@ public void testAddSmsSender() throws IOException {
String body = readResource("add-sms-sender.json");
Response response =
getResponseOfPost(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH, body);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
smsNotificationSenderName = location.substring(location.lastIndexOf("/") + 1);
assertNotNull(smsNotificationSenderName);
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_CREATED)
.header(HttpHeaders.LOCATION, notNullValue());
String location = response.getHeader(HttpHeaders.LOCATION);
assertNotNull(location);
smsNotificationSenderName = location.substring(location.lastIndexOf("/") + 1);
assertNotNull(smsNotificationSenderName);
}

@Test(dependsOnMethods = {"testAddSmsSender"})
Expand All @@ -239,25 +229,18 @@ public void testGetSMSSender() throws IOException {
Response response = getResponseOfGet(
NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH + PATH_SEPARATOR +
smsNotificationSenderName);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo("SMSPublisher"))
.body("provider", equalTo("Vonage"))
.body("providerURL", equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa184"))
.body("key", equalTo("1234"))
.body("secret", equalTo("12345"))
.body("sender", equalTo("073923902"))
.body("contentType", equalTo("JSON"))
.body("properties", notNullValue());
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo("SMSPublisher"))
.body("provider", equalTo("Vonage"))
.body("providerURL", equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa184"))
.body("key", equalTo("1234"))
.body("secret", equalTo("12345"))
.body("sender", equalTo("073923902"))
.body("contentType", equalTo("JSON"))
.body("properties", notNullValue());
}

@Test(dependsOnMethods = {"testGetSMSSender"})
Expand All @@ -267,26 +250,19 @@ public void testGetSMSSenders() throws UnsupportedEncodingException {
"find{ it.name == '" + URLDecoder.decode(smsNotificationSenderName, StandardCharsets.UTF_8.name()) +
"' }.";
Response response = getResponseOfGet(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body(baseIdentifier + "name", equalTo("SMSPublisher"))
.body(baseIdentifier + "provider", equalTo("Vonage"))
.body(baseIdentifier + "providerURL",
equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa184"))
.body(baseIdentifier + "key", equalTo("1234"))
.body(baseIdentifier + "secret", equalTo("12345"))
.body(baseIdentifier + "sender", equalTo("073923902"))
.body(baseIdentifier + "contentType", equalTo("JSON"))
.body(baseIdentifier + "properties", notNullValue());
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body(baseIdentifier + "name", equalTo("SMSPublisher"))
.body(baseIdentifier + "provider", equalTo("Vonage"))
.body(baseIdentifier + "providerURL",
equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa184"))
.body(baseIdentifier + "key", equalTo("1234"))
.body(baseIdentifier + "secret", equalTo("12345"))
.body(baseIdentifier + "sender", equalTo("073923902"))
.body(baseIdentifier + "contentType", equalTo("JSON"))
.body(baseIdentifier + "properties", notNullValue());
}

@Test(dependsOnMethods = {"testGetSMSSenders"})
Expand All @@ -295,25 +271,18 @@ public void testUpdateSMSSender() throws IOException {
String body = readResource("update-sms-sender.json");
Response response = getResponseOfPut(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH +
PATH_SEPARATOR + smsNotificationSenderName, body);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo("SMSPublisher"))
.body("provider", equalTo("Clickatell"))
.body("providerURL", equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa185"))
.body("key", equalTo("123"))
.body("secret", equalTo("123456"))
.body("sender", equalTo("0773923902"))
.body("contentType", equalTo("JSON"))
.body("properties", notNullValue());
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK)
.body("name", equalTo("SMSPublisher"))
.body("provider", equalTo("Clickatell"))
.body("providerURL", equalTo("https://webhook.site/9b79bebd-445a-4dec-ad5e-622b856fa185"))
.body("key", equalTo("123"))
.body("secret", equalTo("123456"))
.body("sender", equalTo("0773923902"))
.body("contentType", equalTo("JSON"))
.body("properties", notNullValue());
}

@Test(dependsOnMethods = {"testUpdateSMSSender"})
Expand All @@ -322,17 +291,10 @@ public void testDeleteSMsSender() throws IOException {
Response response =
getResponseOfDelete(NOTIFICATION_SENDER_API_BASE_PATH + PATH_SEPARATOR + SMS_SENDERS_PATH +
PATH_SEPARATOR + smsNotificationSenderName);
if (!StringUtils.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, tenant)) {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
} else {
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_NO_CONTENT);
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@
<!-- Identity REST API feature -->
<identity.api.dispatcher.version>2.0.13</identity.api.dispatcher.version>
<identity.user.api.version>1.3.23</identity.user.api.version>
<identity.server.api.version>1.2.104</identity.server.api.version>
<identity.server.api.version>1.2.105</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 bd80548

Please sign in to comment.