Changeset 4652
- Timestamp:
- 03/07/14 15:39:42 (10 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/RecordPage.java
r4649 r4652 52 52 53 53 public RecordPage(PageParameters params) { 54 super(new SolrDocumentModel(params.get("docId").toString())); 54 super(params); 55 56 final SolrDocumentModel documentModel = new SolrDocumentModel(params.get("docId").toString()); 57 setModel(documentModel); 58 55 59 final QueryFacetsSelection selection = selectionParametersConverter.fromParameters(params); 56 60 this.contextModel = Model.of(selection); 57 addComponents(getModel()); 61 62 addComponents(documentModel); 58 63 } 59 64 … … 65 70 66 71 private void addComponents(IModel<SolrDocument> documentModel) { 67 if (documentModel.getObject() == null) {68 throw new RuntimeException("Document not found in model " + documentModel.toString());69 }70 72 add(new SolrFieldLabel("name", documentModel, FacetConstants.FIELD_NAME, "Unnamed record")); 71 73 add(createLandingPageLink("landingPageLink", documentModel)); -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/pages/TestFacetedSearchPage.java
r4631 r4652 20 20 import org.springframework.beans.factory.annotation.Autowired; 21 21 import org.springframework.context.annotation.Bean; 22 import org.springframework.context.annotation.ComponentScan;23 22 import org.springframework.context.annotation.Configuration; 24 import org.springframework.test.annotation.DirtiesContext;25 23 import org.springframework.test.context.ContextConfiguration; 26 24 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; … … 28 26 29 27 /** 30 * Abstract base class for tests that require dependency injection of (mock) 31 * objects and services. Based on blog post by Petri Kainulainen found at 28 * Mock injection based on blog post by Petri Kainulainen found at 32 29 * {@link http://www.petrikainulainen.net/programming/tips-and-tricks/mocking-spring-beans-with-apache-wicket-and-mockito/} 33 *34 30 */ 35 31 @RunWith(SpringJUnit4ClassRunner.class) 36 32 @ContextConfiguration(loader = AnnotationConfigContextLoader.class) 37 //@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) // gives us a fresh context for each test38 33 public class TestFacetedSearchPage { 39 34 -
vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/wicket/pages/TestRecordPage.java
r4640 r4652 6 6 import eu.clarin.cmdi.vlo.config.VloConfigFactory; 7 7 import eu.clarin.cmdi.vlo.config.VloSpringConfig; 8 import eu.clarin.cmdi.vlo. pojo.QueryFacetsSelection;8 import eu.clarin.cmdi.vlo.service.SolrDocumentService; 9 9 import org.apache.solr.common.SolrDocument; 10 import org.apache.wicket. model.Model;10 import org.apache.wicket.request.mapper.parameter.PageParameters; 11 11 import org.apache.wicket.util.tester.WicketTester; 12 import org.jmock.Expectations; 13 import static org.jmock.Expectations.returnValue; 14 import org.jmock.Mockery; 15 import org.jmock.integration.junit4.JUnit4Mockery; 12 16 import org.junit.Before; 13 17 import org.junit.Test; 14 18 import org.junit.runner.RunWith; 15 19 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.context.annotation.Bean; 16 21 import org.springframework.context.annotation.Configuration; 17 22 import org.springframework.test.annotation.DirtiesContext; … … 21 26 import org.springframework.test.context.support.AnnotationConfigContextLoader; 22 27 28 /** 29 * Mock injection based on blog post by Petri Kainulainen found at 30 * {@link http://www.petrikainulainen.net/programming/tips-and-tricks/mocking-spring-beans-with-apache-wicket-and-mockito/} 31 */ 23 32 @RunWith(SpringJUnit4ClassRunner.class) 24 33 @ContextConfiguration(loader = AnnotationConfigContextLoader.class) … … 28 37 @Configuration 29 38 static class ContextConfiguration extends VloSpringConfig { 39 40 @Bean 41 public Mockery mockery() { 42 return new JUnit4Mockery(); 43 } 44 45 @Override 46 public SolrDocumentService documentService() { 47 return mockery().mock(SolrDocumentService.class); 48 } 30 49 31 50 @Override … … 40 59 @Autowired(required = true) 41 60 private VloWicketApplication application; 61 @Autowired(required = true) 62 private Mockery mockery; 63 @Autowired(required = true) 64 private SolrDocumentService documentService; 42 65 43 private QueryFacetsSelection selection;44 66 private SolrDocument document; 67 private PageParameters params; 45 68 46 69 @Before … … 48 71 tester = new WicketTester(application); 49 72 document = new SolrDocument(); 50 selection = new QueryFacetsSelection(); 73 params = new PageParameters(); 74 params.set("docId", "docId"); 51 75 } 52 76 53 77 @Test 54 78 public void testRendersSuccessfully() { 55 tester.startPage(new RecordPage(new Model(document), new Model(selection))); 79 mockery.checking(new Expectations() { 80 { 81 oneOf(documentService).getDocument("docId"); 82 will(returnValue(document)); 83 } 84 }); 85 tester.startPage(RecordPage.class, params); 56 86 //assert rendered page class 57 87 tester.assertRenderedPage(RecordPage.class); … … 60 90 @Test 61 91 public void testLandingPageLinkInvisible() { 62 tester.startPage(new RecordPage(new Model(document), new Model(selection))); 92 mockery.checking(new Expectations() { 93 { 94 oneOf(documentService).getDocument("docId"); 95 will(returnValue(document)); 96 } 97 }); 98 tester.startPage(RecordPage.class, params); 63 99 // no landing page for document, assert landing page link is invisible 64 100 tester.assertInvisible("landingPageLink"); … … 68 104 public void testLandingPageLinkVisible() { 69 105 document.addField(FacetConstants.FIELD_LANDINGPAGE, "http://www.landingpage.com"); 70 tester.startPage(new RecordPage(new Model(document), new Model(selection))); 106 107 mockery.checking(new Expectations() { 108 { 109 oneOf(documentService).getDocument("docId"); 110 will(returnValue(document)); 111 } 112 }); 113 tester.startPage(RecordPage.class, params); 71 114 // document has a landing page, assert link is invisible 72 115 tester.assertVisible("landingPageLink"); 73 116 } 74 117 75 118 //TODO: Add test for display of resources 76 119 }
Note: See TracChangeset
for help on using the changeset viewer.