Skip to content

Commit

Permalink
HSEARCH-2908 Rename Elasticsearch client Spy class
Browse files Browse the repository at this point in the history
Using the Mocking nomenclature it is more a spy than a mock, since it calls a real Elasticsearch server.
  • Loading branch information
fax4ever authored and yrodiere committed Feb 20, 2019
1 parent 635d0bb commit c16158c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Expand Up @@ -10,7 +10,7 @@
import org.hibernate.search.backend.elasticsearch.client.spi.ElasticsearchRequest;
import org.hibernate.search.backend.elasticsearch.util.spi.URLEncodedString;
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientMock;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientSpy;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchRequestAssertionMode;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;

Expand All @@ -32,22 +32,22 @@ public class ElasticsearchFieldTypesIT {
public SearchSetupHelper setupHelper = new SearchSetupHelper();

@Rule
public ElasticsearchClientMock clientMock = new ElasticsearchClientMock();
public ElasticsearchClientSpy clientSpy = new ElasticsearchClientSpy();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void addUpdateDelete_routing() {
clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.get().build(), ElasticsearchRequestAssertionMode.STRICT
);

clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.head().pathComponent( URLEncodedString.fromString( INDEX_NAME ) ).build(), ElasticsearchRequestAssertionMode.STRICT
);

clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.put()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.body( indexCreationPayload() )
Expand All @@ -57,7 +57,7 @@ public void addUpdateDelete_routing() {

setupHelper.withDefaultConfiguration( BACKEND_NAME )
.withBackendProperty(
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientMock.getFactory()
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientSpy.getFactory()
)
.withIndex(
"MappedType", INDEX_NAME,
Expand All @@ -67,7 +67,7 @@ public void addUpdateDelete_routing() {
)
.setup();

clientMock.verifyExpectationsMet();
clientSpy.verifyExpectationsMet();
}

private JsonObject indexCreationPayload() {
Expand Down
Expand Up @@ -14,7 +14,7 @@
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement;
import org.hibernate.search.engine.backend.types.Projectable;
import org.hibernate.search.engine.search.SearchQuery;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientMock;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientSpy;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchRequestAssertionMode;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;
import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingIndexManager;
Expand All @@ -40,7 +40,7 @@ public class ElasticsearchSearchQueryIT {
public SearchSetupHelper setupHelper = new SearchSetupHelper();

@Rule
public ElasticsearchClientMock clientMock = new ElasticsearchClientMock();
public ElasticsearchClientSpy clientSpy = new ElasticsearchClientSpy();

@Rule
public ExpectedException thrown = ExpectedException.none();
Expand All @@ -51,7 +51,7 @@ public class ElasticsearchSearchQueryIT {
public void setup() {
setupHelper.withDefaultConfiguration( BACKEND_NAME )
.withBackendProperty(
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientMock.getFactory()
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientSpy.getFactory()
)
.withIndex(
"MappedType", INDEX_NAME,
Expand All @@ -70,7 +70,7 @@ public void projection_sourceFiltering() {
.predicate( f -> f.matchAll() )
.build();

clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.post()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.pathComponent( Paths._SEARCH )
Expand All @@ -94,7 +94,7 @@ public void routing() {
.routing( routingKey )
.build();

clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.post()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.pathComponent( Paths._SEARCH )
Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

public class ElasticsearchClientMock implements TestRule {
public class ElasticsearchClientSpy implements TestRule {
private final CallQueue<ElasticsearchClientSubmitCall> expectations = new CallQueue<>();

@Override
Expand Down
Expand Up @@ -16,7 +16,7 @@
import org.hibernate.search.engine.backend.document.IndexFieldAccessor;
import org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement;
import org.hibernate.search.engine.backend.index.spi.IndexWorkPlan;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientMock;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchClientSpy;
import org.hibernate.search.integrationtest.backend.elasticsearch.testsupport.util.ElasticsearchRequestAssertionMode;
import org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper;
import org.hibernate.search.util.impl.integrationtest.common.stub.mapper.StubMappingIndexManager;
Expand All @@ -41,7 +41,7 @@ public class ElasticsearchIndexingIT {
public SearchSetupHelper setupHelper = new SearchSetupHelper();

@Rule
public ElasticsearchClientMock clientMock = new ElasticsearchClientMock();
public ElasticsearchClientSpy clientSpy = new ElasticsearchClientSpy();

@Rule
public ExpectedException thrown = ExpectedException.none();
Expand All @@ -53,7 +53,7 @@ public class ElasticsearchIndexingIT {
public void setup() {
setupHelper.withDefaultConfiguration( BACKEND_NAME )
.withBackendProperty(
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientMock.getFactory()
BACKEND_NAME, ElasticsearchBackendSpiSettings.CLIENT_FACTORY, clientSpy.getFactory()
)
.withIndex(
"MappedType", INDEX_NAME,
Expand All @@ -71,7 +71,7 @@ public void addUpdateDelete_routing() {
workPlan.add( referenceProvider( "1", routingKey ), document -> {
indexAccessors.string.write( document, "text1" );
} );
clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.put()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.pathComponent( TYPE_NAME )
Expand All @@ -82,12 +82,12 @@ public void addUpdateDelete_routing() {
ElasticsearchRequestAssertionMode.EXTENSIBLE
);
workPlan.execute().join();
clientMock.verifyExpectationsMet();
clientSpy.verifyExpectationsMet();

workPlan.update( referenceProvider( "1", routingKey ), document -> {
indexAccessors.string.write( document, "text2" );
} );
clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.put()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.pathComponent( TYPE_NAME )
Expand All @@ -98,10 +98,10 @@ public void addUpdateDelete_routing() {
ElasticsearchRequestAssertionMode.EXTENSIBLE
);
workPlan.execute().join();
clientMock.verifyExpectationsMet();
clientSpy.verifyExpectationsMet();

workPlan.delete( referenceProvider( "1", routingKey ) );
clientMock.expectNext(
clientSpy.expectNext(
ElasticsearchRequest.delete()
.pathComponent( URLEncodedString.fromString( INDEX_NAME ) )
.pathComponent( TYPE_NAME )
Expand All @@ -111,7 +111,7 @@ public void addUpdateDelete_routing() {
ElasticsearchRequestAssertionMode.EXTENSIBLE
);
workPlan.execute().join();
clientMock.verifyExpectationsMet();
clientSpy.verifyExpectationsMet();
}

private static class IndexAccessors {
Expand Down

0 comments on commit c16158c

Please sign in to comment.