Deleting the topics module since its incomplete and additional cleanups
This commit is contained in:
committed by
Arnold Gálovics
parent
073b1b04b6
commit
6849f45bb8
+66
-13
@@ -18,40 +18,93 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.apache.fineract.integrationtests.useradministration.roles.RolesHelper.SUPER_USER_ROLE_ID;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.client.models.GetNotification;
|
||||
import org.apache.fineract.client.models.GetNotificationsResponse;
|
||||
import org.apache.fineract.client.models.GetOfficesResponse;
|
||||
import org.apache.fineract.client.models.PostClientsRequest;
|
||||
import org.apache.fineract.client.models.PostUsersRequest;
|
||||
import org.apache.fineract.client.models.PostUsersResponse;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.NotificationHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NotificationApiTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationApiTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
public static final int SUPER_USER_ID = 1;
|
||||
public static final String CLIENT_OBJECT_TYPE = "client";
|
||||
public static final String CREATED_ACTION_TYPE = "created";
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private RequestSpecification newUserRequestSpec;
|
||||
private ResponseSpecification newUserResponseSpec;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
|
||||
String username = Utils.randomNameGenerator("NotificationUser", 4);
|
||||
String password = Utils.randomStringGenerator("aA1", 10); // prefix is to conform with the password rules
|
||||
PostUsersRequest createUserRequest = new PostUsersRequest().username(username)
|
||||
.firstname(Utils.randomNameGenerator("NotificationFN", 4)).lastname(Utils.randomNameGenerator("NotificationLN", 4))
|
||||
.email("whatever@mifos.org").password(password).repeatPassword(password).sendPasswordToEmail(false)
|
||||
.roles(List.of(Long.toString(SUPER_USER_ROLE_ID))).officeId(headOffice.getId());
|
||||
|
||||
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
|
||||
Assertions.assertNotNull(userCreationResponse.getResourceId());
|
||||
|
||||
newUserRequestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
newUserRequestSpec.header("Authorization",
|
||||
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, password));
|
||||
newUserResponseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNotificationRetrieval() {
|
||||
HashMap<String, Object> response = (HashMap<String, Object>) NotificationHelper.getNotifications(this.requestSpec,
|
||||
this.responseSpec, "");
|
||||
LOG.info("Response : {}", response.toString());
|
||||
public void testNotificationRetrievalWorksWhenNoNotificationsAreAvailable() {
|
||||
// given
|
||||
// when
|
||||
GetNotificationsResponse response = NotificationHelper.getNotifications(requestSpec, responseSpec);
|
||||
// then
|
||||
Assertions.assertNotNull(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotificationRetrievalWorksWhenOneNotificationIsAvailable() {
|
||||
// given
|
||||
PostClientsRequest clientRequest = ClientHelper.defaultClientCreationRequest();
|
||||
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, clientRequest);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// when
|
||||
NotificationHelper.waitUntilNotificationsAreAvailable(newUserRequestSpec, newUserResponseSpec);
|
||||
GetNotificationsResponse response = NotificationHelper.getNotifications(newUserRequestSpec, newUserResponseSpec);
|
||||
// then
|
||||
Assertions.assertNotNull(response);
|
||||
List<GetNotification> pageItems = response.getPageItems();
|
||||
Assertions.assertEquals(1, pageItems.size());
|
||||
GetNotification firstNotification = pageItems.get(0);
|
||||
Assertions.assertEquals(SUPER_USER_ID, firstNotification.getActorId());
|
||||
Assertions.assertEquals(false, firstNotification.getIsRead());
|
||||
Assertions.assertEquals(CREATED_ACTION_TYPE, firstNotification.getAction());
|
||||
Assertions.assertEquals(clientId.longValue(), firstNotification.getObjectId());
|
||||
Assertions.assertEquals(CLIENT_OBJECT_TYPE, firstNotification.getObjectType());
|
||||
}
|
||||
}
|
||||
|
||||
+27
-15
@@ -18,28 +18,40 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.time.Duration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetNotificationsResponse;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
|
||||
public class NotificationHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationHelper.class);
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
@Slf4j
|
||||
public final class NotificationHelper {
|
||||
|
||||
private static final String NOTIFICATION_API_URL = "/fineract-provider/api/v1/notifications?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final Gson GSON = new JSON().getGson();
|
||||
|
||||
public NotificationHelper(RequestSpecification requestSpec, ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
private NotificationHelper() {}
|
||||
|
||||
public static GetNotificationsResponse getNotifications(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_NOTIFICATIONS_URL = NOTIFICATION_API_URL;
|
||||
log.info("-----------------------------GET NOTIFICATIONS-----------------------------------");
|
||||
String response = Utils.performServerGet(requestSpec, responseSpec, GET_NOTIFICATIONS_URL);
|
||||
return GSON.fromJson(response, GetNotificationsResponse.class);
|
||||
}
|
||||
|
||||
public static Object getNotifications(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jsonReturn) {
|
||||
final String GET_NOTIFICATIONS_URL = NOTIFICATION_API_URL;
|
||||
LOG.info("-----------------------------GET NOTIFICATIONS-----------------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_NOTIFICATIONS_URL, "");
|
||||
public static boolean areNotificationsAvailable(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return getNotifications(requestSpec, responseSpec).getPageItems().size() > 0;
|
||||
}
|
||||
|
||||
// Waiting for notifications to be available is needed due to the asynchronous event processing
|
||||
public static void waitUntilNotificationsAreAvailable(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
await().atMost(Duration.ofSeconds(30)).pollInterval(Duration.ofMillis(250))
|
||||
.until(() -> NotificationHelper.areNotificationsAvailable(requestSpec, responseSpec));
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -29,6 +29,8 @@ import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.client.models.GetOfficesResponse;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
@@ -36,8 +38,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class OfficeHelper {
|
||||
|
||||
public static final long HEAD_OFFICE_ID = 1L; // The ID is hardcoded in the initial Liquibase migration script
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OfficeHelper.class);
|
||||
private static final String OFFICE_URL = "/fineract-provider/api/v1/offices";
|
||||
private static final Gson GSON = new JSON().getGson();
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
@@ -52,6 +57,12 @@ public class OfficeHelper {
|
||||
return new Gson().fromJson(json, new TypeToken<OfficeDomain>() {}.getType());
|
||||
}
|
||||
|
||||
public static GetOfficesResponse getHeadOffice(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
String response = Utils.performServerGet(requestSpec, responseSpec,
|
||||
OFFICE_URL + "/" + HEAD_OFFICE_ID + "?" + Utils.TENANT_IDENTIFIER);
|
||||
return GSON.fromJson(response, GetOfficesResponse.class);
|
||||
}
|
||||
|
||||
public Integer createOffice(final String openingDate) {
|
||||
String json = getAsJSON(openingDate);
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, OFFICE_URL + "?" + Utils.TENANT_IDENTIFIER, json,
|
||||
|
||||
+7
-2
@@ -118,12 +118,17 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
|
||||
return loginIntoServerAndGetBase64EncodedAuthenticationKey("mifos", "password");
|
||||
}
|
||||
|
||||
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey(String username, String password) {
|
||||
awaitSpringBootActuatorHealthyUp();
|
||||
try {
|
||||
LOG.info("Logging in, for integration test...");
|
||||
// system.out.println("-----------------------------------LOGIN-----------------------------------------");
|
||||
String json = RestAssured.given().contentType(ContentType.JSON).body("{\"username\":\"mifos\", \"password\":\"password\"}")
|
||||
.expect().log().ifError().when().post(LOGIN_URL).asString();
|
||||
String json = RestAssured.given().contentType(ContentType.JSON)
|
||||
.body("{\"username\":\"" + username + "\", \"password\":\"" + password + "\"}").expect().log().ifError().when()
|
||||
.post(LOGIN_URL).asString();
|
||||
assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false));
|
||||
String key = JsonPath.with(json).get("base64EncodedAuthenticationKey");
|
||||
assertThat("Failed to obtain key: " + json, StringUtils.isBlank(key), is(false));
|
||||
|
||||
+2
@@ -26,6 +26,8 @@ import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
public final class RolesHelper {
|
||||
|
||||
public static final long SUPER_USER_ROLE_ID = 1L; // This is hardcoded into the initial Liquibase migration
|
||||
|
||||
private RolesHelper() {
|
||||
|
||||
}
|
||||
|
||||
+14
-4
@@ -18,22 +18,25 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.useradministration.users;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.client.models.PostUsersRequest;
|
||||
import org.apache.fineract.client.models.PostUsersResponse;
|
||||
import org.apache.fineract.client.util.JSON;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
public final class UserHelper {
|
||||
|
||||
private UserHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final String CREATE_USER_URL = "/fineract-provider/api/v1/users?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String USER_URL = "/fineract-provider/api/v1/users";
|
||||
private static final Gson GSON = new JSON().getGson();
|
||||
|
||||
private UserHelper() {}
|
||||
|
||||
public static Integer createUser(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, int roleId,
|
||||
int staffId) {
|
||||
@@ -46,6 +49,13 @@ public final class UserHelper {
|
||||
attribute);
|
||||
}
|
||||
|
||||
public static PostUsersResponse createUser(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
PostUsersRequest request) {
|
||||
String requestBody = GSON.toJson(request);
|
||||
String response = Utils.performServerPost(requestSpec, responseSpec, CREATE_USER_URL, requestBody);
|
||||
return GSON.fromJson(response, PostUsersResponse.class);
|
||||
}
|
||||
|
||||
public static Object createUserForSelfService(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
int roleId, int staffId, int clientId, String attribute) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_USER_URL,
|
||||
|
||||
Reference in New Issue
Block a user