Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 1 | import de.ids_mannheim.korap.query.serialize.MetaCollectionSerializer; |
| 2 | import de.ids_mannheim.korap.query.serialize.MetaQuerySerializer; |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 3 | import org.joda.time.DateTime; |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 4 | import org.junit.Test; |
| 5 | import org.junit.runner.RunWith; |
| 6 | import org.junit.runners.JUnit4; |
| 7 | |
| 8 | import java.io.IOException; |
| 9 | import java.util.HashMap; |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 10 | import java.util.LinkedHashMap; |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 11 | import java.util.Map; |
| 12 | |
| 13 | /** |
| 14 | * @author hanl |
| 15 | * @date 04/12/2013 |
| 16 | */ |
| 17 | |
| 18 | @RunWith(JUnit4.class) |
| 19 | public class MetaQuerySerializationTest { |
| 20 | |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 21 | private MetaQuerySerializer querySerializer; |
| 22 | private MetaCollectionSerializer collSerializer; |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 23 | |
| 24 | public MetaQuerySerializationTest() { |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 25 | querySerializer = new MetaQuerySerializer(); |
| 26 | collSerializer = new MetaCollectionSerializer(); |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | @Test |
| 30 | public void test() throws IOException { |
| 31 | Map<String, String> j = new HashMap(); |
| 32 | j.put("author", "Goethe"); |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 33 | j.put("pubPlace", "Erfurt"); |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 34 | j.put("textClass", "wissenschaft"); |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 35 | String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER); |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 36 | // 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 Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 43 | String s = querySerializer.stringify(j, MetaQuerySerializer.TYPE.FILTER); |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 44 | // System.out.println("value reference test single " + s); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void testResourceMeta() throws IOException { |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 49 | String s = collSerializer.serialize("25"); |
| 50 | // System.out.println(" --- RESULT JSON " + s); |
| 51 | } |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 52 | |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 53 | @Test |
| 54 | public void testDates() throws IOException { |
| 55 | Map<String, String> queries = new LinkedHashMap<>(); |
| 56 | queries.put("<pubDate", String.valueOf(new DateTime().getMillis())); |
Michael Hanl | 08b93ed | 2013-12-05 18:04:45 +0000 | [diff] [blame^] | 57 | queries.put(">pubDate", String.valueOf(new DateTime().getMillis() + 2)); |
Michael Hanl | 296a031 | 2013-12-05 17:27:51 +0000 | [diff] [blame] | 58 | queries.put("author", "Goethe"); |
| 59 | String f = querySerializer.stringify(queries, MetaQuerySerializer.TYPE.FILTER); |
Michael Hanl | 08b93ed | 2013-12-05 18:04:45 +0000 | [diff] [blame^] | 60 | // System.out.println("value : "+ f); |
Michael Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 61 | } |
Michael Hanl | 08b93ed | 2013-12-05 18:04:45 +0000 | [diff] [blame^] | 62 | |
| 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 Hanl | 55191d9 | 2013-12-05 11:53:10 +0000 | [diff] [blame] | 81 | } |