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-02-27 16:21:06 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5c55a7e1d457f9385a205486384ff8b00754f8d8
5c55a7e1
1 parent
98b1f8d1
Réorganisation des tests (Nested)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
70 deletions
src/test/java/org/legrog/web/publisher/PublisherServiceDefaultTest.java
src/test/java/org/legrog/web/publisher/PublisherServiceDefaultTest.java
View file @
5c55a7e
package
org
.
legrog
.
web
.
publisher
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.DisplayName
;
...
...
@@ -57,84 +58,102 @@ public class PublisherServiceDefaultTest {
this
.
publisherRepository
=
publisherRepository
;
}
@DisplayName
(
"When a new publisher is added, both Publisher and PublisherVersion should be saved in the right state"
)
@Test
public
void
testAddNewPublisher
(
@Mock
PublisherVersionRepository
publisherVersionRepository
)
{
publisherServiceDefault
.
addNewPublisher
(
publisherVersion
);
publisher
=
publisherVersion
.
getPublisher
();
assertThat
(
publisher
.
getVersions
()).
containsExactly
(
publisherVersion
);
assertThat
(
publisherVersion
.
getPublisher
()).
isEqualTo
(
publisher
);
verify
(
publisherRepository
).
save
(
publisher
);
verify
(
publisherVersionRepository
).
save
(
publisherVersion
);
}
@Nested
@DisplayName
(
"addNewPublisher method"
)
class
AddNewPublisherTests
{
@DisplayName
(
"When a new publisher is added, both Publisher and PublisherVersion should be saved in the right state"
)
@Test
public
void
testAddNewPublisher
(
@Mock
PublisherVersionRepository
publisherVersionRepository
)
{
publisherServiceDefault
.
addNewPublisher
(
publisherVersion
);
publisher
=
publisherVersion
.
getPublisher
();
assertThat
(
publisher
.
getVersions
()).
containsExactly
(
publisherVersion
);
assertThat
(
publisherVersion
.
getPublisher
()).
isEqualTo
(
publisher
);
verify
(
publisherRepository
).
save
(
publisher
);
verify
(
publisherVersionRepository
).
save
(
publisherVersion
);
}
@DisplayName
(
"When a new version of a publisher is added, setting it up, attaching it to publisher and saving both"
)
@Test
public
void
testAddVersionToPublisher
(
@Mock
PublisherRepository
publisherRepository
,
@Mock
PublisherVersionRepository
publisherVersionRepository
)
{
publisherServiceDefault
.
addNewPublisher
(
publisherVersion
);
publisher
=
publisherVersion
.
getPublisher
();
publisherServiceDefault
.
addVersionToPublisher
(
publisher
,
publisherVersion1
);
assertThat
(
publisherVersion1
.
getPublisher
()).
isEqualTo
(
publisher
);
assertThat
(
publisher
.
getVersions
()).
contains
(
publisherVersion
,
publisherVersion1
);
verify
(
publisherRepository
,
times
(
2
)).
save
(
publisher
);
verify
(
publisherVersionRepository
).
save
(
publisherVersion1
);
}
@DisplayName
(
"When a PublisherVersion is validated, it should be the right one"
)
@Test
public
void
testValidateVersionRight
()
{
Set
<
PublisherVersion
>
publisherVersions
;
@Nested
@DisplayName
(
"addVersionToPublisher method"
)
class
AddVersionToPublisherTests
{
@DisplayName
(
"When a new version of a publisher is added, setting it up, attaching it to publisher and saving both"
)
@Test
public
void
testAddVersionToPublisher
(
@Mock
PublisherRepository
publisherRepository
,
@Mock
PublisherVersionRepository
publisherVersionRepository
)
{
publisherServiceDefault
.
addNewPublisher
(
publisherVersion
);
publisher
=
publisherVersion
.
getPublisher
();
publisherServiceDefault
.
addVersionToPublisher
(
publisher
,
publisherVersion1
);
assertThat
(
publisherVersion1
.
getPublisher
()).
isEqualTo
(
publisher
);
assertThat
(
publisher
.
getVersions
()).
contains
(
publisherVersion
,
publisherVersion1
);
verify
(
publisherRepository
,
times
(
2
)).
save
(
publisher
);
verify
(
publisherVersionRepository
).
save
(
publisherVersion1
);
}
publisher
=
new
Publisher
();
publisherVersion
=
new
PublisherVersion
();
publisherVersions
=
new
HashSet
<>();
publisherVersions
.
add
(
publisherVersion
);
publisherVersions
.
add
(
publisherVersionMock
);
publisher
.
setVersions
(
publisherVersions
);
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
assertThat
(
publisher
.
getValidatedVersion
()).
isEqualTo
(
publisherVersionMock
);
}
@DisplayName
(
"When a publisherVersion is validated, the indexed IndexedPublisher should have all attributes right"
)
@Test
public
void
testValidateIndexPublisher
(
@Mock
PublisherSearchRepository
publisherSearchRepository
)
{
publisher
=
new
Publisher
();
publisher
.
setPublisherId
(
111
);
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
when
(
publisherVersionMock
.
getPublisherName
()).
thenReturn
(
"nom"
);
when
(
publisherVersionMock
.
getPublisherHistory
()).
thenReturn
(
"histoire"
);
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
try
{
Mockito
.
verify
(
publisherSearchRepository
).
save
(
indexedPublisherArgumentCaptor
.
capture
());
}
catch
(
IndexingException
e
)
{
logger
.
error
(
"IndexingException {}"
,
e
);
@Nested
@DisplayName
(
"addVersionToPublisher method"
)
class
ValidatePublisherVersionTests
{
@DisplayName
(
"When a PublisherVersion is validated, it should be the right one"
)
@Test
public
void
testValidateVersionRight
()
{
Set
<
PublisherVersion
>
publisherVersions
;
publisher
=
new
Publisher
();
publisherVersion
=
new
PublisherVersion
();
publisherVersions
=
new
HashSet
<>();
publisherVersions
.
add
(
publisherVersion
);
publisherVersions
.
add
(
publisherVersionMock
);
publisher
.
setVersions
(
publisherVersions
);
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
assertThat
(
publisher
.
getValidatedVersion
()).
isEqualTo
(
publisherVersionMock
);
}
@DisplayName
(
"When a publisherVersion is validated, the indexed IndexedPublisher should have all attributes right"
)
@Test
public
void
testValidateIndexPublisher
(
@Mock
PublisherSearchRepository
publisherSearchRepository
)
{
publisher
=
new
Publisher
();
publisher
.
setPublisherId
(
111
);
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
when
(
publisherVersionMock
.
getPublisherName
()).
thenReturn
(
"nom"
);
when
(
publisherVersionMock
.
getPublisherHistory
()).
thenReturn
(
"histoire"
);
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
try
{
Mockito
.
verify
(
publisherSearchRepository
).
save
(
indexedPublisherArgumentCaptor
.
capture
());
}
catch
(
IndexingException
e
)
{
logger
.
error
(
"IndexingException {}"
,
e
);
}
IndexedPublisher
indexedPublisher
=
indexedPublisherArgumentCaptor
.
getValue
();
assertThat
(
indexedPublisher
.
getPublisherId
()).
isEqualTo
(
111
);
assertThat
(
indexedPublisher
.
getPublisherName
()).
isEqualTo
(
"nom"
);
assertThat
(
indexedPublisher
.
getPublisherHistory
()).
isEqualTo
(
"histoire"
);
}
@DisplayName
(
"When a validate creates a PublisherAction it should be saved and have all attributes right"
)
@Test
public
void
testValidateCreateAction
(
@Mock
PublisherActionRepository
publisherActionRepository
)
{
PublisherAction
publisherAction
;
ActionType
actionType
=
ActionType
.
VALIDATE
;
publisher
=
new
Publisher
();
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
publisherAction
=
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
verify
(
publisherActionRepository
).
save
(
publisherAction
);
assertThat
(
publisherAction
.
getPublisherVersion
()).
isEqualTo
(
publisherVersionMock
);
assertThat
(
publisherAction
.
getPublisher
()).
isEqualTo
(
publisher
);
assertThat
(
publisherAction
.
getPublisher
().
getValidatedVersion
()).
isEqualTo
(
publisherVersionMock
);
assertThat
(
publisherAction
.
getActionType
()).
isEqualTo
(
actionType
);
}
IndexedPublisher
indexedPublisher
=
indexedPublisherArgumentCaptor
.
getValue
();
assertThat
(
indexedPublisher
.
getPublisherId
()).
isEqualTo
(
111
);
assertThat
(
indexedPublisher
.
getPublisherName
()).
isEqualTo
(
"nom"
);
assertThat
(
indexedPublisher
.
getPublisherHistory
()).
isEqualTo
(
"histoire"
);
}
@DisplayName
(
"When a validate creates a PublisherAction it should be saved and have all attributes right"
)
@Test
public
void
testValidateCreateAction
(
@Mock
PublisherActionRepository
publisherActionRepository
)
{
PublisherAction
publisherAction
;
ActionType
actionType
=
ActionType
.
VALIDATE
;
publisher
=
new
Publisher
();
when
(
publisherVersionMock
.
getPublisher
()).
thenReturn
(
publisher
);
publisherAction
=
publisherServiceDefault
.
validatePublisherVersion
(
publisherVersionMock
);
verify
(
publisherActionRepository
).
save
(
publisherAction
);
assertThat
(
publisherAction
.
getPublisherVersion
()).
isEqualTo
(
publisherVersionMock
);
assertThat
(
publisherAction
.
getPublisher
()).
isEqualTo
(
publisher
);
assertThat
(
publisherAction
.
getPublisher
().
getValidatedVersion
()).
isEqualTo
(
publisherVersionMock
);
assertThat
(
publisherAction
.
getActionType
()).
isEqualTo
(
actionType
);
}
}
...
...
Please
register
or
login
to post a comment