blob: 6c0b8c4640ddf03fad1cff39328bf48760036795 [file] [log] [blame]
Michael Hanlf0785322015-11-13 16:14:45 +01001import com.fasterxml.jackson.databind.JsonNode;
Michael Hanla36fc332015-10-27 23:11:42 +01002import de.ids_mannheim.korap.config.BeanConfiguration;
Michael Hanlf0785322015-11-13 16:14:45 +01003import de.ids_mannheim.korap.query.serialize.QuerySerializer;
Michael Hanla36fc332015-10-27 23:11:42 +01004import de.ids_mannheim.korap.resource.rewrite.IdWriter;
5import de.ids_mannheim.korap.resource.rewrite.RewriteHandler;
Michael Hanlf0785322015-11-13 16:14:45 +01006import de.ids_mannheim.korap.utils.JsonUtils;
Michael Hanla36fc332015-10-27 23:11:42 +01007import org.junit.AfterClass;
8import org.junit.BeforeClass;
9import org.junit.Test;
10
11/**
12 * @author hanl
13 * @date 21/10/2015
14 */
15public class IdRewriteTest {
16
17 @BeforeClass
18 public static void setup() {
19 BeanConfiguration.loadClasspathContext();
20 }
21
22 @AfterClass
Michael Hanl19390652016-01-16 11:01:24 +010023 public static void close() {
Michael Hanla36fc332015-10-27 23:11:42 +010024 BeanConfiguration.closeApplication();
25 }
26
27 @Test
28 public void insertTokenId() {
29 RewriteHandler handler = new RewriteHandler(
30 BeanConfiguration.getBeans().getConfiguration());
31 assert handler.add(IdWriter.class);
32
Michael Hanlf0785322015-11-13 16:14:45 +010033 String query = "[surface=Wort]";
34 QuerySerializer s = new QuerySerializer();
35 s.setQuery(query, "poliqarp");
36
37 String value = handler.preProcess(s.toJSON(), null);
38 JsonNode result = JsonUtils.readTree(value);
39
40 assert result != null;
41 assert result.path("query").has("idn");
Michael Hanla36fc332015-10-27 23:11:42 +010042
43 }
44
45}