use of org.folio.common.OkapiParams in project mod-kb-ebsco-java by folio-org.
the class AccessTypesServiceImpl method save.
@Override
public CompletableFuture<AccessType> save(String credentialsId, AccessTypePostRequest postRequest, Map<String, String> okapiHeaders) {
AccessType requestData = postRequest.getData();
bodyValidator.validate(credentialsId, requestData);
if (requestData.getAttributes().getCredentialsId() == null) {
requestData.getAttributes().setCredentialsId(credentialsId);
}
return validateAccessTypeLimit(credentialsId, okapiHeaders).thenApply(o -> accessTypeToDbConverter.convert(requestData)).thenCombine(usersService.findByToken(new OkapiParams(okapiHeaders)), this::setCreatorMetaInfo).thenCompose(dbAccessType -> repository.save(dbAccessType, tenantId(okapiHeaders))).thenApply(accessTypeFromDbConverter::convert);
}
use of org.folio.common.OkapiParams in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn200WhenUserIdIsValid.
@Test
public void shouldReturn200WhenUserIdIsValid(TestContext context) throws IOException, URISyntaxException {
final String stubUserId = "88888888-8888-4888-8888-888888888888";
final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
Async async = context.async();
OKAPI_HEADERS.put(XOkapiHeaders.TENANT, STUB_TENANT);
OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withBody(TestUtil.readFile(USER_INFO_STUB_FILE))));
CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
info.thenCompose(userInfo -> {
context.assertNotNull(userInfo);
context.assertEquals("cedrick", userInfo.getUserName());
context.assertEquals("firstname_test", userInfo.getFirstName());
context.assertNull(userInfo.getMiddleName());
context.assertEquals("lastname_test", userInfo.getLastName());
async.complete();
return null;
}).exceptionally(throwable -> {
context.fail(throwable);
async.complete();
return null;
});
}
use of org.folio.common.OkapiParams in project mod-kb-ebsco-java by folio-org.
the class AccessTypesServiceImpl method update.
@Override
public CompletableFuture<Void> update(String credentialsId, String accessTypeId, AccessTypePutRequest putRequest, Map<String, String> okapiHeaders) {
AccessType requestData = putRequest.getData();
bodyValidator.validate(credentialsId, accessTypeId, requestData);
return fetchDbAccessType(credentialsId, accessTypeId, okapiHeaders).thenCombine(usersService.findByToken(new OkapiParams(okapiHeaders)), this::setUpdaterMetaInfo).thenApply(accessType -> updateFields(accessType, requestData.getAttributes())).thenCompose(dbAccessType -> repository.save(dbAccessType, tenantId(okapiHeaders))).thenApply(accessType -> null);
}
use of org.folio.common.OkapiParams in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn404WhenUserNotFound.
@Test
public void shouldReturn404WhenUserNotFound(TestContext context) {
final String stubUserId = "xyz";
final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
Async async = context.async();
OKAPI_HEADERS.put(XOkapiHeaders.TENANT, STUB_TENANT);
OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(404).withStatusMessage("User Not Found")));
CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
info.thenCompose(result -> {
context.assertNull(result);
async.complete();
return null;
}).exceptionally(exception -> {
context.assertTrue(exception.getCause() instanceof NotFoundException);
async.complete();
return null;
});
}
use of org.folio.common.OkapiParams in project mod-kb-ebsco-java by folio-org.
the class UsersLookUpServiceTest method shouldReturn401WhenUnauthorizedAccess.
@Test
public void shouldReturn401WhenUnauthorizedAccess(TestContext context) {
final String stubUserId = "a49cefad-7447-4f2f-9004-de32e7a6cc53";
final String stubUserIdEndpoint = GET_USER_ENDPOINT + stubUserId;
Async async = context.async();
OKAPI_HEADERS.put(XOkapiHeaders.URL, getWiremockUrl());
OKAPI_HEADERS.put(XOkapiHeaders.USER_ID, stubUserId);
stubFor(get(new UrlPathPattern(new RegexPattern(stubUserIdEndpoint), true)).willReturn(new ResponseDefinitionBuilder().withStatus(401).withStatusMessage("Authorization Failure")));
CompletableFuture<User> info = usersLookUpService.lookUpUser(new OkapiParams(OKAPI_HEADERS));
info.thenCompose(result -> {
context.assertNull(result);
async.complete();
return null;
}).exceptionally(exception -> {
context.assertTrue(exception.getCause() instanceof NotAuthorizedException);
async.complete();
return null;
});
}
Aggregations