source: vlo/trunk/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/model/FacetFieldModelTest.java @ 6813

Last change on this file since 6813 was 6813, checked in by davor.ostojic@oeaw.ac.at, 9 years ago

#795 VLO web-app generates unnecessary requests. The idea behind is to fire SOLR query only when selection is changed.

File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 2014 CLARIN
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package eu.clarin.cmdi.vlo.wicket.model;
18
19import com.google.common.collect.ImmutableList;
20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
21import eu.clarin.cmdi.vlo.service.solr.FacetFieldsService;
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.List;
25import org.apache.solr.client.solrj.response.FacetField;
26import org.apache.wicket.model.IModel;
27import org.apache.wicket.model.Model;
28import org.jmock.Expectations;
29import static org.jmock.Expectations.returnValue;
30import org.jmock.Mockery;
31import org.jmock.integration.junit4.JUnit4Mockery;
32import static org.junit.Assert.*;
33import org.junit.Before;
34import org.junit.Test;
35
36/**
37 *
38 * @author twagoo
39 */
40public class FacetFieldModelTest {
41
42    private final Mockery context = new JUnit4Mockery();
43
44    private IModel<QueryFacetsSelection> selectionModel;
45    private QueryFacetsSelection selection;
46    private FacetFieldsService service;
47
48    @Before
49    public void setUp() {
50        service = context.mock(FacetFieldsService.class);
51        selection = new QueryFacetsSelection();
52        selectionModel = new Model(selection);
53    }
54
55    /**
56     * Test of load method, of class FacetFieldsModel.
57     */
58    @Test
59    public void testGetObject() {
60        final FacetFieldModel instance = new FacetFieldModel("facet4", new FacetFieldsModel(service, ImmutableList.of("facet4"), selectionModel, 20));
61       
62        context.checking(new Expectations() {
63            {
64                oneOf(service).getFacetFields(selection, ImmutableList.of("facet4"), 20);
65                will(returnValue(Arrays.asList(
66                        new FacetField("facet4")
67                )));
68            }
69        });
70
71        final FacetField result = instance.getObject();
72        // selection should be returned
73        assertEquals("facet4", result.getName());
74       
75        // make another call, should not trigger a call to service because model is loadabledetachable
76        final FacetField result2 = instance.getObject();
77        assertEquals(result, result2);
78    }
79   
80    /**
81     * Test of load method, of class FacetFieldsModel.
82     */
83    @Test
84    public void testGetObjectNotIncluded() {
85        final FacetFieldModel instance = new FacetFieldModel("facet4", new FacetFieldsModel(service, ImmutableList.of("facet4"), selectionModel, 20));
86
87        context.checking(new Expectations() {
88            {
89                oneOf(service).getFacetFields(selection, ImmutableList.of("facet4"), 20);
90                will(returnValue(Collections.emptyList()));
91            }
92        });
93
94        final FacetField result = instance.getObject();
95        // selection should be returned
96        assertNull(result);
97    }
98
99}
Note: See TracBrowser for help on using the repository browser.