Search in sources :

Example 16 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsHtmlNull.

@Test
public void generateOneQueryRuleNotEqualsHtmlNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().not().eq(htmlAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(boolQuery().mustNot(existsQuery(htmlAttrName))));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 17 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsScriptNull.

// TODO enable when implemented in QueryGenerator (see note in QueryGenerator)
// @Test
// public void generateOneQueryRuleNotEqualsMrefNull()
// {
// }
@Test
public void generateOneQueryRuleNotEqualsScriptNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().not().eq(scriptAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(boolQuery().mustNot(existsQuery(scriptAttrName))));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 18 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class QueryGeneratorReferencesTest method generateOneQueryRuleNotEqualsCompoundPartString.

@Test
public void generateOneQueryRuleNotEqualsCompoundPartString() {
    String value = "value";
    Query<Entity> q = new QueryImpl<>().not().eq(PREFIX + refCompoundPart0AttributeName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(nestedQuery(REF_ENTITY_ATT, termQuery(PREFIX + refCompoundPart0AttributeName + '.' + FIELD_NOT_ANALYZED, value), ScoreMode.Avg)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 19 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class L3CacheRepositoryDecoratorTest method beforeMethod.

@BeforeMethod
public void beforeMethod() {
    entityType = entityTypeFactory.create(repositoryName);
    entityType.addAttribute(attributeFactory.create().setDataType(INT).setName(ID), ROLE_ID);
    entityType.addAttribute(attributeFactory.create().setName(COUNTRY));
    when(entityManager.create(entityType, NO_POPULATE)).thenReturn(new DynamicEntity(entityType));
    entity1 = entityManager.create(entityType, NO_POPULATE);
    entity1.set(ID, 1);
    entity1.set(COUNTRY, "NL");
    entity2 = entityManager.create(entityType, NO_POPULATE);
    entity2.set(ID, 2);
    entity2.set(COUNTRY, "NL");
    entity3 = entityManager.create(entityType, NO_POPULATE);
    entity3.set(ID, 3);
    entity3.set(COUNTRY, "GB");
    when(delegateRepository.getCapabilities()).thenReturn(Sets.newHashSet(CACHEABLE));
    l3CacheRepositoryDecorator = new L3CacheRepositoryDecorator(delegateRepository, l3Cache, transactionInformation);
    verify(delegateRepository).getCapabilities();
    query = new QueryImpl<>().eq(COUNTRY, "GB");
    query.pageSize(10);
    query.sort(new Sort().on(COUNTRY));
    query.setFetch(fetch);
    when(delegateRepository.getEntityType()).thenReturn(entityType);
    when(delegateRepository.getName()).thenReturn(repositoryName);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) DynamicEntity(org.molgenis.data.support.DynamicEntity) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 20 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixWhenNoDuplicate.

@Test
public void testGetLabelWithPostFixWhenNoDuplicate() {
    String label = "label";
    when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.empty());
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
    String expected = "label";
    assertEquals(actual, expected);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5