use of org.folio.rest.jaxrs.model.UserdataimportCollection in project mod-user-import by folio-org.
the class UserImportAPITest method testImportUserWithNoPreferencesWithUpdateOnlyPresentFieldAndExistingPreferenceNotDelete.
@Test
public void testImportUserWithNoPreferencesWithUpdateOnlyPresentFieldAndExistingPreferenceNotDelete() throws IOException {
mock.setMockJsonContent("mock_user_update_with_preference_not_delete.json");
List<User> users = new ArrayList<>();
User user = generateUser("89101112", "User", "Update", "58512926-9a29-483b-b801-d36aced855d3");
Address address = new Address().withAddressLine1("Test first line").withCity("Test city").withRegion("Test region").withPostalCode("12345").withAddressTypeId("Returns").withPrimaryAddress(Boolean.FALSE);
List<Address> addresses = new ArrayList<>();
addresses.add(address);
user.getPersonal().setAddresses(addresses);
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1).withUpdateOnlyPresentFields(true);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(1)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
use of org.folio.rest.jaxrs.model.UserdataimportCollection in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithDepartmentsOnNewUserCreation.
@Test
public void testImportWithDepartmentsOnNewUserCreation() throws IOException {
mock.setMockJsonContent("mock_user_creation_with_existng_department.json");
List<User> users = new ArrayList<>();
User user = generateUser("1234567", "Amy", "Cabble", null);
user.setDepartments(Set.of("Accounting"));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(1)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
use of org.folio.rest.jaxrs.model.UserdataimportCollection in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithUserCreationWithoutPersonalData.
@Test
public void testImportWithUserCreationWithoutPersonalData() throws IOException {
mock.setMockJsonContent("mock_user_creation_without_personal_data.json");
User user = generateUser("1234567", "Amy", "Cabble", null);
user.setPersonal(null);
List<User> users = new ArrayList<>();
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(1)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(0)).body(FAILED_USERS, hasSize(0)).statusCode(200);
}
use of org.folio.rest.jaxrs.model.UserdataimportCollection in project mod-user-import by folio-org.
the class UserImportAPITest method testImportWithPatronGroupResponseError.
@Test
public void testImportWithPatronGroupResponseError() throws IOException {
mock.setMockJsonContent("mock_patron_groups_error.json");
List<User> users = new ArrayList<>();
users.add(generateUser("1234567", "Amy", "Cabble", null));
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.FAILED_TO_IMPORT_USERS)).body(ERROR, containsString(UserImportAPIConstants.FAILED_TO_LIST_PATRON_GROUPS)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(1)).body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString(UserImportAPIConstants.FAILED_TO_LIST_PATRON_GROUPS)).body(FAILED_USERS, hasSize(1)).statusCode(500);
}
use of org.folio.rest.jaxrs.model.UserdataimportCollection in project mod-user-import by folio-org.
the class UserImportAPITest method testImportUsersWithNotExistedCustomFieldOptions.
@Test
public void testImportUsersWithNotExistedCustomFieldOptions() throws IOException {
mock.setMockJsonContent("mock_user_creation_with_custom_fields.json");
List<User> users = new ArrayList<>();
User user = generateUser("1234567", "Amy", "Cabble", null).withCustomFields(new CustomFields().withAdditionalProperty("department_1", "Development"));
users.add(user);
UserdataimportCollection collection = new UserdataimportCollection().withUsers(users).withTotalRecords(1);
given().header(TENANT_HEADER).header(TOKEN_HEADER).header(new Header(XOkapiHeaders.URL, getOkapiUrl())).header(JSON_CONTENT_TYPE_HEADER).body(collection).post(USER_IMPORT).then().body(MESSAGE, equalTo(UserImportAPIConstants.USERS_WERE_IMPORTED_SUCCESSFULLY)).body(TOTAL_RECORDS, equalTo(1)).body(CREATED_RECORDS, equalTo(0)).body(UPDATED_RECORDS, equalTo(0)).body(FAILED_RECORDS, equalTo(1)).body(FAILED_USERS, hasSize(1)).body(FAILED_USERS + "[0]." + EXTERNAL_SYSTEM_ID, equalTo(users.get(0).getExternalSystemId())).body(FAILED_USERS + "[0]." + USERNAME, equalTo(users.get(0).getUsername())).body(FAILED_USERS + "[0]." + USER_ERROR_MESSAGE, containsString("Custom field's options do not exist in the system: [refId = department_1, options: [Development]].")).statusCode(200);
}
Aggregations