blob: 667fc32bf95f88799d034c141442f27e02d228b8 [file] [log] [blame]
margaretha7cd52d12023-03-15 16:56:06 +01001package de.ids_mannheim.korap.web.controller;
2
Marc Kupietzd43a98d2023-09-22 17:11:46 +02003import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
margaretha205dc5b2024-06-05 11:12:11 +02005import static org.junit.jupiter.api.Assertions.assertNull;
Marc Kupietzd43a98d2023-09-22 17:11:46 +02006import static org.junit.jupiter.api.Assertions.assertTrue;
margaretha7cd52d12023-03-15 16:56:06 +01007
Marc Kupietzd43a98d2023-09-22 17:11:46 +02008import org.junit.jupiter.api.Test;
margaretha205dc5b2024-06-05 11:12:11 +02009import org.springframework.beans.factory.annotation.Autowired;
margaretha7cd52d12023-03-15 16:56:06 +010010
11import com.google.common.net.HttpHeaders;
12
13import de.ids_mannheim.korap.cache.VirtualCorpusCache;
14import de.ids_mannheim.korap.config.SpringJerseyTest;
margaretha205dc5b2024-06-05 11:12:11 +020015import de.ids_mannheim.korap.dao.QueryDao;
16import de.ids_mannheim.korap.entity.QueryDO;
margaretha7cd52d12023-03-15 16:56:06 +010017import de.ids_mannheim.korap.exceptions.KustvaktException;
margaretha96c309d2023-08-16 12:24:12 +020018import jakarta.ws.rs.client.Entity;
19import jakarta.ws.rs.core.Form;
20import jakarta.ws.rs.core.MediaType;
21import jakarta.ws.rs.core.Response;
22import jakarta.ws.rs.core.Response.Status;
margaretha7cd52d12023-03-15 16:56:06 +010023
24public class AdminLoadVCTest extends SpringJerseyTest {
margaretha205dc5b2024-06-05 11:12:11 +020025
26 @Autowired
27 private QueryDao dao;
28
margaretha7cd52d12023-03-15 16:56:06 +010029
30 @Test
margaretha35e1ca22023-11-16 22:00:01 +010031 public void testLoadCacheVC ()
32 throws KustvaktException, InterruptedException {
margaretha7cd52d12023-03-15 16:56:06 +010033 assertFalse(VirtualCorpusCache.contains("named-vc1"));
34 Form f = new Form();
35 f.param("token", "secret");
margaretha35e1ca22023-11-16 22:00:01 +010036 Response response = target().path(API_VERSION).path("admin").path("vc")
37 .path("load-cache").request()
38 .header(HttpHeaders.CONTENT_TYPE,
39 MediaType.APPLICATION_FORM_URLENCODED)
40 .post(Entity.form(f));
margaretha7cd52d12023-03-15 16:56:06 +010041 assertEquals(Status.OK.getStatusCode(), response.getStatus());
margaretha205dc5b2024-06-05 11:12:11 +020042 Thread.sleep(200);
43
margaretha7cd52d12023-03-15 16:56:06 +010044 assertTrue(VirtualCorpusCache.contains("named-vc1"));
margaretha7cd52d12023-03-15 16:56:06 +010045 VirtualCorpusCache.reset();
46 assertFalse(VirtualCorpusCache.contains("named-vc1"));
margaretha205dc5b2024-06-05 11:12:11 +020047
48 QueryDO vc = dao.retrieveQueryByName("named-vc1", "system");
49 dao.deleteQuery(vc);
50 vc = dao.retrieveQueryByName("named-vc1", "system");
51 assertNull(vc);
margaretha7cd52d12023-03-15 16:56:06 +010052 }
53}