blob: 7b4c3aaa21612c92eea2dbf6a37b2d4762f664d0 [file] [log] [blame]
Michael Hanl505f48c2015-06-26 19:04:27 +02001import com.fasterxml.jackson.databind.JsonNode;
2import de.ids_mannheim.korap.query.serialize.MetaQueryBuilder;
3import de.ids_mannheim.korap.utils.JsonUtils;
4import org.junit.Assert;
5import org.junit.Test;
6
7import java.util.HashSet;
8import java.util.Set;
9import java.util.regex.Matcher;
10import java.util.regex.Pattern;
11
12/**
13 * @author hanl
14 * @date 26/06/2015
15 */
16public 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}