Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -26,14 +26,16 @@
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.List;
import org.apache.fineract.client.feign.FineractFeignClient;
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.client.feign.helpers.FeignNotificationHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.NotificationHelper;
import org.apache.fineract.integrationtests.common.FineractFeignClientHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
Expand All @@ -46,11 +48,11 @@ public class NotificationApiTest {
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;
private FeignNotificationHelper notificationHelper;
private FeignNotificationHelper newUserNotificationHelper;

@BeforeEach
public void setUp() {
Expand All @@ -59,43 +61,42 @@ public void setUp() {
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();

notificationHelper = new FeignNotificationHelper(FineractFeignClientHelper.getFineractFeignClient());

GetOfficesResponse headOffice = OfficeHelper.getHeadOffice();
String username = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
String password = Utils.randomStringGenerator("A1b2c3d4e5f$", 1); // prefix is to conform with the password
// rules
String password = Utils.randomStringGenerator("A1b2c3d4e5f$", 1);

PostUsersRequest createUserRequest = new PostUsersRequest().username(username).firstname(Utils.randomFirstNameGenerator())
.lastname(Utils.randomLastNameGenerator()).email("whatever@mifos.org").password(password).repeatPassword(password)
.sendPasswordToEmail(false).roles(List.of(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();

FineractFeignClient newUserClient = FineractFeignClientHelper.createNewFineractFeignClient(username, password);
newUserNotificationHelper = new FeignNotificationHelper(newUserClient);
}

@Test
public void testNotificationRetrievalWorksWhenNoNotificationsAreAvailable() {
// given
// when
GetNotificationsResponse response = NotificationHelper.getNotifications(requestSpec, responseSpec);
GetNotificationsResponse response = notificationHelper.getNotifications();
// then
Assertions.assertNotNull(response);
}

@Test
public void testNotificationRetrievalWorksWhenOneNotificationIsAvailable() {
// given
// given (still using RestAssured-based ClientHelper - to be migrated separately)
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);
newUserNotificationHelper.waitUntilNotificationsAreAvailable();
GetNotificationsResponse response = newUserNotificationHelper.getNotifications();
// then
Assertions.assertNotNull(response);
List<GetNotification> pageItems = response.getPageItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.fineract.client.models.GetClientsClientIdResponse;
import org.apache.fineract.client.models.GetSearchResponse;
import org.apache.fineract.client.models.PostClientsResponse;
import org.apache.fineract.integrationtests.client.feign.helpers.FeignSearchHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.SearchHelper;
import org.apache.fineract.integrationtests.common.FineractFeignClientHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
import org.apache.fineract.integrationtests.common.shares.ShareAccountHelper;
Expand All @@ -48,70 +47,69 @@ public class SearchResourcesTest {

private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private FeignSearchHelper searchHelper;

@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();
this.searchHelper = new FeignSearchHelper(FineractFeignClientHelper.getFineractFeignClient());
}

@Test
public void searchAnyValueOverAllResources() {
final List<String> resources = Arrays.asList("clients", "clientIdentifiers", "groups", "savings", "shares", "loans");
final String resources = "clients,clientIdentifiers,groups,savings,shares,loans";

final String query = Utils.randomStringGenerator("C", 12);
final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.TRUE,
resources.toString());
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.TRUE);
assertNotNull(searchResponse);
assertEquals(0, searchResponse.size());
}

@Test
public void searchAnyValueOverClientResources() {
final List<String> resources = Arrays.asList("clients");
final String resources = "clients";

final String query = Utils.randomStringGenerator("C", 12);
final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.TRUE,
getResources(resources));
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.TRUE);
assertNotNull(searchResponse);
assertEquals(0, searchResponse.size());
}

@Test
public void searchOverClientResources() {
final List<String> resources = Arrays.asList("clients");
final String resources = "clients";

// Client and Loan account creation
// Client creation (still using RestAssured-based ClientHelper - to be migrated separately)
String jsonPayload = ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, ClientHelper.LEGALFORM_ID_PERSON, null);
final PostClientsResponse clientResponse = ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
final Long clientId = clientResponse.getClientId();
final GetClientsClientIdResponse getClientResponse = ClientHelper.getClient(requestSpec, responseSpec, clientId.intValue());
final String query = getClientResponse.getAccountNo();

final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.FALSE,
getResources(resources));
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.FALSE);
assertNotNull(searchResponse);
assertEquals(1, searchResponse.size());
assertEquals(getClientResponse.getDisplayName(), searchResponse.get(0).getEntityName(), "Client name comparation");
}

@Test
public void searchAnyValueOverLoanResources() {
final List<String> resources = Arrays.asList("loans");
final String resources = "loans";

final String query = Utils.randomStringGenerator("L", 12);
final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.TRUE,
getResources(resources));
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.TRUE);
assertNotNull(searchResponse);
assertEquals(0, searchResponse.size());
}

@Test
public void searchOverSavingsResources() {
final List<String> resources = Arrays.asList("savings");
final String resources = "savings";

// Setup (still using RestAssured-based helpers - to be migrated separately)
String jsonPayload = ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, ClientHelper.LEGALFORM_ID_PERSON, null);
final PostClientsResponse clientResponse = ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
final Long clientId = clientResponse.getClientId();
Expand All @@ -120,8 +118,7 @@ public void searchOverSavingsResources() {
final SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
final String query = (String) savingsAccountHelper.getSavingsAccountDetail(savingsId, "accountNo");

final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.FALSE,
getResources(resources));
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.FALSE);

assertNotNull(searchResponse);
assertEquals(1, searchResponse.size());
Expand All @@ -137,8 +134,9 @@ public void searchOverSavingsResources() {

@Test
public void searchOverSharesResources() {
final List<String> resources = Arrays.asList("shares");
final String resources = "shares";

// Setup (still using RestAssured-based helpers - to be migrated separately)
String jsonPayload = ClientHelper.getBasicClientAsJSON(ClientHelper.DEFAULT_OFFICE_ID, ClientHelper.LEGALFORM_ID_PERSON, null);
final PostClientsResponse clientsResponse = ClientHelper.addClientAsPerson(requestSpec, responseSpec, jsonPayload);
final Long clientId = clientsResponse.getClientId();
Expand Down Expand Up @@ -170,8 +168,7 @@ public void searchOverSharesResources() {
responseSpec);
final String query = (String) shareAccountData.get("accountNo");

final ArrayList<GetSearchResponse> searchResponse = SearchHelper.getSearch(requestSpec, responseSpec, query, Boolean.FALSE,
getResources(resources));
final List<GetSearchResponse> searchResponse = searchHelper.search(query, resources, Boolean.FALSE);

assertNotNull(searchResponse);
assertEquals(1, searchResponse.size());
Expand All @@ -184,9 +181,4 @@ public void searchOverSharesResources() {
assertNotNull(result.getEntityStatus().getCode());
assertNotNull(result.getEntityStatus().getValue());
}

private String getResources(final List<String> resources) {
return String.join(",", resources);
}

}
Loading
Loading