Skip to content

Commit ed423f1

Browse files
committed
HSEARCH-5300 Add integration tests modules for the metamodel processor
1 parent ce65e6a commit ed423f1

File tree

15 files changed

+800
-22
lines changed

15 files changed

+800
-22
lines changed

build/parents/build/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,11 @@
717717
<artifactId>hibernate-search-integrationtest-java-modules-pojo-standalone-lucene</artifactId>
718718
<version>${project.version}</version>
719719
</dependency>
720+
<dependency>
721+
<groupId>org.hibernate.search</groupId>
722+
<artifactId>hibernate-search-integrationtest-metamodel-standalone-lucene</artifactId>
723+
<version>${project.version}</version>
724+
</dependency>
720725
<dependency>
721726
<groupId>org.hibernate.search</groupId>
722727
<artifactId>hibernate-search-integrationtest-backend-lucene-next</artifactId>

build/reports/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
<artifactId>hibernate-search-integrationtest-mapper-orm-jakarta-batch</artifactId>
149149
<scope>test</scope>
150150
</dependency>
151+
<dependency>
152+
<groupId>org.hibernate.search</groupId>
153+
<artifactId>hibernate-search-integrationtest-metamodel-standalone-lucene</artifactId>
154+
</dependency>
151155
<dependency>
152156
<groupId>org.hibernate.search</groupId>
153157
<artifactId>hibernate-search-documentation</artifactId>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.hibernate.search</groupId>
6+
<artifactId>hibernate-search-integrationtest</artifactId>
7+
<version>8.0.0-SNAPSHOT</version>
8+
<relativePath>../..</relativePath>
9+
</parent>
10+
<artifactId>hibernate-search-integrationtest-metamodel-orm-lucene</artifactId>
11+
12+
<name>Hibernate Search ITs - Metamodel - ORM mapper with the Lucene backend</name>
13+
<description>Hibernate Search integration tests for metamodel generation with ORM mapper and the Lucene backend</description>
14+
15+
<properties>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.hibernate.search</groupId>
21+
<artifactId>hibernate-search-mapper-orm</artifactId>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.hibernate.search</groupId>
26+
<artifactId>hibernate-search-backend-lucene</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.hibernate.search</groupId>
31+
<artifactId>hibernate-search-util-internal-integrationtest-mapper-orm</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.hibernate.search</groupId>
36+
<artifactId>hibernate-search-util-internal-integrationtest-backend-lucene</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
<!--
40+
Leave this dependency here, not in a utils module, so that we don't need to recompile
41+
the utils to re-run the tests with a different database.
42+
-->
43+
<dependency>
44+
<groupId>${jdbc.driver.groupId}</groupId>
45+
<artifactId>${jdbc.driver.artifactId}</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.hibernate.search</groupId>
50+
<artifactId>hibernate-search-metamodel-processor</artifactId>
51+
<scope>provided</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>${version.compiler.plugin}</version>
60+
<executions>
61+
<execution>
62+
<id>default-testCompile</id>
63+
<configuration>
64+
<fork>false</fork>
65+
<proc>full</proc>
66+
<annotationProcessors>
67+
<annotationProcessor>org.hibernate.search.metamodel.processor.HibernateSearchMetamodelProcessor</annotationProcessor>
68+
</annotationProcessors>
69+
<annotationProcessorPaths>
70+
<path>
71+
<groupId>org.hibernate.search</groupId>
72+
<artifactId>hibernate-search-metamodel-processor</artifactId>
73+
<version>${project.version}</version>
74+
</path>
75+
<path>
76+
<groupId>org.hibernate.search</groupId>
77+
<artifactId>hibernate-search-backend-lucene</artifactId>
78+
<version>${project.version}</version>
79+
</path>
80+
</annotationProcessorPaths>
81+
</configuration>
82+
</execution>
83+
</executions>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-failsafe-plugin</artifactId>
88+
<executions>
89+
<execution>
90+
<id>it</id>
91+
<goals>
92+
<goal>integration-test</goal>
93+
<goal>verify</goal>
94+
</goals>
95+
<configuration>
96+
<skip>${test.lucene.skip}</skip>
97+
<systemPropertyVariables>
98+
<org.hibernate.search.integrationtest.backend.type>lucene</org.hibernate.search.integrationtest.backend.type>
99+
</systemPropertyVariables>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
</project>
107+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.integrationtest.metamodel.standalone.lucene;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
import jakarta.persistence.ElementCollection;
14+
import jakarta.persistence.Embeddable;
15+
import jakarta.persistence.Entity;
16+
import jakarta.persistence.Id;
17+
import jakarta.persistence.ManyToOne;
18+
import jakarta.persistence.OneToMany;
19+
20+
import org.hibernate.SessionFactory;
21+
import org.hibernate.search.engine.backend.types.Projectable;
22+
import org.hibernate.search.mapper.orm.Search;
23+
import org.hibernate.search.mapper.orm.scope.SearchScope;
24+
import org.hibernate.search.mapper.orm.session.SearchSession;
25+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
26+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
27+
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
28+
import org.hibernate.search.util.impl.integrationtest.backend.lucene.LuceneBackendConfiguration;
29+
import org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper;
30+
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.extension.RegisterExtension;
34+
35+
class EntityAsTreeSmokeIT {
36+
37+
@RegisterExtension
38+
public OrmSetupHelper setupHelper = OrmSetupHelper.withSingleBackend( new LuceneBackendConfiguration() );
39+
40+
private SessionFactory sessionFactory;
41+
42+
@BeforeEach
43+
void setup() {
44+
sessionFactory = setupHelper.start()
45+
.withAnnotatedTypes( ContainedNonEntity.class, IndexedEntity.class, ContainedEntity.class )
46+
.setup();
47+
}
48+
49+
@Test
50+
void indexAndSearch() {
51+
IndexedEntity indexed1 = new IndexedEntity( "1", "some interesting text" );
52+
ContainedEntity containedEntity1_1 = new ContainedEntity( "1_1", "some contained entity text" );
53+
containedEntity1_1.containing = indexed1;
54+
indexed1.containedEntities.add( containedEntity1_1 );
55+
ContainedNonEntity containedNonEntity1_1 = new ContainedNonEntity( "some contained nonentity text" );
56+
indexed1.containedNonEntities.add( containedNonEntity1_1 );
57+
58+
IndexedEntity indexed2 = new IndexedEntity( "2", "some other text" );
59+
ContainedEntity containedEntity2_1 = new ContainedEntity( "2_1", "some other text" );
60+
containedEntity2_1.containing = indexed2;
61+
indexed2.containedEntities.add( containedEntity2_1 );
62+
ContainedNonEntity containedNonEntity2_1 = new ContainedNonEntity( "some other text" );
63+
indexed2.containedNonEntities.add( containedNonEntity2_1 );
64+
65+
try ( var s = sessionFactory.openSession() ) {
66+
SearchSession session = Search.session( s );
67+
SearchScope<EntityAsTreeSmokeIT_IndexedEntity__, IndexedEntity> scope = EntityAsTreeSmokeIT_IndexedEntity__.INDEX.scope( session );
68+
assertThat( session.search( scope )
69+
.where( f -> f.match().field( EntityAsTreeSmokeIT_IndexedEntity__.INDEX.containedEntities.text )
70+
.matching( "entity text" ) )
71+
.fetchHits( 20 ) )
72+
.isEmpty();
73+
}
74+
75+
with( sessionFactory ).runInTransaction( session -> {
76+
session.persist( indexed1 );
77+
session.persist( containedEntity1_1 );
78+
session.persist( indexed2 );
79+
} );
80+
81+
try ( var s = sessionFactory.openSession() ) {
82+
SearchSession session = Search.session( s );
83+
SearchScope<EntityAsTreeSmokeIT_IndexedEntity__, IndexedEntity> scope = EntityAsTreeSmokeIT_IndexedEntity__.INDEX.scope( session );
84+
assertThat( session.search( scope )
85+
.select( f -> f.id() )
86+
.where( f -> f.match().field( EntityAsTreeSmokeIT_IndexedEntity__.INDEX.containedEntities.text )
87+
.matching( "entity" ) )
88+
.fetchHits( 20 ) )
89+
.containsExactlyInAnyOrder( indexed1.id );
90+
}
91+
}
92+
93+
@Entity
94+
@Indexed
95+
public static class IndexedEntity {
96+
@Id
97+
public String id;
98+
@FullTextField(projectable = Projectable.YES)
99+
public String text;
100+
@OneToMany(mappedBy = "containing")
101+
@IndexedEmbedded
102+
public List<ContainedEntity> containedEntities = new ArrayList<>();
103+
@ElementCollection
104+
@IndexedEmbedded
105+
public List<ContainedNonEntity> containedNonEntities = new ArrayList<>();
106+
107+
public IndexedEntity() {
108+
}
109+
110+
public IndexedEntity(String id, String text) {
111+
this.id = id;
112+
this.text = text;
113+
}
114+
}
115+
116+
@Entity
117+
public static class ContainedEntity {
118+
// Not setting @DocumentId here because it shouldn't be necessary
119+
@Id
120+
public String id;
121+
@FullTextField
122+
public String text;
123+
@ManyToOne
124+
public IndexedEntity containing;
125+
126+
public ContainedEntity() {
127+
}
128+
129+
public ContainedEntity(String id, String text) {
130+
this.id = id;
131+
this.text = text;
132+
}
133+
}
134+
135+
@Embeddable
136+
public static class ContainedNonEntity {
137+
@FullTextField(projectable = Projectable.YES)
138+
public String text;
139+
140+
public ContainedNonEntity() {
141+
}
142+
143+
public ContainedNonEntity(String text) {
144+
this.text = text;
145+
}
146+
}
147+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.hibernate.search</groupId>
6+
<artifactId>hibernate-search-integrationtest</artifactId>
7+
<version>8.0.0-SNAPSHOT</version>
8+
<relativePath>../..</relativePath>
9+
</parent>
10+
<artifactId>hibernate-search-integrationtest-metamodel-standalone-elasticsearch</artifactId>
11+
12+
<name>Hibernate Search ITs - Metamodel - Standalone with the Elasticsearch backend</name>
13+
<description>Hibernate Search integration tests for metamodel generation with standalone mapper and the Elasticsearch backend</description>
14+
15+
<properties>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.hibernate.search</groupId>
21+
<artifactId>hibernate-search-mapper-pojo-standalone</artifactId>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.hibernate.search</groupId>
26+
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
27+
<scope>test</scope>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.hibernate.search</groupId>
31+
<artifactId>hibernate-search-util-internal-integrationtest-mapper-pojo-standalone</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.hibernate.search</groupId>
36+
<artifactId>hibernate-search-util-internal-integrationtest-backend-elasticsearch</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.hibernate.search</groupId>
41+
<artifactId>hibernate-search-metamodel-processor</artifactId>
42+
<scope>provided</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<build>
47+
<plugins>
48+
<plugin>
49+
<artifactId>maven-compiler-plugin</artifactId>
50+
<version>${version.compiler.plugin}</version>
51+
<executions>
52+
<execution>
53+
<id>default-testCompile</id>
54+
<configuration>
55+
<fork>false</fork>
56+
<proc>full</proc>
57+
<annotationProcessors>
58+
<annotationProcessor>org.hibernate.search.metamodel.processor.HibernateSearchMetamodelProcessor</annotationProcessor>
59+
</annotationProcessors>
60+
<annotationProcessorPaths>
61+
<path>
62+
<groupId>org.hibernate.search</groupId>
63+
<artifactId>hibernate-search-metamodel-processor</artifactId>
64+
<version>${project.version}</version>
65+
</path>
66+
<path>
67+
<groupId>org.hibernate.search</groupId>
68+
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
69+
<version>${project.version}</version>
70+
</path>
71+
</annotationProcessorPaths>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-failsafe-plugin</artifactId>
79+
<executions>
80+
<execution>
81+
<id>it</id>
82+
<goals>
83+
<goal>integration-test</goal>
84+
<goal>verify</goal>
85+
</goals>
86+
<configuration>
87+
<skip>${test.elasticsearch.skip}</skip>
88+
<systemPropertyVariables>
89+
<org.hibernate.search.integrationtest.backend.type>elasticsearch</org.hibernate.search.integrationtest.backend.type>
90+
</systemPropertyVariables>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>
98+

0 commit comments

Comments
 (0)