Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 1 | import com.fasterxml.jackson.databind.JsonNode; |
Michael Hanl | a36fc33 | 2015-10-27 23:11:42 +0100 | [diff] [blame] | 2 | import de.ids_mannheim.korap.config.BeanConfiguration; |
Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 3 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
Michael Hanl | a36fc33 | 2015-10-27 23:11:42 +0100 | [diff] [blame] | 4 | import de.ids_mannheim.korap.resource.rewrite.IdWriter; |
| 5 | import de.ids_mannheim.korap.resource.rewrite.RewriteHandler; |
Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 6 | import de.ids_mannheim.korap.utils.JsonUtils; |
Michael Hanl | a36fc33 | 2015-10-27 23:11:42 +0100 | [diff] [blame] | 7 | import org.junit.AfterClass; |
| 8 | import org.junit.BeforeClass; |
| 9 | import org.junit.Test; |
| 10 | |
| 11 | /** |
| 12 | * @author hanl |
| 13 | * @date 21/10/2015 |
| 14 | */ |
| 15 | public class IdRewriteTest { |
| 16 | |
| 17 | @BeforeClass |
| 18 | public static void setup() { |
| 19 | BeanConfiguration.loadClasspathContext(); |
| 20 | } |
| 21 | |
| 22 | @AfterClass |
| 23 | public static void drop() { |
| 24 | BeanConfiguration.closeApplication(); |
| 25 | } |
| 26 | |
| 27 | @Test |
| 28 | public void insertTokenId() { |
| 29 | RewriteHandler handler = new RewriteHandler( |
| 30 | BeanConfiguration.getBeans().getConfiguration()); |
| 31 | assert handler.add(IdWriter.class); |
| 32 | |
Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 33 | String query = "[surface=Wort]"; |
| 34 | QuerySerializer s = new QuerySerializer(); |
| 35 | s.setQuery(query, "poliqarp"); |
| 36 | |
| 37 | String value = handler.preProcess(s.toJSON(), null); |
| 38 | JsonNode result = JsonUtils.readTree(value); |
| 39 | |
| 40 | assert result != null; |
| 41 | assert result.path("query").has("idn"); |
Michael Hanl | a36fc33 | 2015-10-27 23:11:42 +0100 | [diff] [blame] | 42 | |
| 43 | } |
| 44 | |
| 45 | } |