use of com.yahoo.search.pagetemplates.engine.Resolver in project vespa by vespa-engine.
the class ChoiceOfTwoSourcesTestCase method testExecution.
@Test
public void testExecution() {
// Create the page template
Choice page = Choice.createSingleton(importPage("ChoiceOfTwoSources.xml"));
// Create a federated result
Query query = new Query();
Result result = new Result(query);
result.hits().add(createHits("source1", 3));
result.hits().add(createHits("source2", 3));
result.hits().add(createHits("source3", 3));
// Resolve
Resolver resolver = new DeterministicResolver();
Resolution resolution = resolver.resolve(page, query, result);
assertEquals(1, resolution.getResolution((Choice) ((PageTemplate) page.get(0).get(0)).getSection().elements(Source.class).get(0)));
// Execute
Organizer organizer = new Organizer();
organizer.organize(page, resolution, result);
// Check execution:
// No subsections: Last choice (source2) used
assertEqualHitGroups(createHits("source2", 3), result.hits());
// Check rendering
assertRendered(result, "ChoiceOfTwoSourcesResult.xml");
}
use of com.yahoo.search.pagetemplates.engine.Resolver in project vespa by vespa-engine.
the class MapSourcesToSectionsTestCase method testExecution.
@Test
public void testExecution() {
// Create the page template
Choice page = Choice.createSingleton(importPage("MapSourcesToSections.xml"));
// Create a federated result
Query query = new Query();
Result result = new Result(query);
result.hits().add(createHits("source1", 3));
result.hits().add(createHits("source2", 4));
result.hits().add(createHits("source3", 5));
result.hits().add(createHits("source4", 6));
result.hits().add(createHits("source5", 7));
// Resolve
Resolver resolver = new DeterministicResolverAssertingMethod();
Resolution resolution = resolver.resolve(page, query, result);
Map<String, List<PageElement>> mapping = resolution.getResolution((MapChoice) ((PageTemplate) page.get(0).get(0)).getSection().elements().get(2));
assertNotNull(mapping);
assertEquals("source1", ((Source) mapping.get("box1source").get(0)).getName());
assertEquals("source2", ((Source) mapping.get("box2source").get(0)).getName());
assertEquals("source3", ((Source) mapping.get("box3source").get(0)).getName());
assertEquals("source4", ((Source) mapping.get("box4source").get(0)).getName());
// Execute
Organizer organizer = new Organizer();
organizer.organize(page, resolution, result);
// Check execution:
// Two subsections, each containing two sub-subsections with one source each
assertEquals(2, result.hits().size());
HitGroup row1 = (HitGroup) result.hits().get(0);
HitGroup column11 = (HitGroup) row1.get(0);
HitGroup column12 = (HitGroup) row1.get(1);
HitGroup row2 = (HitGroup) result.hits().get(1);
HitGroup column21 = (HitGroup) row2.get(0);
HitGroup column22 = (HitGroup) row2.get(1);
assertEqualHitGroups(createHits("source1", 3), column11);
assertEqualHitGroups(createHits("source2", 4), column12);
assertEqualHitGroups(createHits("source3", 5), column21);
assertEqualHitGroups(createHits("source4", 6), column22);
// Check rendering
assertRendered(result, "MapSourcesToSectionsResult.xml");
}
Aggregations