Skip to content

Commit

Permalink
HSEARCH-1656 Test annotation on implemented interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fax4ever committed Apr 11, 2019
1 parent 807f03d commit ea692b5
Showing 1 changed file with 94 additions and 0 deletions.
@@ -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;
}
}
}

0 comments on commit ea692b5

Please sign in to comment.