Search in sources :

Example 36 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetRange.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetRange() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(// "avant 2000", "2000-2005", "après 2005"
    yearFacetDefinition).build();
    final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, searchQuery, null);
    // On vérifie qu'il existe une valeur pour chaque marques et que le nombre d'occurrences est correct
    final Map<String, List<Car>> databaseCluster = new HashMap<>();
    databaseCluster.put(YearCluster.before2000.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.between2000and2005.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.after2005.getLabel(), new ArrayList<>());
    for (final Car car : carDataBase.getAllCars()) {
        if (car.getYear() < 2000) {
            databaseCluster.get(YearCluster.before2000.getLabel()).add(car);
        } else if (car.getYear() < 2005) {
            databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(car);
        } else {
            databaseCluster.get(YearCluster.after2005.getLabel()).add(car);
        }
    }
    Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
    for (final Entry<FacetValue, DtList<Car>> entry : result.getClusters().entrySet()) {
        final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
        final int searchFacetCount = entry.getValue().size();
        final List<Car> carsByYear = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(carsByYear.size(), searchFacetCount);
        for (final Car car : entry.getValue()) {
            if (car.getYear() < 2000) {
                Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
            } else if (car.getYear() < 2005) {
                Assert.assertEquals(searchFacetLabel, YearCluster.between2000and2005.getLabel());
            } else {
                Assert.assertEquals(searchFacetLabel, YearCluster.after2005.getLabel());
            }
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) HashMap(java.util.HashMap) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Car(io.vertigo.dynamo.search_2_4.data.domain.Car) ArrayList(java.util.ArrayList) DtList(io.vertigo.dynamo.domain.model.DtList) List(java.util.List) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 37 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class AbstractSearchManagerTest method testClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
    // On vérifie qu'il existe une valeur pour chaque marques et que le nombre d'occurrences est correct
    final Map<String, List<Item>> databaseCluster = new HashMap<>();
    for (final Item item : itemDataBase.getAllItems()) {
        databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(item);
    }
    int previousCount = Integer.MAX_VALUE;
    Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
    for (final Entry<FacetValue, DtList<Item>> entry : result.getClusters().entrySet()) {
        final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
        final int searchFacetCount = entry.getValue().size();
        final List<Item> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByManufacturer.size(), searchFacetCount);
        Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
        previousCount = searchFacetCount;
        for (final Item item : entry.getValue()) {
            Assert.assertEquals(searchFacetLabel, item.getManufacturer().toLowerCase(Locale.FRENCH));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) ItemSearchLoader(io.vertigo.dynamo.search.data.domain.ItemSearchLoader) URLDecoder(java.net.URLDecoder) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Facet(io.vertigo.dynamo.collections.model.Facet) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ItemDataBase(io.vertigo.dynamo.search.data.domain.ItemDataBase) Item(io.vertigo.dynamo.search.data.domain.Item) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) Set(java.util.Set) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) Collectors(java.util.stream.Collectors) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) VUserException(io.vertigo.lang.VUserException) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Logger(org.apache.logging.log4j.Logger) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) ArrayList(java.util.ArrayList) DtList(io.vertigo.dynamo.domain.model.DtList) List(java.util.List) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 38 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testWhereInEmpty.

/**
 * Test exécution d'une tache.
 */
@Test
public void testWhereInEmpty() {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskList("TK_WHERE_ID_TEST", "select * from SUPER_HERO where ID in (#DTC_SUPER_HERO_IN.ROWNUM.ID#)");
        final DtList<SuperHero> ids = new DtList<>(SuperHero.class);
        final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, ids).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(0, resultList.size());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 39 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testWhereNotIn.

/**
 * Test exécution d'une tache.
 */
@Test
public void testWhereNotIn() {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskList("TK_WHERE_ID_TEST", "select * from SUPER_HERO where ID not in (#DTC_SUPER_HERO_IN.ROWNUM.ID#)");
        final DtList<SuperHero> ids = new DtList<>(SuperHero.class);
        final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, ids).build();
        ids.add(createSuperHero(10001L + 1));
        ids.add(createSuperHero(10001L + 3));
        ids.add(createSuperHero(10001L + 5));
        ids.add(createSuperHero(10001L + 6));
        ids.add(createSuperHero(10001L + 7));
        ids.add(createSuperHero(10001L + 8));
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(4, resultList.size());
        Assert.assertEquals(10001L + 0, resultList.get(0).getId().longValue());
        Assert.assertEquals(10001L + 2, resultList.get(1).getId().longValue());
        Assert.assertEquals(10001L + 4, resultList.get(2).getId().longValue());
        Assert.assertEquals(10001L + 9, resultList.get(3).getId().longValue());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 40 with DtList

use of io.vertigo.dynamo.domain.model.DtList in project vertigo by KleeGroup.

the class TaskEngineSelectDynamicTest method testWhereNotIn2200.

/**
 * Test where in avec 2200 Id a exclure.
 */
@Test
public void testWhereNotIn2200() {
    superHeroDataBase.populateSuperHero(storeManager, 4500);
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final TaskDefinition taskDefinition = registerTaskList("TK_WHERE_ID_TEST", "select * from SUPER_HERO  where ID not in (#DTC_SUPER_HERO_IN.ROWNUM.ID#)");
        final DtList<SuperHero> ids = new DtList<>(SuperHero.class);
        for (int i = 0; i < 2200; i++) {
            ids.add(createSuperHero(10001L + 2 * i));
        }
        final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, ids).build();
        final DtList<SuperHero> resultList = taskManager.execute(task).getResult();
        Assert.assertEquals(10 + 4500 - 2200, resultList.size());
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Aggregations

DtList (io.vertigo.dynamo.domain.model.DtList)49 Test (org.junit.Test)21 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)16 HashMap (java.util.HashMap)14 DtField (io.vertigo.dynamo.domain.metamodel.DtField)13 ArrayList (java.util.ArrayList)13 List (java.util.List)12 Facet (io.vertigo.dynamo.collections.model.Facet)8 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)8 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)8 Task (io.vertigo.dynamo.task.model.Task)8 Map (java.util.Map)8 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)7 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)7 URI (io.vertigo.dynamo.domain.model.URI)7 LinkedHashMap (java.util.LinkedHashMap)7 AbstractTestCaseJU4 (io.vertigo.AbstractTestCaseJU4)6 VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)5 ListFilter (io.vertigo.dynamo.collections.ListFilter)5