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