|
11 | 11 | import static org.junit.Assert.assertFalse; |
12 | 12 | import static org.junit.Assert.assertTrue; |
13 | 13 |
|
| 14 | +import java.io.ByteArrayInputStream; |
14 | 15 | import java.io.IOException; |
15 | 16 | import java.io.Writer; |
16 | 17 | import java.nio.charset.StandardCharsets; |
|
27 | 28 | import org.apache.solr.common.SolrDocument; |
28 | 29 | import org.apache.solr.common.SolrInputDocument; |
29 | 30 | import org.dspace.AbstractIntegrationTestWithDatabase; |
| 31 | +import org.dspace.builder.BitstreamBuilder; |
| 32 | +import org.dspace.builder.CollectionBuilder; |
30 | 33 | import org.dspace.builder.CommunityBuilder; |
| 34 | +import org.dspace.builder.ItemBuilder; |
| 35 | +import org.dspace.content.Bitstream; |
| 36 | +import org.dspace.content.Collection; |
31 | 37 | import org.dspace.content.Community; |
| 38 | +import org.dspace.content.Item; |
32 | 39 | import org.dspace.content.factory.ContentServiceFactory; |
33 | 40 | import org.dspace.core.Constants; |
34 | 41 | import org.dspace.core.factory.CoreServiceFactory; |
@@ -303,4 +310,56 @@ public void testDeleteRobots() |
303 | 310 | } |
304 | 311 | assertEquals("Wrong number of documents remaining --", 1, nDocs); |
305 | 312 | } |
| 313 | + |
| 314 | + @Test |
| 315 | + public void testPostViewShouldNotLogIgnoredBundles() throws Exception { |
| 316 | + ContentServiceFactory csf = ContentServiceFactory.getInstance(); |
| 317 | + MockSolrLoggerServiceImpl solrLoggerService = DSpaceServicesFactory.getInstance() |
| 318 | + .getServiceManager() |
| 319 | + .getServiceByName("solrLoggerService", MockSolrLoggerServiceImpl.class); |
| 320 | + solrLoggerService.bitstreamService = csf.getBitstreamService(); |
| 321 | + solrLoggerService.contentServiceFactory = csf; |
| 322 | + solrLoggerService.configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); |
| 323 | + solrLoggerService.clientInfoService = CoreServiceFactory.getInstance().getClientInfoService(); |
| 324 | + solrLoggerService.afterPropertiesSet(); |
| 325 | + SolrStatisticsCore solrStatisticsCore = DSpaceServicesFactory.getInstance() |
| 326 | + .getServiceManager() |
| 327 | + .getServiceByName(SolrStatisticsCore.class.getName(), MockSolrStatisticsCore.class); |
| 328 | + |
| 329 | + solrStatisticsCore.getSolr().deleteByQuery("*:*"); |
| 330 | + solrStatisticsCore.getSolr().commit(); |
| 331 | + |
| 332 | + context.turnOffAuthorisationSystem(); |
| 333 | + Community community = CommunityBuilder |
| 334 | + .createCommunity(context) |
| 335 | + .withName("Test Community").build(); |
| 336 | + Collection collection = CollectionBuilder |
| 337 | + .createCollection(context, community) |
| 338 | + .withName("Test Collection").build(); |
| 339 | + Item item = ItemBuilder |
| 340 | + .createItem(context, collection) |
| 341 | + .withTitle("Test Item for Logging").build(); |
| 342 | + Bitstream originalBitstream = BitstreamBuilder |
| 343 | + .createBitstream(context, item, new ByteArrayInputStream("original content".getBytes()), "ORIGINAL") |
| 344 | + .withName("original.txt") |
| 345 | + .build(); |
| 346 | + Bitstream thumbnailBitstream = BitstreamBuilder |
| 347 | + .createBitstream(context, item, new ByteArrayInputStream("thumbnail content".getBytes()), "THUMBNAIL") |
| 348 | + .withName("thumbnail.jpg") |
| 349 | + .build(); |
| 350 | + |
| 351 | + context.restoreAuthSystemState(); |
| 352 | + solrLoggerService.postView(originalBitstream, null, eperson); |
| 353 | + solrLoggerService.postView(thumbnailBitstream, null, eperson); |
| 354 | + |
| 355 | + solrStatisticsCore.getSolr().commit(); |
| 356 | + |
| 357 | + SolrQuery thumbnailQuery = new SolrQuery("id:" + thumbnailBitstream.getID().toString()); |
| 358 | + QueryResponse thumbnailResponse = solrStatisticsCore.getSolr().query(thumbnailQuery); |
| 359 | + assertEquals("Thumbnail bundle should NOT be logged", 0, thumbnailResponse.getResults().getNumFound()); |
| 360 | + |
| 361 | + SolrQuery originalQuery = new SolrQuery("id:" + originalBitstream.getID().toString()); |
| 362 | + QueryResponse originalResponse = solrStatisticsCore.getSolr().query(originalQuery); |
| 363 | + assertEquals("ORIGINAL bundle SHOULD be logged", 1, originalResponse.getResults().getNumFound()); |
| 364 | + } |
306 | 365 | } |
0 commit comments