Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-4673 Add test for projection records without -parameters comp…
…iler flag
- Loading branch information
1 parent
e7384ca
commit 0f1c7d8
Showing
4 changed files
with
203 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
...mapper/pojo/mapping/definition/ProjectionConstructorRecordNoParametersCompilerFlagIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* 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.pojo.mapping.definition; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.Parameter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor; | ||
import org.hibernate.search.mapper.pojo.standalone.mapping.SearchMapping; | ||
import org.hibernate.search.mapper.pojo.standalone.session.SearchSession; | ||
import org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock; | ||
import org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior; | ||
import org.hibernate.search.util.impl.integrationtest.mapper.pojo.standalone.StandalonePojoMappingSetupHelper; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ProjectionConstructorRecordNoParametersCompilerFlagIT { | ||
|
||
private static final String INDEX_NAME = "index_name"; | ||
|
||
@Rule | ||
public BackendMock backendMock = new BackendMock(); | ||
|
||
@Rule | ||
public StandalonePojoMappingSetupHelper setupHelper = StandalonePojoMappingSetupHelper.withBackendMock( MethodHandles.lookup(), backendMock ); | ||
|
||
@Test | ||
public void sourcesCompiledWithoutParametersFlag() { | ||
assertThat( ConstructorWithParameters.class.getDeclaredConstructors()[0].getParameters() ) | ||
.extracting( Parameter::isNamePresent ) | ||
.containsOnly( Boolean.FALSE, Boolean.FALSE ); | ||
} | ||
|
||
@Test | ||
public void typeLevelAnnotation() { | ||
@Indexed(index = INDEX_NAME) | ||
class IndexedEntity { | ||
@DocumentId | ||
public Integer id; | ||
@FullTextField | ||
public String text; | ||
@GenericField | ||
public Integer integer; | ||
} | ||
@ProjectionConstructor | ||
record MyProjection(String text, Integer integer) { } | ||
|
||
backendMock.expectAnySchema( INDEX_NAME ); | ||
SearchMapping mapping = setupHelper.start() | ||
.withAnnotatedTypes( MyProjection.class ) | ||
.setup( IndexedEntity.class ); | ||
testSuccessfulRootProjection( | ||
mapping, IndexedEntity.class, MyProjection.class, | ||
Arrays.asList( | ||
Arrays.asList( "result1", 1 ), | ||
Arrays.asList( "result2", 2 ), | ||
Arrays.asList( "result3", 3 ) | ||
), | ||
Arrays.asList( | ||
new MyProjection( "result1", 1 ), | ||
new MyProjection( "result2", 2 ), | ||
new MyProjection( "result3", 3 ) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
public void constructorLevelAnnotation_canonical() { | ||
@Indexed(index = INDEX_NAME) | ||
class IndexedEntity { | ||
@DocumentId | ||
public Integer id; | ||
@FullTextField | ||
public String text; | ||
@GenericField | ||
public Integer integer; | ||
} | ||
record MyProjection(String text, Integer integer) { | ||
@ProjectionConstructor | ||
public MyProjection { | ||
} | ||
|
||
public MyProjection(String text, Integer integer, String somethingElse) { | ||
this( text, integer ); | ||
} | ||
} | ||
|
||
backendMock.expectAnySchema( INDEX_NAME ); | ||
SearchMapping mapping = setupHelper.start() | ||
.withAnnotatedTypes( MyProjection.class ) | ||
.setup( IndexedEntity.class ); | ||
testSuccessfulRootProjection( | ||
mapping, IndexedEntity.class, MyProjection.class, | ||
Arrays.asList( | ||
Arrays.asList( "result1", 1 ), | ||
Arrays.asList( "result2", 2 ), | ||
Arrays.asList( "result3", 3 ) | ||
), | ||
Arrays.asList( | ||
new MyProjection( "result1", 1 ), | ||
new MyProjection( "result2", 2 ), | ||
new MyProjection( "result3", 3 ) | ||
) | ||
); | ||
} | ||
|
||
private <P> void testSuccessfulRootProjection(SearchMapping mapping, Class<?> indexedType, Class<P> projectionType, | ||
List<?> rawProjectionResults, List<P> expectedProjectionResults) { | ||
try ( SearchSession session = mapping.createSession() ) { | ||
backendMock.expectSearchProjection( | ||
INDEX_NAME, | ||
StubSearchWorkBehavior.of( | ||
rawProjectionResults.size(), | ||
rawProjectionResults | ||
) | ||
); | ||
|
||
assertThat( session.search( indexedType ) | ||
.select( projectionType ) | ||
.where( f -> f.matchAll() ) | ||
.fetchAllHits() ) | ||
.usingRecursiveFieldByFieldElementComparator() | ||
.containsExactlyElementsOf( expectedProjectionResults ); | ||
} | ||
backendMock.verifyExpectationsMet(); | ||
} | ||
|
||
static class ConstructorWithParameters { | ||
ConstructorWithParameters(int paramInt, String paramString) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters