Search in sources :

Example 1 with UserdataimportCollection

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);
}
Also used : TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Address(org.folio.rest.jaxrs.model.Address) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 2 with UserdataimportCollection

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);
}
Also used : TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 3 with UserdataimportCollection

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);
}
Also used : TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 4 with UserdataimportCollection

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);
}
Also used : TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Example 5 with UserdataimportCollection

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);
}
Also used : CustomFields(org.folio.rest.jaxrs.model.CustomFields) TestUtils.generateUser(org.folio.TestUtils.generateUser) User(org.folio.rest.jaxrs.model.User) Header(io.restassured.http.Header) ArrayList(java.util.ArrayList) UserdataimportCollection(org.folio.rest.jaxrs.model.UserdataimportCollection) Test(org.junit.Test)

Aggregations

UserdataimportCollection (org.folio.rest.jaxrs.model.UserdataimportCollection)58 ArrayList (java.util.ArrayList)57 User (org.folio.rest.jaxrs.model.User)57 Header (io.restassured.http.Header)56 TestUtils.generateUser (org.folio.TestUtils.generateUser)55 Test (org.junit.Test)55 RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)13 Address (org.folio.rest.jaxrs.model.Address)8 CustomFields (org.folio.rest.jaxrs.model.CustomFields)5 CustomField (org.folio.rest.jaxrs.model.CustomField)4 Department (org.folio.rest.jaxrs.model.Department)4 IncludedObjects (org.folio.rest.jaxrs.model.IncludedObjects)4 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 AsyncResult (io.vertx.core.AsyncResult)2 CompositeFuture (io.vertx.core.CompositeFuture)2 Context (io.vertx.core.Context)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 HttpMethod (io.vertx.core.http.HttpMethod)2