| margaretha | 398f472 | 2019-01-09 19:07:20 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.rewrite; |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 2 | |
| margaretha | f68daa6 | 2017-09-21 02:11:24 +0200 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotNull; |
| 5 | |
| margaretha | f68daa6 | 2017-09-21 02:11:24 +0200 | [diff] [blame] | 6 | import org.junit.Test; |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| margaretha | f68daa6 | 2017-09-21 02:11:24 +0200 | [diff] [blame] | 8 | |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 9 | import com.fasterxml.jackson.databind.JsonNode; |
| margaretha | f68daa6 | 2017-09-21 02:11:24 +0200 | [diff] [blame] | 10 | |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 11 | import de.ids_mannheim.korap.config.KustvaktConfiguration; |
| 12 | import de.ids_mannheim.korap.config.SpringJerseyTest; |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 13 | import de.ids_mannheim.korap.config.TestVariables; |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 14 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 15 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 16 | import de.ids_mannheim.korap.user.User; |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 17 | import de.ids_mannheim.korap.utils.JsonUtils; |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 18 | |
| Michael Hanl | fbd6fbb | 2015-09-14 16:10:12 +0200 | [diff] [blame] | 19 | /** |
| 20 | * @author hanl |
| 21 | * @date 03/09/2015 |
| 22 | */ |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 23 | public class CollectionRewriteTest extends SpringJerseyTest { |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 24 | |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 25 | @Autowired |
| 26 | public KustvaktConfiguration config; |
| 27 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 28 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 29 | public void testCollectionNodeRemoveCorpusIdNoErrors () |
| 30 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 31 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 32 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 33 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 34 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 35 | s.setCollection("textClass=politik & corpusSigle=WPD"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 36 | String result = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 37 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 38 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 39 | assertNotNull(node); |
| 40 | assertEquals(1, node.at("/collection/operands").size()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 43 | |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 44 | @Test |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 45 | public void testCollectionNodeDeletionNotification () { |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 46 | |
| 47 | } |
| 48 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 49 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 50 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 51 | public void testCollectionNodeRemoveAllCorpusIdNoErrors () |
| 52 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 53 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 54 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 55 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 56 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 57 | s.setCollection("corpusSigle=BRZ13 & corpusSigle=WPD"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 58 | String result = s.toJSON(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 59 | |
| 60 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| 61 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | 4563692 | 2016-06-03 14:00:56 +0200 | [diff] [blame] | 62 | |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 63 | assertNotNull(node); |
| 64 | assertEquals(0, node.at("/collection/operands").size()); |
| 65 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 66 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 69 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 70 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 71 | public void testCollectionNodeRemoveGroupedCorpusIdNoErrors () |
| 72 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 73 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 74 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 75 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 76 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 77 | s.setCollection("(corpusSigle=BRZ13 & textClass=Wissenschaft) & corpusSigle=WPD"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 78 | String result = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 79 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 80 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 81 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 82 | assertNotNull(node); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 83 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 84 | .asText()); |
| 85 | assertEquals("textClass", |
| 86 | node.at("/collection/operands/0/operands/0/key").asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 87 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 88 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 91 | |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 92 | //fixme: will probably fail when one doc groups are being refactored |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 93 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 94 | public void testCollectionCleanEmptyDocGroupNoErrors () |
| 95 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 96 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 97 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 98 | handler.add(CollectionCleanRewrite.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 99 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 100 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 101 | s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft & textClass=Sport"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 102 | String result = s.toJSON(); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 103 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 104 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 105 | User.UserFactory.getUser("test_user"))); |
| 106 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 107 | assertNotNull(node); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 108 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 109 | assertEquals(2, node.at("/collection/operands").size()); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 110 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 111 | assertEquals("textClass", node.at("/collection/operands/0/key") |
| 112 | .asText()); |
| 113 | assertEquals("textClass", node.at("/collection/operands/1/key") |
| 114 | .asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 115 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 116 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 119 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 120 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 121 | public void testCollectionCleanMoveOneDocFromGroupUpNoErrors () |
| 122 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 123 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 124 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 125 | handler.add(CollectionCleanRewrite.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 126 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 127 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 128 | s.setCollection("(corpusSigle=BRZ13 & textClass=wissenschaft)"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 129 | String result = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 130 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 131 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 132 | assertNotNull(node); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 133 | assertEquals("koral:doc", node.at("/collection/@type").asText()); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 134 | assertEquals("textClass", node.at("/collection/key").asText()); |
| 135 | assertEquals("wissenschaft", node.at("/collection/value").asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 136 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 137 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 140 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 141 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 142 | public void testCollectionCleanEmptyGroupAndMoveOneFromGroupUpNoErrors () |
| 143 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 144 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 145 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 146 | handler.add(CollectionCleanRewrite.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 147 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 148 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 149 | s.setCollection("(corpusSigle=BRZ13 & corpusSigle=WPD) & textClass=Wissenschaft"); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 150 | String result = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 151 | JsonNode node = JsonUtils.readTree(handler.processQuery(result, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 152 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 153 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 154 | assertNotNull(node); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 155 | assertEquals("koral:doc", node.at("/collection/@type").asText()); |
| 156 | assertEquals("textClass", node.at("/collection/key").asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 157 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 158 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 161 | |
| Michael Hanl | f078532 | 2015-11-13 16:14:45 +0100 | [diff] [blame] | 162 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 163 | public void testCollectionRemoveAndMoveOneFromGroupUpNoErrors () |
| 164 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 165 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 59bff81 | 2015-10-27 23:10:32 +0100 | [diff] [blame] | 166 | handler.add(CollectionConstraint.class); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 167 | handler.add(CollectionCleanRewrite.class); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 168 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 169 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 170 | s.setCollection("(docID=random & textClass=Wissenschaft) & corpusSigle=WPD"); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 171 | String org = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 172 | JsonNode node = JsonUtils.readTree(handler.processQuery(org, |
| Michael Hanl | 022543e | 2015-11-17 21:25:25 +0100 | [diff] [blame] | 173 | User.UserFactory.getUser("test_user"))); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 174 | assertNotNull(node); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 175 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 176 | assertEquals(2, node.at("/collection/operands").size()); |
| Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 177 | assertEquals("koral:doc", node.at("/collection/operands/0/@type") |
| 178 | .asText()); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 179 | assertEquals("koral:doc", node.at("/collection/operands/1/@type") |
| 180 | .asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 181 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 182 | .asText()); |
| Michael Hanl | 66ca71c | 2015-09-14 23:11:30 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 185 | |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 186 | @Test |
| 187 | public void testPublicCollectionRewriteEmptyAdd () throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 188 | RewriteHandler handler = new RewriteHandler(config); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 189 | handler.add(CollectionRewrite.class); |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 190 | |
| 191 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 192 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 193 | String org = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 194 | JsonNode node = JsonUtils.readTree(handler.processQuery(org, |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 195 | User.UserFactory.getUser("test_user"))); |
| 196 | assertNotNull(node); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 197 | assertEquals("availability", node.at("/collection/key") |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 198 | .asText()); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 199 | assertEquals("CC-BY.*", node.at("/collection/value") |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 200 | .asText()); |
| 201 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 202 | .asText()); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 203 | assertEquals("availability(FREE)", node.at("/collection/rewrites/0/scope") |
| 204 | .asText()); |
| Michael Hanl | d8aa621 | 2016-06-03 12:48:43 +0200 | [diff] [blame] | 205 | //todo: |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | |
| 209 | @Test |
| 210 | public void testPublicCollectionRewriteNonEmptyAdd () |
| 211 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 212 | RewriteHandler handler = new RewriteHandler(config); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 213 | handler.add(CollectionRewrite.class); |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 214 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 215 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 216 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 217 | s.setCollection("(docSigle=WPD_AAA & textClass=wissenschaft)"); |
| 218 | String org = s.toJSON(); |
| 219 | JsonNode node = JsonUtils.readTree(handler.processQuery(org, |
| 220 | User.UserFactory.getUser("test_user"))); |
| 221 | assertNotNull(node); |
| 222 | assertEquals(2, node.at("/collection/operands").size()); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 223 | assertEquals("availability", |
| 224 | node.at("/collection/operands/0/key").asText()); |
| 225 | assertEquals("CC-BY.*", |
| 226 | node.at("/collection/operands/0/value").asText()); |
| 227 | assertEquals("docSigle", |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 228 | node.at("/collection/operands/1/operands/0/key").asText()); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 229 | assertEquals("textClass", |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 230 | node.at("/collection/operands/1/operands/1/key").asText()); |
| 231 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 232 | .asText()); |
| margaretha | e7badb3 | 2017-06-22 15:16:00 +0200 | [diff] [blame] | 233 | assertEquals("availability(FREE)", node.at("/collection/rewrites/0/scope") |
| 234 | .asText()); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 235 | } |
| Michael Hanl | e56bb89 | 2016-05-25 17:34:41 +0200 | [diff] [blame] | 236 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 237 | |
| 238 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 239 | public void testRemoveCorpusFromDifferentGroups () throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 240 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 241 | handler.add(CollectionConstraint.class); |
| 242 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 243 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 244 | s.setCollection("(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)"); |
| 245 | String org = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 246 | JsonNode node = JsonUtils.readTree(handler.processQuery(org, |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 247 | User.UserFactory.getUser("test_user"))); |
| 248 | assertNotNull(node); |
| 249 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 250 | assertEquals(2, node.at("/collection/operands").size()); |
| 251 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 252 | .asText()); |
| 253 | assertEquals("koral:docGroup", node.at("/collection/operands/1/@type") |
| 254 | .asText()); |
| 255 | assertEquals(1, node.at("/collection/operands/0/operands").size()); |
| 256 | assertEquals(1, node.at("/collection/operands/1/operands").size()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 257 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 258 | .asText()); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 261 | |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 262 | @Test |
| Michael Hanl | f8fcc7a | 2016-06-03 17:41:07 +0200 | [diff] [blame] | 263 | public void testRemoveOneCorpusAndMoveDocFromTwoGroups () |
| 264 | throws KustvaktException { |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 265 | RewriteHandler handler = new RewriteHandler(config); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 266 | handler.add(CollectionConstraint.class); |
| 267 | // todo: use this collection query also to test clean up filter! after reduction of corpusSigle (wiss | freizeit)! |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 268 | handler.add(CollectionCleanRewrite.class); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 269 | QuerySerializer s = new QuerySerializer(); |
| Michael Hanl | cb2d3f9 | 2016-06-02 17:34:06 +0200 | [diff] [blame] | 270 | s.setQuery(TestVariables.SIMPLE_ADD_QUERY, "poliqarp"); |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 271 | s.setCollection("(corpusSigle=BRZ14 & textClass=wissenschaft) | (corpusSigle=AZPR | textClass=freizeit)"); |
| 272 | String org = s.toJSON(); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 273 | JsonNode node = JsonUtils.readTree(handler.processQuery(org, |
| Michael Hanl | 86d598e | 2016-05-26 15:13:00 +0200 | [diff] [blame] | 274 | User.UserFactory.getUser("test_user"))); |
| 275 | assertNotNull(node); |
| 276 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 277 | assertEquals(2, node.at("/collection/operands").size()); |
| 278 | assertEquals("koral:doc", node.at("/collection/operands/0/@type") |
| 279 | .asText()); |
| Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 280 | assertEquals("koral:doc", node.at("/collection/operands/0/@type") |
| 281 | .asText()); |
| 282 | assertEquals("textClass", node.at("/collection/operands/0/key") |
| 283 | .asText()); |
| 284 | assertEquals("wissenschaft", node.at("/collection/operands/0/value") |
| 285 | .asText()); |
| 286 | assertEquals("koral:doc", node.at("/collection/operands/1/@type") |
| 287 | .asText()); |
| 288 | assertEquals("textClass", node.at("/collection/operands/1/key") |
| 289 | .asText()); |
| 290 | assertEquals("freizeit", node.at("/collection/operands/1/value") |
| 291 | .asText()); |
| 292 | assertEquals("koral:rewrite", node.at("/collection/rewrites/0/@type") |
| 293 | .asText()); |
| Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
| Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 297 | |
| Michael Hanl | fbd6fbb | 2015-09-14 16:10:12 +0200 | [diff] [blame] | 298 | } |