use of org.apache.syncope.core.persistence.jpa.entity.user.JPAUPlainAttrValue in project syncope by apache.
the class ElasticsearchAnySearchDAOTest method searchRequest_groupOwner.
@Test
public void searchRequest_groupOwner() throws IOException {
// 1. mock
AnyUtils anyUtils = mock(AnyUtils.class);
when(anyUtils.getField("id")).thenReturn(ReflectionUtils.findField(JPAUser.class, "id"));
when(anyUtils.newPlainAttrValue()).thenReturn(new JPAUPlainAttrValue());
when(anyUtilsFactory.getInstance(AnyTypeKind.USER)).thenReturn(anyUtils);
when(entityFactory.newEntity(PlainSchema.class)).thenReturn(new JPAPlainSchema());
when(groupDAO.findKey("groupKey")).thenReturn("groupKey");
try (MockedStatic<ElasticsearchUtils> utils = Mockito.mockStatic(ElasticsearchUtils.class)) {
utils.when(() -> ElasticsearchUtils.getContextDomainName(SyncopeConstants.MASTER_DOMAIN, AnyTypeKind.USER)).thenReturn("master_user");
// 2. test
Set<String> adminRealms = Set.of(RealmUtils.getGroupOwnerRealm("/any", "groupKey"));
AnyCond anyCond = new AnyCond(AttrCond.Type.ISNOTNULL);
anyCond.setSchema("id");
SearchRequest request = new SearchRequest.Builder().index(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), AnyTypeKind.USER)).searchType(SearchType.QueryThenFetch).query(searchDAO.getQuery(adminRealms, SearchCond.getLeaf(anyCond), AnyTypeKind.USER)).from(1).size(10).build();
assertThat(new Query.Builder().bool(QueryBuilders.bool().must(new Query.Builder().exists(QueryBuilders.exists().field("id").build()).build()).must(new Query.Builder().term(QueryBuilders.term().field("memberships").value(FieldValue.of("groupKey")).build()).build()).build()).build()).usingRecursiveComparison().isEqualTo(request.query());
}
}
Aggregations