blob: 99fb774e1568ff29a866f6e16b9a1bf38603ed18 [file] [log] [blame]
Michael Hanl55191d92013-12-05 11:53:10 +00001import de.ids_mannheim.korap.query.serialize.MetaCollectionSerializer;
2import de.ids_mannheim.korap.query.serialize.MetaQuerySerializer;
Michael Hanl296a0312013-12-05 17:27:51 +00003import org.joda.time.DateTime;
Michael Hanl55191d92013-12-05 11:53:10 +00004import org.junit.Test;
5import org.junit.runner.RunWith;
6import org.junit.runners.JUnit4;
7
8import java.io.IOException;
9import java.util.HashMap;
Michael Hanl296a0312013-12-05 17:27:51 +000010import java.util.LinkedHashMap;
Michael Hanl55191d92013-12-05 11:53:10 +000011import java.util.Map;
12
13/**
14 * @author hanl
15 * @date 04/12/2013
16 */
17
18@RunWith(JUnit4.class)
19public class MetaQuerySerializationTest {
20
Michael Hanl296a0312013-12-05 17:27:51 +000021 private MetaQuerySerializer querySerializer;
22 private MetaCollectionSerializer collSerializer;
Michael Hanl55191d92013-12-05 11:53:10 +000023
24 public MetaQuerySerializationTest() {
Michael Hanl296a0312013-12-05 17:27:51 +000025 querySerializer = new MetaQuerySerializer();
26 collSerializer = new MetaCollectionSerializer();
Michael Hanl55191d92013-12-05 11:53:10 +000027 }
28
29 @Test
30 public void test() throws IOException {
31 Map<String, String> j = new HashMap();
32 j.put("author", "Goethe");
Michael Hanl296a0312013-12-05 17:27:51 +000033 j.put("pubPlace", "Erfurt");
Michael Hanl55191d92013-12-05 11:53:10 +000034 j.put("textClass", "wissenschaft");
Michael Hanl296a0312013-12-05 17:27:51 +000035 String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
Michael Hanl55191d92013-12-05 11:53:10 +000036// System.out.println("value reference " + s);
37 }
38
39 @Test
40 public void testSingle() throws IOException {
41 Map<String, String> j = new HashMap();
42 j.put("textClass", "wissenschaft");
Michael Hanl296a0312013-12-05 17:27:51 +000043 String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER);
Michael Hanl55191d92013-12-05 11:53:10 +000044// System.out.println("value reference test single " + s);
45 }
46
47 @Test
48 public void testResourceMeta() throws IOException {
Michael Hanl296a0312013-12-05 17:27:51 +000049 String s = collSerializer.serialize("25");
50// System.out.println(" --- RESULT JSON " + s);
51 }
Michael Hanl55191d92013-12-05 11:53:10 +000052
Michael Hanl296a0312013-12-05 17:27:51 +000053 @Test
54 public void testDates() throws IOException {
55 Map<String, String> queries = new LinkedHashMap<>();
56 queries.put("<pubDate", String.valueOf(new DateTime().getMillis()));
Michael Hanl08b93ed2013-12-05 18:04:45 +000057 queries.put(">pubDate", String.valueOf(new DateTime().getMillis() + 2));
Michael Hanl296a0312013-12-05 17:27:51 +000058 queries.put("author", "Goethe");
59 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
Michael Hanl08b93ed2013-12-05 18:04:45 +000060// System.out.println("value : "+ f);
Michael Hanl55191d92013-12-05 11:53:10 +000061 }
Michael Hanl08b93ed2013-12-05 18:04:45 +000062
63 @Test
64 public void testUntil() throws IOException {
65 Map<String, String> queries = new LinkedHashMap<>();
66 queries.put(">pubDate", String.valueOf(new DateTime().getMillis()));
67 queries.put("author", "Hesse");
68 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
69 System.out.println("value until : " + f);
70 }
71
72 @Test
73 public void testSince() throws IOException {
74 Map<String, String> queries = new LinkedHashMap<>();
75 queries.put("<pubDate", String.valueOf(new DateTime().getMillis()));
76 queries.put("author", "Kafka");
77 String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER);
78 System.out.println("value since : " + f);
79 }
80
Michael Hanl55191d92013-12-05 11:53:10 +000081}