Search in sources :

Example 11 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-circulation-storage by folio-org.

the class RequestPreferencesApiTest method canDeleteRequestPreferenceById.

@Test
public void canDeleteRequestPreferenceById() {
    RequestPreference preference = createRequestPreference().getJson().mapTo(RequestPreference.class);
    JsonResponse response = deletePreference(preference.getId());
    assertThat(response, isNoContent());
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 12 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-circulation-storage by folio-org.

the class RequestPreferencesApiTest method canGetRequestPreferences.

@Test
public void canGetRequestPreferences() {
    createRequestPreference(USER_ID);
    createRequestPreference(USER_ID2);
    JsonResponse responseGet = getPreferences("");
    List<RequestPreference> preferences = responseGet.getJson().getJsonArray("requestPreferences").stream().map(o -> ((JsonObject) o).mapTo(RequestPreference.class)).collect(Collectors.toList());
    assertThat(responseGet.getJson().getInteger("totalRecords"), is(2));
    assertThat(preferences, hasItem(hasProperty("userId", Matchers.is(USER_ID))));
    assertThat(preferences, hasItem(hasProperty("userId", Matchers.is(USER_ID2))));
}
Also used : ResponseHandler(org.folio.rest.support.ResponseHandler) JsonResponse(org.folio.rest.support.JsonResponse) RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HttpResponseStatusCodeMatchers.isNotFound(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isNotFound) Before(org.junit.Before) MalformedURLException(java.net.MalformedURLException) HttpResponseStatusCodeMatchers.isCreated(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isCreated) HttpResponseStatusCodeMatchers.isUnprocessableEntity(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isUnprocessableEntity) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) UUID(java.util.UUID) ApiTests(org.folio.rest.support.ApiTests) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) RequestPreferences(org.folio.rest.jaxrs.model.RequestPreferences) List(java.util.List) Matchers.hasItem(org.hamcrest.Matchers.hasItem) HttpResponseStatusCodeMatchers.isNoContent(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isNoContent) Matchers.containsString(org.hamcrest.Matchers.containsString) RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 13 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-circulation-storage by folio-org.

the class RequestPreferencesApiTest method cannotUpdateRequestPreferenceWithInvalidId.

@Test
public void cannotUpdateRequestPreferenceWithInvalidId() {
    RequestPreference preference = constructDefaultPreference(USER_ID).withId("invalid_id");
    JsonResponse response = updatePreference(preference);
    assertThat(response, isUnprocessableEntity());
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 14 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportData method fetchRequestPreferences.

private Map<String, RequestPreference> fetchRequestPreferences(UserdataimportCollection userdataCollection) {
    final Map<String, RequestPreference> requestPreferenceMap = new HashMap<>();
    for (User user : userdataCollection.getUsers()) {
        requestPreferenceMap.put(user.getUsername(), user.getRequestPreference());
        user.setRequestPreference(null);
    }
    return requestPreferenceMap;
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference) User(org.folio.rest.jaxrs.model.User) HashMap(java.util.HashMap)

Example 15 with RequestPreference

use of org.folio.rest.jaxrs.model.RequestPreference in project mod-user-import by folio-org.

the class UserImportAPI method createUserPreference.

private Future<RequestPreference> createUserPreference(User user, UserImportData userImportData, Map<String, String> okapiHeaders) {
    RequestPreference requestPreference = userImportData.getRequestPreferences().get(user.getUsername());
    if (requestPreference == null) {
        return Future.succeededFuture();
    }
    requestPreference.setUserId(user.getId());
    return prefService.validate(requestPreference, userImportData, user).compose(o -> {
        udpService.updateUserPreference(requestPreference, userImportData);
        return prefService.create(okapiHeaders, requestPreference);
    });
}
Also used : RequestPreference(org.folio.rest.jaxrs.model.RequestPreference)

Aggregations

RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)24 Test (org.junit.Test)20 User (org.folio.rest.jaxrs.model.User)12 Header (io.restassured.http.Header)11 ArrayList (java.util.ArrayList)11 TestUtils.generateUser (org.folio.TestUtils.generateUser)11 UserdataimportCollection (org.folio.rest.jaxrs.model.UserdataimportCollection)11 JsonResponse (org.folio.rest.support.JsonResponse)9 Address (org.folio.rest.jaxrs.model.Address)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 RequestPreferences (org.folio.rest.jaxrs.model.RequestPreferences)2 JsonObject (io.vertx.core.json.JsonObject)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1