| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.cache; |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 2 | |
| 3 | import static org.junit.Assert.assertNotNull; |
| 4 | import static org.junit.Assert.assertTrue; |
| 5 | |
| 6 | import java.io.IOException; |
| 7 | |
| 8 | import org.junit.Test; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | |
| 11 | import de.ids_mannheim.korap.KrillCollection; |
| 12 | import de.ids_mannheim.korap.collection.CachedVCData; |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 13 | import de.ids_mannheim.korap.config.NamedVCLoader; |
| 14 | import de.ids_mannheim.korap.config.SpringJerseyTest; |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 15 | import de.ids_mannheim.korap.dao.VirtualCorpusDao; |
| 16 | import de.ids_mannheim.korap.entity.VirtualCorpus; |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 17 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| 18 | import de.ids_mannheim.korap.util.QueryException; |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 19 | import net.sf.ehcache.CacheManager; |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 20 | import net.sf.ehcache.Element; |
| 21 | |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 22 | public class NamedVCLoaderTest extends SpringJerseyTest { |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 23 | |
| 24 | @Autowired |
| 25 | private NamedVCLoader vcLoader; |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 26 | @Autowired |
| 27 | private VirtualCorpusDao dao; |
| 28 | |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 29 | @Test |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 30 | public void testNamedVCLoader () |
| 31 | throws IOException, QueryException, KustvaktException { |
| 32 | KrillCollection.cache = CacheManager.newInstance().getCache("named_vc"); |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 33 | Element element = KrillCollection.cache.get("named-vc1"); |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 34 | assertTrue(element == null); |
| 35 | |
| 36 | vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld"); |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 37 | |
| 38 | element = KrillCollection.cache.get("named-vc1"); |
| 39 | assertNotNull(element); |
| 40 | CachedVCData cachedData = (CachedVCData) element.getObjectValue(); |
| 41 | assertTrue(cachedData.getDocIdMap().size() > 0); |
| margaretha | 9e53bb2 | 2018-09-14 19:39:15 +0200 | [diff] [blame] | 42 | |
| 43 | KrillCollection.cache.removeAll(); |
| 44 | VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system"); |
| 45 | dao.deleteVirtualCorpus(vc); |
| margaretha | 563aabe | 2018-09-13 20:39:45 +0200 | [diff] [blame] | 46 | } |
| 47 | } |