use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.
the class SimpleSearchUserTest method searchNoMatches.
@Test(dependsOnMethods = "create", groups = "search")
public void searchNoMatches() {
String nowIsoDateTimeString = Instant.ofEpochMilli(System.currentTimeMillis()).toString();
SearchRequest sr = new SearchRequest();
sr.setFilter(String.format("urn:ietf:params:scim:schemas:extension:gluu:2.0:User:scimCustomThird eq 1 and displayName eq \"%s\" " + "and addresses[postalCode ne null or type eq null] and meta.lastModified gt \"%s\"", "test", nowIsoDateTimeString));
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
assertNull(listResponse.getResources());
}
use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.
the class ComplexSearchUserTest method searchExcludedAttributesParam.
@Test
public void searchExcludedAttributesParam() {
int count = 3;
List<String> attrList = Arrays.asList("x509Certificates", "entitlements", "roles", "ims", "phoneNumbers", "addresses", "emails", "groups");
logger.debug("Searching at most {} users using POST verb", count);
logger.debug("Sorted by displayName ascending");
logger.debug("Excluding the attributes {}", attrList);
SearchRequest sr = new SearchRequest();
sr.setFilter("displayName pr");
sr.setSortBy("displayName");
sr.setSortOrder("descending");
// Generate a string with the attributes to exclude
sr.setExcludedAttributes(attrList.toString().replaceFirst("\\[", "").replaceFirst("]", ""));
sr.setCount(count);
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
if (listResponse.getResources().size() < count)
logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
else {
// Obtain an array of results
UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
assertEquals(users.length, count);
// Verify attributes were excluded
for (UserResource u : users) {
assertNull(u.getX509Certificates());
assertNull(u.getEntitlements());
assertNull(u.getRoles());
assertNull(u.getIms());
assertNull(u.getPhoneNumbers());
assertNull(u.getAddresses());
assertNull(u.getEmails());
}
boolean correctSorting = true;
for (int i = 1; i < users.length && correctSorting; i++) {
String displayName = users[i - 1].getDisplayName();
String displayName2 = users[i].getDisplayName();
// Check if second string is less or equal than first
correctSorting = displayName.compareTo(displayName2) >= 0;
}
if (!correctSorting) {
// LDAP may ignore case sensitivity, try again using lowercasing
correctSorting = true;
for (int i = 1; i < users.length && correctSorting; i++) {
String displayName = users[i - 1].getDisplayName().toLowerCase();
String displayName2 = users[i].getDisplayName().toLowerCase();
// Check if second string is less or equal than first
correctSorting = displayName.compareTo(displayName2) >= 0;
}
}
assertTrue(correctSorting);
}
}
use of io.jans.scim.model.scim2.SearchRequest in project jans by JanssenProject.
the class ComplexSearchUserTest method searchSortByDate.
// This test is disabled to avoid problems in attribute excludeMetaLastMod being inconsistent with updatedAt in testing server
// @Test
public void searchSortByDate() {
SearchRequest sr = new SearchRequest();
sr.setFilter("userName pr");
sr.setSortBy("meta.lastModified");
sr.setAttributes(Collections.singletonList(sr.getSortBy()));
Response response = client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse = response.readEntity(ListResponse.class);
UserResource[] users = listResponse.getResources().stream().map(usrClass::cast).collect(Collectors.toList()).toArray(new UserResource[0]);
for (int i = 1; i < users.length; i++) {
String lastMod1 = users[i - 1].getMeta() == null ? null : users[i - 1].getMeta().getLastModified();
String lastMod2 = users[i].getMeta() == null ? null : users[i].getMeta().getLastModified();
if (// Both being non null is OK
lastMod1 != null)
assertNotNull(lastMod2);
if (// If second is null, first must be
lastMod2 == null)
assertNull(lastMod1);
if (lastMod1 != null && lastMod2 != null) {
ZonedDateTime dt1 = ZonedDateTime.parse(lastMod1);
ZonedDateTime dt2 = ZonedDateTime.parse(lastMod2);
assertTrue(dt1.isEqual(dt2) || dt1.isBefore(dt2));
}
}
}
use of io.jans.scim.model.scim2.SearchRequest in project java-retail by googleapis.
the class SearchSimpleQuery method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT QUERY PHRASES HERE:
String queryPhrase = "Hoodie";
String visitorId = UUID.randomUUID().toString();
int pageSize = 10;
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(queryPhrase).setVisitorId(visitorId).setPageSize(pageSize).build();
System.out.println("Search request: " + searchRequest);
try (SearchServiceClient client = SearchServiceClient.create()) {
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
System.out.println("Search response: " + searchResponse);
return searchResponse;
}
}
use of io.jans.scim.model.scim2.SearchRequest in project java-retail by googleapis.
the class SearchWithBoostSpec method getSearchResponse.
public static SearchResponse getSearchResponse(String defaultSearchPlacementName) throws IOException {
// TRY DIFFERENT CONDITIONS HERE:
String searchQuery = "Tee";
String condition = "(colorFamilies: ANY(\"Blue\"))";
float boost = 0.0f;
int pageSize = 10;
String visitorId = UUID.randomUUID().toString();
BoostSpec boostSpec = BoostSpec.newBuilder().addConditionBoostSpecs(ConditionBoostSpec.newBuilder().setCondition(condition).setBoost(boost).build()).build();
SearchRequest searchRequest = SearchRequest.newBuilder().setPlacement(defaultSearchPlacementName).setQuery(searchQuery).setVisitorId(visitorId).setBoostSpec(boostSpec).setPageSize(pageSize).build();
System.out.println("Search request: " + searchRequest);
try (SearchServiceClient client = SearchServiceClient.create()) {
SearchResponse searchResponse = client.search(searchRequest).getPage().getResponse();
System.out.println("Search response: " + searchResponse);
return searchResponse;
}
}
Aggregations