blob: 7e3736afb7244f947f4729fc85d1767a0988790c [file] [log] [blame]
margaretha5c67dd52018-12-18 17:27:05 +01001package de.ids_mannheim.korap.cache;
margaretha563aabe2018-09-13 20:39:45 +02002
3import static org.junit.Assert.assertNotNull;
4import static org.junit.Assert.assertTrue;
5
6import java.io.IOException;
7
8import org.junit.Test;
9import org.springframework.beans.factory.annotation.Autowired;
10
11import de.ids_mannheim.korap.KrillCollection;
12import de.ids_mannheim.korap.collection.CachedVCData;
margaretha5c67dd52018-12-18 17:27:05 +010013import de.ids_mannheim.korap.config.NamedVCLoader;
14import de.ids_mannheim.korap.config.SpringJerseyTest;
margaretha9e53bb22018-09-14 19:39:15 +020015import de.ids_mannheim.korap.dao.VirtualCorpusDao;
16import de.ids_mannheim.korap.entity.VirtualCorpus;
margaretha563aabe2018-09-13 20:39:45 +020017import de.ids_mannheim.korap.exceptions.KustvaktException;
18import de.ids_mannheim.korap.util.QueryException;
margaretha9e53bb22018-09-14 19:39:15 +020019import net.sf.ehcache.CacheManager;
margaretha563aabe2018-09-13 20:39:45 +020020import net.sf.ehcache.Element;
21
margaretha9e53bb22018-09-14 19:39:15 +020022public class NamedVCLoaderTest extends SpringJerseyTest {
margaretha563aabe2018-09-13 20:39:45 +020023
24 @Autowired
25 private NamedVCLoader vcLoader;
margaretha9e53bb22018-09-14 19:39:15 +020026 @Autowired
27 private VirtualCorpusDao dao;
28
margaretha563aabe2018-09-13 20:39:45 +020029 @Test
margaretha9e53bb22018-09-14 19:39:15 +020030 public void testNamedVCLoader ()
31 throws IOException, QueryException, KustvaktException {
32 KrillCollection.cache = CacheManager.newInstance().getCache("named_vc");
margaretha563aabe2018-09-13 20:39:45 +020033 Element element = KrillCollection.cache.get("named-vc1");
margaretha9e53bb22018-09-14 19:39:15 +020034 assertTrue(element == null);
35
36 vcLoader.loadVCToCache("named-vc1", "/vc/named-vc1.jsonld");
margaretha563aabe2018-09-13 20:39:45 +020037
38 element = KrillCollection.cache.get("named-vc1");
39 assertNotNull(element);
40 CachedVCData cachedData = (CachedVCData) element.getObjectValue();
41 assertTrue(cachedData.getDocIdMap().size() > 0);
margaretha9e53bb22018-09-14 19:39:15 +020042
43 KrillCollection.cache.removeAll();
44 VirtualCorpus vc = dao.retrieveVCByName("named-vc1", "system");
45 dao.deleteVirtualCorpus(vc);
margaretha563aabe2018-09-13 20:39:45 +020046 }
47}