-
Notifications
You must be signed in to change notification settings - Fork 242
/
OutboxPollingAutomaticIndexingFilterIT.java
205 lines (169 loc) · 5.98 KB
/
OutboxPollingAutomaticIndexingFilterIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.integrationtest.mapper.orm.coordination.outboxpolling.automaticindexing;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import org.hibernate.search.mapper.orm.Search;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.util.common.SearchException;
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
import org.hibernate.search.util.impl.integrationtest.mapper.orm.ReusableOrmSetupHolder;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;
public class OutboxPollingAutomaticIndexingFilterIT {
@ClassRule
public static BackendMock backendMock = new BackendMock();
@ClassRule
public static ReusableOrmSetupHolder setupHolder = ReusableOrmSetupHolder.withBackendMock( backendMock );
@Rule
public MethodRule setupHolderMethodRule = setupHolder.methodRule();
@ReusableOrmSetupHolder.Setup
public void setup(OrmSetupHelper.SetupContext setupContext) {
backendMock
.expectSchema( EntityA.INDEX, b -> b.field( "indexedField", String.class ) )
.expectSchema( Entity1A.INDEX, b -> b.field( "indexedField", String.class ) )
.expectSchema( Entity2A.INDEX, b -> b.field( "indexedField", String.class ) )
.expectSchema( Entity1B.INDEX, b -> b.field( "indexedField", String.class ) );
setupContext.withAnnotatedTypes(
EntityA.class, Entity1A.class, Entity1B.class, Entity2A.class
);
}
@Before
public void clearFilter() throws Exception {
Search.automaticIndexingFilter(
setupHolder.entityManagerFactory(),
ctx -> { /*clear out any settings from tests*/ }
);
}
@Test
public void partialSessionFilterFails() {
setupHolder.runInTransaction( session -> {
assertThatThrownBy( () ->
Search.session( session ).automaticIndexingFilter(
ctx -> ctx.exclude( Entity1A.class ) )
).isInstanceOf( SearchException.class )
.hasMessageContainingAll(
"Use a different coordination strategy or an application-level automatic indexing filter.",
"The outbox polling coordination strategy allows only disabling the indexing of all types at the session level.",
"Applying a session-level automatic indexing filter that does not disable all types is prohibited."
);
} );
}
@Test
public void allTypesMixSessionFilterFails() {
setupHolder.runInTransaction( session -> {
assertThatThrownBy( () ->
Search.session( session ).automaticIndexingFilter(
ctx -> ctx.exclude( EntityA.class )
.exclude( Entity1A.class )
.exclude( Entity1B.class )
.include( Entity2A.class ) )
).isInstanceOf( SearchException.class )
.hasMessageContainingAll(
"Use a different coordination strategy or an application-level automatic indexing filter.",
"The outbox polling coordination strategy allows only disabling the indexing of all types at the session level.",
"Applying a session-level automatic indexing filter that does not disable all types is prohibited."
);
} );
}
@Test
public void allTypesExcludeExplicitlySessionFilter() {
setupHolder.runInTransaction( session -> {
Search.session( session ).automaticIndexingFilter(
ctx -> ctx.exclude( EntityA.class )
.exclude( Entity1A.class )
.exclude( Entity1B.class )
.exclude( Entity2A.class ) );
session.persist( new EntityA( 1, "test" ) );
session.persist( new Entity1A( 2, "test" ) );
session.persist( new Entity1B( 3, "test" ) );
session.persist( new Entity2A( 4, "test" ) );
} );
backendMock.verifyExpectationsMet();
}
@Test
public void allTypesExcludeInheritanceSessionFilter() {
setupHolder.runInTransaction( session -> {
Search.session( session ).automaticIndexingFilter(
ctx -> ctx.exclude( EntityA.class )
);
session.persist( new EntityA( 1, "test" ) );
session.persist( new Entity1A( 2, "test" ) );
session.persist( new Entity1B( 3, "test" ) );
session.persist( new Entity2A( 4, "test" ) );
} );
backendMock.verifyExpectationsMet();
}
@Entity
@Indexed(index = EntityA.INDEX)
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public static class EntityA {
static final String INDEX = "A";
@Id
private Integer id;
@Basic
@GenericField
private String indexedField;
public EntityA() {
}
public EntityA(Integer id, String indexedField) {
this.id = id;
this.indexedField = indexedField;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getIndexedField() {
return indexedField;
}
public void setIndexedField(String indexedField) {
this.indexedField = indexedField;
}
}
@Entity
@Indexed(index = Entity1A.INDEX)
public static class Entity1A extends EntityA {
static final String INDEX = "1A";
public Entity1A() {
}
public Entity1A(Integer id, String indexedField) {
super( id, indexedField );
}
}
@Entity
@Indexed(index = Entity1B.INDEX)
public static class Entity1B extends EntityA {
static final String INDEX = "1B";
public Entity1B() {
}
public Entity1B(Integer id, String indexedField) {
super( id, indexedField );
}
}
@Entity
@Indexed(index = Entity2A.INDEX)
public static class Entity2A extends Entity1A {
static final String INDEX = "2A";
public Entity2A() {
}
public Entity2A(Integer id, String indexedField) {
super( id, indexedField );
}
}
}