Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-1656 Test annotation on implemented interface
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...t/java/org/hibernate/search/integrationtest/mapper/pojo/model/ImplementedInterfaceIT.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,94 @@ | ||
/* | ||
* 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.model; | ||
|
||
import org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper; | ||
import org.hibernate.search.mapper.javabean.JavaBeanMapping; | ||
import org.hibernate.search.mapper.javabean.session.SearchSession; | ||
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId; | ||
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.impl.integrationtest.common.rule.BackendMock; | ||
import org.hibernate.search.util.impl.test.rule.StaticCounters; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class ImplementedInterfaceIT { | ||
|
||
@Rule | ||
public BackendMock backendMock = new BackendMock( "stubBackend" ); | ||
|
||
@Rule | ||
public JavaBeanMappingSetupHelper setupHelper = new JavaBeanMappingSetupHelper(); | ||
|
||
@Rule | ||
public StaticCounters counters = new StaticCounters(); | ||
|
||
private JavaBeanMapping mapping; | ||
|
||
@Before | ||
public void setup() { | ||
backendMock.expectSchema( IndexedPojo.class.getName(), b -> b | ||
.field( "text", String.class ) | ||
); | ||
|
||
mapping = setupHelper.withBackendMock( backendMock ).setup( IndexedPojo.class ); | ||
backendMock.verifyExpectationsMet(); | ||
} | ||
|
||
@Test | ||
public void index() { | ||
try ( SearchSession session = mapping.createSession() ) { | ||
IndexedPojo indexedPojo = new IndexedPojo( 1, "Using some other text here" ); | ||
session.getMainWorkPlan().add( indexedPojo ); | ||
|
||
backendMock.expectWorks( IndexedPojo.class.getName() ).add( "1", b -> b | ||
.field( "text", "Using some other text here" ) | ||
).preparedThenExecuted(); | ||
} | ||
} | ||
|
||
public interface ImplementedInterface { | ||
|
||
@GenericField | ||
default String getText() { | ||
return "Index your POJOs with Hibernate Search 6"; | ||
} | ||
} | ||
|
||
@Indexed | ||
public static class IndexedPojo implements ImplementedInterface { | ||
|
||
private Integer id; | ||
private String text; | ||
|
||
public IndexedPojo(Integer id, String text) { | ||
this.id = id; | ||
this.text = text; | ||
} | ||
|
||
@DocumentId | ||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
} | ||
} |