Search in sources :

Example 1 with KbCredentialsPatchRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPatchRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn404OnPatchWhenCredentialsAreMissing.

@Test
public void shouldReturn404OnPatchWhenCredentialsAreMissing() {
    KbCredentialsPatchRequest kbCredentialsPatchRequest = stubPatchRequest();
    kbCredentialsPatchRequest.getData().getAttributes().setName(STUB_CREDENTIALS_NAME);
    String patchBody = Json.encode(kbCredentialsPatchRequest);
    mockVerifyValidCredentialsRequest();
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/11111111-1111-1111-a111-111111111111";
    JsonapiError error = patchWithStatus(resourcePath, patchBody, SC_NOT_FOUND, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "KbCredentials not found by id");
}
Also used : JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with KbCredentialsPatchRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPatchRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn204OnPatchIfCredentialsAreValid.

@Test
public void shouldReturn204OnPatchIfCredentialsAreValid() {
    String credentialsId = saveKbCredentials(getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    KbCredentialsPatchRequest kbCredentialsPatchRequest = stubPatchRequest();
    kbCredentialsPatchRequest.getData().getAttributes().setCustomerId("updated");
    String patchBody = Json.encode(kbCredentialsPatchRequest);
    mockVerifyValidCredentialsRequest();
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/" + credentialsId;
    patchWithNoContent(resourcePath, patchBody, STUB_TOKEN_HEADER);
    KbCredentials actual = getKbCredentialsNonSecured(vertx).get(0);
    assertNotNull(actual);
    assertNotNull(actual.getId());
    assertNotNull(actual.getType());
    assertEquals(getWiremockUrl(), actual.getAttributes().getUrl());
    assertEquals(STUB_API_KEY, actual.getAttributes().getApiKey());
    assertEquals(STUB_CREDENTIALS_NAME, actual.getAttributes().getName());
    assertEquals("updated", actual.getAttributes().getCustomerId());
    assertEquals(STUB_USERNAME, actual.getMeta().getCreatedByUsername());
    assertEquals(STUB_USER_ID, actual.getMeta().getCreatedByUserId());
    assertNotNull(actual.getMeta().getCreatedDate());
    assertEquals(STUB_USERNAME, actual.getMeta().getUpdatedByUsername());
    assertEquals(STUB_USER_ID, actual.getMeta().getUpdatedByUserId());
    assertNotNull(actual.getMeta().getUpdatedDate());
}
Also used : KbCredentialsTestUtil.saveKbCredentials(org.folio.util.KbCredentialsTestUtil.saveKbCredentials) KbCredentialsTestUtil.getKbCredentials(org.folio.util.KbCredentialsTestUtil.getKbCredentials) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) Test(org.junit.Test)

Example 3 with KbCredentialsPatchRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPatchRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPatchWhenCredentialsWithProvidedNameAlreadyExist.

@Test
public void shouldReturn422OnPatchWhenCredentialsWithProvidedNameAlreadyExist() {
    saveKbCredentials(getWiremockUrl(), STUB_CREDENTIALS_NAME, STUB_API_KEY, STUB_CUSTOMER_ID, vertx);
    String credentialsId = saveKbCredentials(getWiremockUrl(), STUB_CREDENTIALS_NAME + "2", STUB_API_KEY, OTHER_CUST_ID, vertx);
    KbCredentialsPatchRequest kbCredentialsPatchRequest = stubPatchRequest();
    kbCredentialsPatchRequest.getData().getAttributes().setName(STUB_CREDENTIALS_NAME);
    String patchBody = Json.encode(kbCredentialsPatchRequest);
    mockVerifyValidCredentialsRequest();
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/" + credentialsId;
    JsonapiError error = patchWithStatus(resourcePath, patchBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Duplicate name");
    assertErrorContainsDetail(error, String.format("Credentials with name '%s' already exist", STUB_CREDENTIALS_NAME));
}
Also used : JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) Matchers.containsString(org.hamcrest.Matchers.containsString) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) Test(org.junit.Test)

Example 4 with KbCredentialsPatchRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPatchRequest in project mod-kb-ebsco-java by folio-org.

the class EholdingsKbCredentialsImplTest method shouldReturn422OnPatchWhenCredentialsNameIsLongerThen255.

