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");
}
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());
}
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));
}
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)");
}
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);
}
Aggregations