blob: ccd0011e5b89694a6d5c0d547c80fb91d11dc35c [file] [log] [blame]
Michael Hanlababa392013-12-05 21:57:37 +00001import com.fasterxml.jackson.core.JsonGenerationException;
2import com.fasterxml.jackson.databind.JsonMappingException;
3import de.ids_mannheim.korap.query.serialize.JsonGenerator;
Michael Hanl55191d92013-12-05 11:53:10 +00004import de.ids_mannheim.korap.query.serialize.MetaCollectionSerializer;
5import de.ids_mannheim.korap.query.serialize.MetaQuerySerializer;
Michael Hanl296a0312013-12-05 17:27:51 +00006import org.joda.time.DateTime;
Michael Hanl55191d92013-12-05 11:53:10 +00007import org.junit.Test;
8import org.junit.runner.RunWith;
9import org.junit.runners.JUnit4;
10
11import java.io.IOException;
12import java.util.HashMap;
Michael Hanl296a0312013-12-05 17:27:51 +000013import java.util.LinkedHashMap;
Michael Hanl55191d92013-12-05 11:53:10 +000014import java.util.Map;
15
16/**
17 * @author hanl
18 * @date 04/12/2013
19 */
20
21@RunWith(JUnit4.class)
22public class MetaQuerySerializationTest {
23
Michael Hanl296a0312013-12-05 17:27:51 +000024 private MetaQuerySerializer querySerializer;
25 private MetaCollectionSerializer collSerializer;
Michael Hanl55191d92013-12-05 11:53:10 +000026
27 public MetaQuerySerializationTest() {
Michael Hanl296a0312013-12-05 17:27:51 +000028 querySerializer = new MetaQuerySerializer();
29 collSerializer = new MetaCollectionSerializer();
Michael Hanl55191d92013-12-05 11:53:10 +000030 }
31
32 @Test
33 public void test() throws IOException {
34 Map<String, String> j = new HashMap();
35 j.put("author", "Goethe");
Michael Hanl296a0312013-12-05 17:27:51 +000036 j.put("pubPlace", "Erfurt");
Michael Hanl55191d92013-12-05 11:53:10 +000037 j.put("textClass", "wissenschaft");
Michael Hanl296a0312013-12-05 17:27:51 +000038 String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
Michael Hanl55191d92013-12-05 11:53:10 +000039// System.out.println("value reference " + s);
40 }
41
42 @Test
43 public void testSingle() throws IOException {
44 Map<String, String> j = new HashMap();
45 j.put("textClass", "wissenschaft");
Michael Hanl296a0312013-12-05 17:27:51 +000046 String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
Michael Hanlababa392013-12-05 21:57:37 +000047 System.out.println("------ TEXT SINGLE " + s);
Michael Hanl55191d92013-12-05 11:53:10 +000048 }
49
50 @Test
51 public void testResourceMeta() throws IOException {
Michael Hanl296a0312013-12-05 17:27:51 +000052 String s = collSerializer.serialize("25");
Michael Hanlababa392013-12-05 21:57:37 +000053 System.out.println(" --- RESULT JSON " + s);
Michael Hanl296a0312013-12-05 17:27:51 +000054 }
Michael Hanl55191d92013-12-05 11:53:10 +000055
Michael Hanl296a0312013-12-05 17:27:51 +000056 @Test
57 public void testDates() throws IOException {
58 Map<String, String> queries = new LinkedHashMap<>();
Michael Hanlababa392013-12-05 21:57:37 +000059 queries.put("pubDate", String.valueOf(new DateTime().getMillis()) + "~"
60 + String.valueOf(new DateTime().getMillis() + 2));
Michael Hanl296a0312013-12-05 17:27:51 +000061 queries.put("author", "Goethe");
62 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
Michael Hanlababa392013-12-05 21:57:37 +000063 System.out.println("value until/since : " + f);
Michael Hanl55191d92013-12-05 11:53:10 +000064 }
Michael Hanl08b93ed2013-12-05 18:04:45 +000065
66 @Test
67 public void testUntil() throws IOException {
68 Map<String, String> queries = new LinkedHashMap<>();
Michael Hanlababa392013-12-05 21:57:37 +000069 queries.put("pubDate", ">" + String.valueOf(new DateTime().getMillis()));
Michael Hanl08b93ed2013-12-05 18:04:45 +000070 queries.put("author", "Hesse");
71 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
72 System.out.println("value until : " + f);
73 }
74
75 @Test
76 public void testSince() throws IOException {
77 Map<String, String> queries = new LinkedHashMap<>();
Michael Hanlababa392013-12-05 21:57:37 +000078 queries.put("pubDate", "<" + String.valueOf(new DateTime().getMillis()));
Michael Hanl08b93ed2013-12-05 18:04:45 +000079 queries.put("author", "Kafka");
80 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
81 System.out.println("value since : " + f);
82 }
83
Michael Hanlababa392013-12-05 21:57:37 +000084 //@Test
85 public void testGenerator() {
86 /*
87 * just for testing...
88 */
89 JsonGenerator jg = new JsonGenerator();
90 int i = 0;
91 String[] queries;
92 queries = new String[]{
93 "shrink({[base=foo]})",
94 "shrink({[base=foo]}[orth=bar])",
95 "shrink(1:[base=Der]{1:[base=Mann]})",
96 };
97
98 for (String q : queries) {
99 i++;
100 try {
101 System.out.println(q);
102 jg.run(q, "poliqarp", System.getProperty("user.home") + "/bsp" + i + ".json");
103 System.out.println();
104 } catch (NullPointerException npe) {
105 npe.printStackTrace();
106 System.out.println("null\n");
107 } catch (JsonGenerationException e) {
108 e.printStackTrace();
109 } catch (JsonMappingException e) {
110 e.printStackTrace();
111 } catch (IOException e) {
112 e.printStackTrace();
113 }
114 }
115 }
116
Michael Hanl55191d92013-12-05 11:53:10 +0000117}