Changeset 4501
- Timestamp:
- 02/12/14 13:19:02 (10 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app
- Files:
-
- 5 added
- 3 deleted
- 7 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/pom.xml
r4498 r4501 50 50 <artifactId>spring-context</artifactId> 51 51 <version>${spring.version}</version> 52 <type>jar</type>53 52 <exclusions> 54 53 <!-- … … 66 65 <artifactId>spring-web</artifactId> 67 66 <version>${spring.version}</version> 68 <type>jar</type> 67 </dependency> 68 <dependency> 69 <groupId>org.springframework</groupId> 70 <artifactId>spring-test</artifactId> 71 <version>${spring.version}</version> 72 <scope>test</scope> 69 73 </dependency> 70 74 … … 94 98 <version>${solr.version}</version> 95 99 <type>jar</type> 100 </dependency> 101 <!-- JMOCK for mocking --> 102 <dependency> 103 <groupId>org.jmock</groupId> 104 <artifactId>jmock-junit4</artifactId> 105 <version>2.6.0</version> 106 <scope>test</scope> 107 <exclusions> 108 <exclusion> 109 <artifactId>junit-dep</artifactId> 110 <groupId>junit</groupId> 111 </exclusion> 112 </exclusions> 96 113 </dependency> 97 114 </dependencies> -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/VloWicketApplication.java
r4469 r4501 4 4 import org.apache.wicket.markup.html.WebPage; 5 5 import org.apache.wicket.protocol.http.WebApplication; 6 import org.apache.wicket.spring.injection.annot.SpringComponentInjector; 7 import org.springframework.beans.BeansException; 8 import org.springframework.context.ApplicationContext; 9 import org.springframework.context.ApplicationContextAware; 6 10 7 11 /** 8 * Application object for your web application. 9 * If you want to run thisapplication without deploying, run the Start class.10 * 12 * Application object for your web application. If you want to run this 13 * application without deploying, run the Start class. 14 * 11 15 * @see eu.clarin.cmdi.Start#main(String[]) 12 16 */ 13 public class VloWicketApplication extends WebApplication 14 { 15 /** 16 * @see org.apache.wicket.Application#getHomePage() 17 */ 18 @Override 19 public Class<? extends WebPage> getHomePage() 20 { 21 return FacetedSearchPage.class; 22 } 17 public class VloWicketApplication extends WebApplication implements ApplicationContextAware { 23 18 24 /** 25 * @see org.apache.wicket.Application#init() 26 */ 27 @Override 28 public void init() 29 { 30 super.init(); 19 private ApplicationContext applicationContext; 31 20 32 // add your configuration here 33 } 21 /** 22 * @return the home page of this application 23 * @see org.apache.wicket.Application#getHomePage() 24 */ 25 @Override 26 public Class<? extends WebPage> getHomePage() { 27 return FacetedSearchPage.class; 28 } 29 30 /** 31 * @see org.apache.wicket.Application#init() 32 */ 33 @Override 34 public void init() { 35 super.init(); 36 // this listener will inject any spring beans that need to be autowired 37 getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext)); 38 } 39 40 /** 41 * Method needed for dynamic injection of application context (as happens in 42 * unit tests) 43 * 44 * @param applicationContext 45 * @throws BeansException 46 */ 47 @Override 48 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 49 this.applicationContext = applicationContext; 50 } 34 51 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/components/FacetsPanel.java
r4500 r4501 17 17 package eu.clarin.cmdi.vlo.components; 18 18 19 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 20 import eu.clarin.cmdi.vlo.service.FacetFieldsService; 21 import eu.clarin.cmdi.vlo.service.impl.FacetFieldsDataProvider; 19 22 import org.apache.solr.client.solrj.response.FacetField; 20 import org.apache.wicket.markup.html.list.ListItem;21 import org.apache.wicket.markup.html.list.ListView;22 23 import org.apache.wicket.markup.html.panel.Panel; 24 import org.apache.wicket.markup.repeater.Item; 25 import org.apache.wicket.markup.repeater.data.DataView; 26 import org.apache.wicket.markup.repeater.data.IDataProvider; 23 27 import org.apache.wicket.model.util.ListModel; 28 import org.apache.wicket.spring.injection.annot.SpringBean; 24 29 25 30 /** … … 29 34 public class FacetsPanel extends Panel { 30 35 31 public FacetsPanel(String id, ListModel<FacetField> model) { 36 @SpringBean 37 private FacetFieldsService facetFieldsService; 38 39 public FacetsPanel(String id, ListModel<FacetSelection> model) { 32 40 super(id, model); 33 add(new ListView<FacetField>("facets", model) { 41 42 final IDataProvider<FacetField> provider = new FacetFieldsDataProvider(facetFieldsService, model); 43 add(new DataView<FacetField>("facets", provider) { 34 44 35 45 @Override 36 protected void populateItem(ListItem<FacetField> item) { 37 //TODO: Check whether a value has been selected or not 46 protected void populateItem(Item<FacetField> item) { 38 47 item.add(new FacetPanel("facet", item.getModel())); 39 48 } 40 49 }); 41 50 } 42 43 51 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/config/VloSpringConfig.java
r4498 r4501 18 18 19 19 import eu.clarin.cmdi.vlo.VloWicketApplication; 20 import eu.clarin.cmdi.vlo.service.FacetFieldsService; 21 import eu.clarin.cmdi.vlo.service.SearchResultsDao; 22 import eu.clarin.cmdi.vlo.service.SolrQueryFactory; 23 import eu.clarin.cmdi.vlo.service.impl.SearchResultsDaoImpl; 24 import eu.clarin.cmdi.vlo.service.impl.SolrFacetFieldsService; 25 import eu.clarin.cmdi.vlo.service.impl.SolrQueryFactoryImpl; 26 import org.springframework.beans.factory.annotation.Value; 20 27 import org.springframework.context.annotation.Bean; 21 28 import org.springframework.context.annotation.Configuration; … … 24 31 * Annotation based Spring configuration for the VLO web application. 25 32 * 26 * Note: this works because {@link org.apache.wicket.spring.SpringWebApplicationFactory} 27 * is used in place of the standard Wicket application factory and annotation 28 * driven configuration is enabled in WEB-INF/applicationContext.xml 33 * Note: this works because 34 * {@link org.apache.wicket.spring.SpringWebApplicationFactory} is used in place 35 * of the standard Wicket application factory and annotation driven 36 * configuration is enabled in WEB-INF/applicationContext.xml 29 37 * 30 38 * @author twagoo … … 38 46 */ 39 47 @Bean 40 VloWicketApplication webApplication() {48 public VloWicketApplication webApplication() { 41 49 return new VloWicketApplication(); 42 50 } 51 52 @Bean 53 public VloConfig vloConfig() { 54 VloConfig.readPackagedConfig(); 55 return VloConfig.config; 56 } 57 58 @Bean 59 public FacetFieldsService facetFieldsService() { 60 return new SolrFacetFieldsService(searchResultsDao(), queryFactory()); 61 } 62 63 @Bean 64 public SearchResultsDao searchResultsDao() { 65 return new SearchResultsDaoImpl(vloConfig().getSolrUrl()); 66 } 67 68 public SolrQueryFactory queryFactory() { 69 return new SolrQueryFactoryImpl(); 70 } 43 71 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetedSearchPage.java
r4500 r4501 2 2 3 3 import eu.clarin.cmdi.vlo.components.FacetsPanel; 4 import eu.clarin.cmdi.vlo.pojo.Facet; 5 import eu.clarin.cmdi.vlo.pojo.FacetSelection; 4 6 import java.util.Arrays; 5 import org.apache.solr.client.solrj.response.FacetField;7 import java.util.Collections; 6 8 import org.apache.wicket.request.mapper.parameter.PageParameters; 7 9 import org.apache.wicket.markup.html.WebPage; … … 14 16 public FacetedSearchPage(final PageParameters parameters) { 15 17 super(parameters); 16 17 add(new FacetsPanel("facets", new ListModel<FacetField>(Arrays.asList( 18 new FacetField("Language"), 19 new FacetField("Resource type"))))); 18 final FacetSelection languageSelection = new FacetSelection(new Facet("Language"), Collections.singleton("Dutch")); 19 final FacetSelection typeSelection = new FacetSelection(new Facet("Resource type"), Collections.<String>emptySet()); 20 21 add(new FacetsPanel("facets", 22 new ListModel<FacetSelection>( 23 Arrays.asList(languageSelection, typeSelection) 24 ))); 20 25 } 21 26 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/SearchResultsDao.java
r4480 r4501 1 package eu.clarin.cmdi.vlo.service.impl; 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 */ 2 17 3 import eu.clarin.cmdi.vlo.FacetConstants; 18 package eu.clarin.cmdi.vlo.service; 19 4 20 import java.util.List; 5 21 import org.apache.solr.client.solrj.SolrQuery; 6 22 import org.apache.solr.client.solrj.response.FacetField; 7 import org.apache.solr.client.solrj.response.QueryResponse;8 23 import org.apache.solr.common.SolrDocumentList; 9 24 10 public class SearchResultsDao extends SolrDao { 25 /** 26 * 27 * @author twagoo 28 */ 29 public interface SearchResultsDao { 11 30 12 //private final static Logger LOG = LoggerFactory.getLogger(SearchResultsDao.class);31 SolrDocumentList getDocIdList(SolrQuery query); 13 32 14 private QueryResponse response;33 List<FacetField> getFacets(SolrQuery query); 15 34 16 public SearchResultsDao() { 17 super(); 18 } 19 20 public SolrDocumentList getResults(SolrQuery query) { 21 setDefaultSortField(query); 22 response = fireQuery(query); 23 SolrDocumentList results = response.getResults(); 24 return results; 25 } 26 27 public List<FacetField> getFacets(SolrQuery query) { 28 response = fireQuery(query); 29 return response.getFacetFields(); 30 } 31 32 public SolrDocumentList getDocIdList(SolrQuery query) { 33 setDefaultSortField(query); 34 query.setFields(FacetConstants.FIELD_ID); 35 query.setFacet(false); 36 query.setStart(0); 37 query.setRows(Integer.MAX_VALUE); 38 QueryResponse queryResponse = fireQuery(query); 39 return queryResponse.getResults(); 40 } 41 42 private void setDefaultSortField(SolrQuery query) { 43 if (query.getSortField() == null) { 44 query.setSortField(FacetConstants.FIELD_NAME, SolrQuery.ORDER.asc); 45 } 46 } 47 35 SolrDocumentList getResults(SolrQuery query); 36 48 37 } -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/AutoCompleteDao.java
r4480 r4501 15 15 * 16 16 */ 17 public class AutoCompleteDao extends SolrDao {17 public class AutoCompleteDao extends SolrDaoImpl { 18 18 19 public AutoCompleteDao(String solrUrl) { 20 super(solrUrl); 21 } 22 19 23 /** 20 24 * Returns list of suggestions for incomplete input (used for autocomplete -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/SearchResultsDaoImpl.java
r4480 r4501 1 1 package eu.clarin.cmdi.vlo.service.impl; 2 2 3 import eu.clarin.cmdi.vlo.service.SearchResultsDao; 3 4 import eu.clarin.cmdi.vlo.FacetConstants; 4 5 import java.util.List; … … 8 9 import org.apache.solr.common.SolrDocumentList; 9 10 10 public class SearchResultsDao extends SolrDao {11 public class SearchResultsDaoImpl extends SolrDaoImpl implements SearchResultsDao { 11 12 12 //private final static Logger LOG = LoggerFactory.getLogger(SearchResultsDao.class); 13 14 private QueryResponse response; 15 16 public SearchResultsDao() { 17 super(); 13 public SearchResultsDaoImpl(String solrUrl) { 14 super(solrUrl); 18 15 } 19 16 17 @Override 20 18 public SolrDocumentList getResults(SolrQuery query) { 21 22 23 24 19 setDefaultSortField(query); 20 QueryResponse response = fireQuery(query); 21 SolrDocumentList results = response.getResults(); 22 return results; 25 23 } 26 24 25 @Override 27 26 public List<FacetField> getFacets(SolrQuery query) { 28 29 27 QueryResponse response = fireQuery(query); 28 return response.getFacetFields(); 30 29 } 31 30 31 @Override 32 32 public SolrDocumentList getDocIdList(SolrQuery query) { 33 setDefaultSortField(query); 34 query.setFields(FacetConstants.FIELD_ID); 35 query.setFacet(false); 36 query.setStart(0); 37 query.setRows(Integer.MAX_VALUE); 38 QueryResponse queryResponse = fireQuery(query); 39 return queryResponse.getResults(); 33 query = query.getCopy(); 34 setDefaultSortField(query); 35 query.setFields(FacetConstants.FIELD_ID); 36 query.setFacet(false); 37 query.setStart(0); 38 query.setRows(Integer.MAX_VALUE); 39 QueryResponse queryResponse = fireQuery(query); 40 return queryResponse.getResults(); 40 41 } 41 42 42 43 private void setDefaultSortField(SolrQuery query) { 43 44 query.setSortField(FacetConstants.FIELD_NAME, SolrQuery.ORDER.asc);45 44 if (query.getSortField() == null) { 45 query.setSort(SolrQuery.SortClause.asc(FacetConstants.FIELD_NAME)); 46 } 46 47 } 47 48 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/SolrDaoImpl.java
r4480 r4501 16 16 import org.slf4j.LoggerFactory; 17 17 18 public class SolrDao {18 public class SolrDaoImpl { 19 19 20 private final static Logger LOG = LoggerFactory.getLogger(SolrDao .class);20 private final static Logger LOG = LoggerFactory.getLogger(SolrDaoImpl.class); 21 21 private final HttpSolrServer solrServer; 22 22 23 public SolrDao() { 24 String solrUrl; 25 solrUrl = VloConfig.getSolrUrl(); 23 public SolrDaoImpl(String solrUrl) { 26 24 solrServer = new HttpSolrServer(solrUrl); 27 25 } -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/pages/TestFacetedSearchPage.java
r4469 r4501 2 2 3 3 import eu.clarin.cmdi.vlo.VloWicketApplication; 4 import eu.clarin.cmdi.vlo.config.VloSpringConfig; 5 import eu.clarin.cmdi.vlo.service.FacetFieldsService; 6 import java.util.Arrays; 7 import java.util.List; 8 import org.apache.solr.client.solrj.response.FacetField; 4 9 import org.apache.wicket.util.tester.WicketTester; 10 import org.jmock.Expectations; 11 import org.jmock.Mockery; 12 import org.jmock.integration.junit4.JUnit4Mockery; 5 13 import org.junit.Before; 6 14 import org.junit.Test; 15 import org.junit.runner.RunWith; 16 import org.springframework.beans.factory.annotation.Autowired; 17 import org.springframework.context.annotation.Bean; 18 import org.springframework.context.annotation.ComponentScan; 19 import org.springframework.context.annotation.Configuration; 20 import org.springframework.test.context.ContextConfiguration; 21 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 22 import org.springframework.test.context.support.AnnotationConfigContextLoader; 7 23 8 24 /** 9 * Simple test using the WicketTester 25 * Abstract base class for tests that require dependency injection of (mock) 26 * objects and services. Based on blog post by Petri Kainulainen found at 27 * {@link http://www.petrikainulainen.net/programming/tips-and-tricks/mocking-spring-beans-with-apache-wicket-and-mockito/} 28 * 10 29 */ 11 public class TestFacetedSearchPage 12 { 13 private WicketTester tester; 30 @RunWith(SpringJUnit4ClassRunner.class) 31 @ContextConfiguration(loader = AnnotationConfigContextLoader.class) 32 public class TestFacetedSearchPage { 14 33 15 @Before 16 public void setUp() 17 { 18 tester = new WicketTester(new VloWicketApplication()); 19 } 34 @Configuration 35 @ComponentScan 36 static class ContextConfiguration extends VloSpringConfig { 20 37 21 @Test 22 public void homepageRendersSuccessfully() 23 { 24 //start and render the test page 25 tester.startPage(FacetedSearchPage.class); 38 @Bean 39 public Mockery mockery() { 40 return new JUnit4Mockery(); 41 } 26 42 27 //assert rendered page class 28 tester.assertRenderedPage(FacetedSearchPage.class); 29 } 43 @Override 44 public FacetFieldsService facetFieldsService() { 45 return mockery().mock(FacetFieldsService.class); 46 } 47 48 } 49 50 private WicketTester tester; 51 @Autowired 52 private VloWicketApplication application; 53 @Autowired 54 private Mockery mockery; 55 @Autowired 56 private FacetFieldsService facetFieldsService; 57 58 @Before 59 public void setUp() { 60 tester = new WicketTester(application); 61 } 62 63 @Test 64 public void homepageRendersSuccessfully() { 65 // mock behaviour of facet fields service 66 mockery.checking(new Expectations() { 67 { 68 oneOf(facetFieldsService).getFacetFieldCount(); 69 will(returnValue(2L)); 70 oneOf(facetFieldsService).getFacetFields(with(any(List.class))); 71 will(returnValue(Arrays.asList(new FacetField("language"), new FacetField("resource class")))); 72 } 73 }); 74 75 //start and render the test page 76 tester.startPage(FacetedSearchPage.class); 77 78 //assert rendered page class 79 tester.assertRenderedPage(FacetedSearchPage.class); 80 } 30 81 }
Note: See TracChangeset
for help on using the changeset viewer.