Michael Hanl | 505f48c | 2015-06-26 19:04:27 +0200 | [diff] [blame] | 1 | import com.fasterxml.jackson.databind.JsonNode; |
| 2 | import de.ids_mannheim.korap.query.serialize.MetaQueryBuilder; |
| 3 | import de.ids_mannheim.korap.utils.JsonUtils; |
| 4 | import org.junit.Assert; |
| 5 | import org.junit.Test; |
| 6 | |
| 7 | import java.util.HashSet; |
| 8 | import java.util.Set; |
| 9 | import java.util.regex.Matcher; |
| 10 | import java.util.regex.Pattern; |
| 11 | |
| 12 | /** |
| 13 | * @author hanl |
| 14 | * @date 26/06/2015 |
| 15 | */ |
| 16 | public class MetaQueryBuilderTest { |
| 17 | |
| 18 | private static Pattern p = Pattern |
| 19 | .compile("^/\\s*\\d+-(?:c(?:hars?)?|t(?:okens)?)$/"); |
| 20 | |
| 21 | private static Pattern p3 = Pattern |
| 22 | .compile("\\d+-(c(?:hars?)?|t(?:okens)?)?"); |
| 23 | |
| 24 | @Test |
| 25 | public void testRegex() { |
| 26 | Matcher m = p.matcher("1-tokens,2-chars"); |
| 27 | while (m.find()) { |
| 28 | int size = m.groupCount(); |
| 29 | System.out.println("FOUND "); |
| 30 | for (int i = 0; i < size; i++) |
| 31 | System.out.println("GROUP " + m.group(i)); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | @Test |
| 36 | public void testMetaBuilder() { |
| 37 | Set<String> f = new HashSet<>(); |
| 38 | f.add("docID"); |
| 39 | f.add("corpusID"); |
| 40 | MetaQueryBuilder m = new MetaQueryBuilder(); |
| 41 | m.addEntry("fields", f); |
| 42 | JsonNode n = JsonUtils.readTree(JsonUtils.toJSON(m.raw())); |
| 43 | Assert.assertEquals("[\"docID\",\"corpusID\"]", n.at("/fields").toString()); |
| 44 | } |
| 45 | } |