@Test
public void shouldReturn422OnPatchWhenCredentialsNameIsLongerThen255() {
    KbCredentialsPatchRequest kbCredentialsPatchRequest = stubPatchRequest();
    kbCredentialsPatchRequest.getData().getAttributes().setName(Strings.repeat('*', 256));
    String patchBody = Json.encode(kbCredentialsPatchRequest);
    String resourcePath = KB_CREDENTIALS_ENDPOINT + "/11111111-1111-1111-a111-111111111111";
    JsonapiError error = patchWithStatus(resourcePath, patchBody, SC_UNPROCESSABLE_ENTITY, STUB_TOKEN_HEADER).as(JsonapiError.class);
    assertErrorContainsTitle(error, "Invalid name");
    assertErrorContainsDetail(error, "name is too long (maximum is 255 characters)");
}
Also used : JsonapiError(org.folio.rest.jaxrs.model.JsonapiError) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 5 with KbCredentialsPatchRequest

use of org.folio.rest.jaxrs.model.KbCredentialsPatchRequest in project mod-kb-ebsco-java by folio-org.

the class KbCredentialsServiceImpl method updatePartially.

@Override
public CompletableFuture<Void> updatePartially(String id, KbCredentialsPatchRequest entity, Map<String, String> okapiHeaders) {
    KbCredentials patchRequestData = convertPatchToCredentials(entity);
    patchBodyValidator.validate(patchRequestData);
    KbCredentialsDataAttributes attributes = patchRequestData.getAttributes();
    return prepareAndSave(fetchDbKbCredentials(id, okapiHeaders), (dbCredentials, userInfo) -> preparePartialUpdateEntity(dbCredentials, attributes, userInfo), okapiHeaders).thenApply(dbKbCredentials -> null);
}
Also used : KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) DbKbCredentials(org.folio.repository.kbcredentials.DbKbCredentials) KbCredentialsPutBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPutBodyValidator) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) BiFunction(java.util.function.BiFunction) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationInvalidException(org.folio.holdingsiq.service.exception.ConfigurationInvalidException) CompletableFuture(java.util.concurrent.CompletableFuture) KbCredentialsCollection(org.folio.rest.jaxrs.model.KbCredentialsCollection) Function(java.util.function.Function) Context(io.vertx.core.Context) ConfigurationService(org.folio.holdingsiq.service.ConfigurationService) KbCredentialsKey(org.folio.rest.jaxrs.model.KbCredentialsKey) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) RowSetUtils.fromUUID(org.folio.db.RowSetUtils.fromUUID) ConversionService(org.springframework.core.convert.ConversionService) KbCredentialsPatchBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPatchBodyValidator) KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes) KbCredentialsPostRequest(org.folio.rest.jaxrs.model.KbCredentialsPostRequest) OkapiData(org.folio.holdingsiq.model.OkapiData) UserInfo(org.folio.util.UserInfo) Collection(java.util.Collection) KbCredentialsPutRequest(org.folio.rest.jaxrs.model.KbCredentialsPutRequest) TenantTool.tenantId(org.folio.rest.tools.utils.TenantTool.tenantId) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) HoldingsService(org.folio.service.holdings.HoldingsService) StringUtils.defaultIfBlank(org.apache.commons.lang3.StringUtils.defaultIfBlank) OffsetDateTime(java.time.OffsetDateTime) KbCredentialsPatchRequest(org.folio.rest.jaxrs.model.KbCredentialsPatchRequest) ServiceExceptions(org.folio.service.exc.ServiceExceptions) KbCredentialsPostBodyValidator(org.folio.rest.validator.kbcredentials.KbCredentialsPostBodyValidator) Optional(java.util.Optional) Configuration(org.folio.holdingsiq.model.Configuration) TokenUtils.fetchUserInfo(org.folio.util.TokenUtils.fetchUserInfo) KbCredentialsRepository(org.folio.repository.kbcredentials.KbCredentialsRepository) KbCredentials(org.folio.rest.jaxrs.model.KbCredentials) DbKbCredentials(org.folio.repository.kbcredentials.DbKbCredentials) KbCredentialsDataAttributes(org.folio.rest.jaxrs.model.KbCredentialsDataAttributes)

Aggregations

KbCredentialsPatchRequest (org.folio.rest.jaxrs.model.KbCredentialsPatchRequest)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Test (org.junit.Test)9 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)8 KbCredentials (org.folio.rest.jaxrs.model.KbCredentials)2 Context (io.vertx.core.Context)1 OffsetDateTime (java.time.OffsetDateTime)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 BiFunction (java.util.function.BiFunction)1 Function (java.util.function.Function)1 StringUtils.defaultIfBlank (org.apache.commons.lang3.StringUtils.defaultIfBlank)1 RowSetUtils.fromUUID (org.folio.db.RowSetUtils.fromUUID)1 RowSetUtils.toUUID (org.folio.db.RowSetUtils.toUUID)1 Configuration (org.folio.holdingsiq.model.Configuration)1 OkapiData (org.folio.holdingsiq.model.OkapiData)1