use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProviderTest method byNameNotFound.
@Test
public void byNameNotFound() {
stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType()).withBody(byNameEmptyResponse)));
UserDirectorySearchResult result = p.searchByDisplayName(byNameSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().isEmpty());
verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType())).withRequestBody(equalTo(byNameRequest)));
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class ExecDirectoryStoreTest method byNameSuccessEmptyResult.
@Test
public void byNameSuccessEmptyResult() {
UserDirectorySearchResult output = getStore("byNameSuccessEmptyResult").searchByDisplayName("user");
assertFalse(output.isLimited());
assertTrue(output.getResults().isEmpty());
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProviderTest method byThreepidNotFound.
@Test
public void byThreepidNotFound() {
stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType()).withBody(byThreepidEmptyResponse)));
UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
assertTrue(!result.isLimited());
assertTrue(result.getResults().isEmpty());
verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType())).withRequestBody(equalTo(byThreepidRequest)));
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class RestDirectoryProvider method search.
private UserDirectorySearchResult search(String by, String query) {
UserDirectorySearchRequest request = new UserDirectorySearchRequest(query);
request.setBy(by);
try (CloseableHttpResponse httpResponse = client.execute(RestClientUtils.post(cfg.getEndpoints().getDirectory(), request))) {
int status = httpResponse.getStatusLine().getStatusCode();
if (status < 200 || status >= 300) {
throw new InternalServerError("REST backend: Error: " + IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8));
}
UserDirectorySearchResult response = parser.parse(httpResponse, UserDirectorySearchResult.class);
for (UserDirectorySearchResult.Result result : response.getResults()) {
result.setUserId(MatrixID.asAcceptable(result.getUserId(), mxCfg.getDomain()).getId());
}
return response;
} catch (IOException e) {
throw new InternalServerError("REST backend: I/O error: " + e.getMessage());
}
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class MemoryIdentityStore method search.
private UserDirectorySearchResult search(Predicate<MemoryIdentityConfig> predicate, Function<MemoryIdentityConfig, UserDirectorySearchResult.Result> mapper) {
UserDirectorySearchResult search = new UserDirectorySearchResult();
cfg.getIdentities().stream().filter(predicate).map(mapper).forEach(search::addResult);
return search;
}
Aggregations