Toggle navigation
Toggle navigation
This project
Loading...
Sign in
grogv3
/
grog-cubi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Francois Leveque
2017-03-06 12:29:29 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
699c90bab9520a6c5461aa62b505bd557433d6a8
699c90ba
1 parent
40f2aa63
More tests
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
src/test/java/org/legrog/entities/AccountSearchRepositorySolrjTest.java
src/test/java/org/legrog/entities/AccountSearchRepositorySolrjTest.java
0 → 100644
View file @
699c90b
package
org
.
legrog
.
entities
;
import
org.apache.solr.client.solrj.SolrClient
;
import
org.apache.solr.client.solrj.SolrQuery
;
import
org.apache.solr.client.solrj.SolrServerException
;
import
org.apache.solr.client.solrj.beans.BindingException
;
import
org.apache.solr.common.params.SolrParams
;
import
org.junit.jupiter.api.*
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.junit.platform.runner.JUnitPlatform
;
import
org.junit.runner.RunWith
;
import
org.legrog.test.MockitoExtension
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
/**
* Classe testant AccountSearchRepositorySolrj
*/
@RunWith
(
JUnitPlatform
.
class
)
@ExtendWith
(
MockitoExtension
.
class
)
@DisplayName
(
"Indexes and searches with SearchRepository"
)
public
class
AccountSearchRepositorySolrjTest
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
AccountSearchRepository
accountSearchRepository
;
private
SolrClient
solrClient
;
@Captor
ArgumentCaptor
<
SolrParams
>
solrParamsArgumentCaptor
;
@BeforeEach
public
void
setup
(
@Mock
SolrClient
solrClient
)
{
accountSearchRepository
=
new
AccountSearchRepositorySolrj
(
solrClient
);
this
.
solrClient
=
solrClient
;
}
@Nested
@DisplayName
(
"search method"
)
class
SearchTests
{
@DisplayName
(
"when repository in IO error, should throw a SearchingException"
)
@Test
public
void
searchIOETest
()
throws
IOException
,
SolrServerException
{
when
(
solrClient
.
query
(
Mockito
.
anyString
(),
Mockito
.
any
())).
thenThrow
(
new
IOException
());
Assertions
.
assertThrows
(
SearchingException
.
class
,
()
->
accountSearchRepository
.
search
(
"a"
));
}
@DisplayName
(
"when repository in SolrServerException, should throw an SearchingException with its root cause"
)
@Test
public
void
searchSSETest
()
throws
SolrServerException
,
IOException
{
when
(
solrClient
.
query
(
Mockito
.
any
())).
thenThrow
(
new
SolrServerException
(
new
BindingException
(
"BE test 2"
)));
try
{
accountSearchRepository
.
search
(
"b"
);
}
catch
(
SearchingException
se
)
{
logger
.
error
(
"SearchingException {}"
,
se
);
assertThat
(
se
.
getRootCause
().
getClass
()).
isEqualTo
(
BindingException
.
class
);
}
}
@DisplayName
(
"when called, it parameter should be embedded in a query sent through SolrClient"
)
@Test
public
void
searchParameterTest
()
throws
IOException
,
SolrServerException
{
try
{
accountSearchRepository
.
search
(
"c"
);
Mockito
.
verify
(
solrClient
).
query
(
Mockito
.
anyString
(),
solrParamsArgumentCaptor
.
capture
());
}
catch
(
SearchingException
se
)
{
logger
.
error
(
"SearchingException {}"
,
se
);
}
SolrQuery
solrQuery
=
(
SolrQuery
)
solrParamsArgumentCaptor
.
getValue
();
assertThat
(
solrQuery
.
getQuery
()).
isEqualTo
(
"c"
);
}
}
}
Please
register
or
login
to post a comment