Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
15
Issues
15
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
c4094c0a
Commit
c4094c0a
authored
Apr 27, 2015
by
Alexander Basov
Committed by
Matija Obreza
Apr 30, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mocked EmailService in EmailVerificationServiceTest
parent
51cd5a52
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
4 deletions
+105
-4
pom.xml
pom.xml
+5
-0
src/test/java/org/genesys2/unit/ContentServiceTest.java
src/test/java/org/genesys2/unit/ContentServiceTest.java
+91
-2
src/test/java/org/genesys2/unit/EmailVerificationServiceTest.java
.../java/org/genesys2/unit/EmailVerificationServiceTest.java
+9
-2
No files found.
pom.xml
View file @
c4094c0a
...
...
@@ -479,6 +479,11 @@
<artifactId>
pgr-ontology-model
</artifactId>
<version>
0.7.1-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-all
</artifactId>
<version>
2.0.2-beta
</version>
</dependency>
</dependencies>
<build>
...
...
src/test/java/org/genesys2/unit/ContentServiceTest.java
View file @
c4094c0a
...
...
@@ -3,7 +3,10 @@ package org.genesys2.unit;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.velocity.app.VelocityEngine
;
import
org.genesys2.server.model.impl.ActivityPost
;
import
org.genesys2.server.model.impl.Article
;
import
org.genesys2.server.persistence.domain.ActivityPostRepository
;
import
org.genesys2.server.persistence.domain.ArticleRepository
;
import
org.genesys2.server.service.ContentService
;
import
org.genesys2.server.service.HtmlSanitizer
;
import
org.genesys2.server.service.impl.ContentServiceImpl
;
...
...
@@ -11,6 +14,7 @@ import org.genesys2.server.service.impl.OWASPSanitizer;
import
org.genesys2.server.test.JpaDataConfig
;
import
org.genesys2.server.test.PropertyPlacholderInitializer
;
import
org.genesys2.spring.config.HazelcastConfig
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -20,12 +24,19 @@ import org.springframework.cache.support.NoOpCacheManager;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Locale
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
ContentServiceTest
.
Config
.
class
,
initializers
=
PropertyPlacholderInitializer
.
class
)
...
...
@@ -66,11 +77,32 @@ public class ContentServiceTest {
@Autowired
private
ActivityPostRepository
postRepository
;
@Autowired
private
ArticleRepository
articleRepository
;
@Before
public
void
setUp
()
{
//create activity post for test
contentService
.
createActivityPost
(
"title of activity post"
,
"body of activity post"
);
//create article for test
List
<
Article
>
articleList
=
new
ArrayList
<>();
Article
article
=
new
Article
();
article
.
setLang
(
"en"
);
article
.
setSlug
(
"smtp.email-verification"
);
article
.
setClassPk
(
contentService
.
ensureClassPK
(
Article
.
class
));
articleList
.
add
(
article
);
contentService
.
save
(
articleList
);
}
@After
public
void
teardown
()
{
//delete activity post
contentService
.
deleteActivityPost
(
contentService
.
lastNews
().
get
(
0
).
getId
());
//delete articles
articleRepository
.
deleteAll
();
}
@Test
...
...
@@ -86,9 +118,66 @@ public class ContentServiceTest {
public
void
lastNewsTest
()
{
LOG
.
info
(
"Start test-method lastNewsTest"
);
contentService
.
lastNews
();
List
<
ActivityPost
>
postList
=
contentService
.
lastNews
();
assertTrue
(
postList
.
size
()
==
1
);
assertTrue
(
postList
.
get
(
0
).
getTitle
().
equals
(
"title of activity post"
));
assertTrue
(
postList
.
get
(
0
).
getBody
().
equals
(
"body of activity post"
));
LOG
.
info
(
"Test lastNewsTest is passed!"
);
}
@Test
public
void
listArticlesTest
()
{
LOG
.
info
(
"Start test-method listArticlesTest"
);
List
<
Article
>
articleList
=
contentService
.
listArticles
(
new
PageRequest
(
0
,
6
)).
getContent
();
assertNotNull
(
"ArticleList must be not null"
,
articleList
);
assertTrue
(!
articleList
.
isEmpty
());
LOG
.
info
(
"Test listArticlesTest is passed!"
);
}
@Test
public
void
listArticlesByLangTest
(){
LOG
.
info
(
"Start test-method listArticlesByLangTest"
);
List
<
Article
>
articleList
=
contentService
.
listArticlesByLang
(
"ru"
,
new
PageRequest
(
0
,
6
)).
getContent
();
assertTrue
(
articleList
.
isEmpty
());
articleList
=
contentService
.
listArticlesByLang
(
"en"
,
new
PageRequest
(
0
,
6
)).
getContent
();
assertTrue
(!
articleList
.
isEmpty
());
LOG
.
info
(
"Test listArticlesByLangTest is passed!"
);
}
@Test
public
void
saveTest
(){
LOG
.
info
(
"Start test-method saveTest"
);
List
<
Article
>
articleList
=
contentService
.
listArticles
(
new
PageRequest
(
0
,
6
)).
getContent
();
assertTrue
(
articleList
.
size
()
==
1
);
List
<
Article
>
articleListForSave
=
new
ArrayList
<>();
Article
article
=
new
Article
();
article
.
setLang
(
"en"
);
article
.
setSlug
(
"smtp.email-verification"
);
article
.
setClassPk
(
contentService
.
ensureClassPK
(
Article
.
class
));
articleListForSave
.
add
(
article
);
contentService
.
save
(
articleListForSave
);
assertTrue
(
contentService
.
listArticles
(
new
PageRequest
(
0
,
6
)).
getContent
().
size
()
==
2
);
LOG
.
info
(
"Test saveTest is passed!"
);
}
@Test
public
void
getGlobalArticleTets
(){
LOG
.
info
(
"Start test-method getGlobalArticleTets"
);
assertNotNull
(
contentService
.
getGlobalArticle
(
"smtp.email-verification"
,
Locale
.
ENGLISH
));
LOG
.
info
(
"Test getGlobalArticleTets is passed!"
);
}
}
src/test/java/org/genesys2/unit/EmailVerificationServiceTest.java
View file @
c4094c0a
...
...
@@ -21,6 +21,7 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.support.NoOpCacheManager
;
...
...
@@ -64,7 +65,7 @@ public class EmailVerificationServiceTest {
@Bean
public
EMailService
eMailService
()
{
return
new
EMailServiceImpl
(
);
return
Mockito
.
mock
(
EMailServiceImpl
.
class
);
}
@Bean
...
...
@@ -108,6 +109,9 @@ public class EmailVerificationServiceTest {
}
}
@Autowired
private
EMailService
eMailService
;
@Autowired
private
VerificationTokenRepository
verificationTokenRepository
;
...
...
@@ -197,8 +201,9 @@ public class EmailVerificationServiceTest {
public
void
sendVerificationEmailTest
()
{
LOG
.
info
(
"Start test-method sendVerificationEmailTest"
);
Mockito
.
doNothing
().
when
(
eMailService
).
sendMail
(
"title for oneArticle"
,
"<h1>Tho BOdy of oneArticle</h1"
,
"salexandrbasov@gmail.com"
);
emailVerificationService
.
sendVerificationEmail
(
userService
.
listUsers
(
new
PageRequest
(
0
,
1
)).
getContent
().
get
(
0
));
Mockito
.
verify
(
eMailService
).
sendMail
(
"title for oneArticle"
,
"<h1>Tho BOdy of oneArticle</h1"
,
"salexandrbasov@gmail.com"
);
LOG
.
info
(
"Test sendVerificationEmailTest passed!"
);
}
...
...
@@ -206,7 +211,9 @@ public class EmailVerificationServiceTest {
public
void
sendPasswordResetEmailTest
()
{
LOG
.
info
(
"Start test-method sendPasswordResetEmailTest"
);
Mockito
.
doNothing
().
when
(
eMailService
).
sendMail
(
"title for twoArticle"
,
"<h1>Tho BOdy of twoArticle</h1"
,
"salexandrbasov@gmail.com"
);
emailVerificationService
.
sendPasswordResetEmail
(
userService
.
listUsers
(
new
PageRequest
(
0
,
1
)).
getContent
().
get
(
0
));
Mockito
.
verify
(
eMailService
).
sendMail
(
"title for twoArticle"
,
"<h1>Tho BOdy of twoArticle</h1"
,
"salexandrbasov@gmail.com"
);
LOG
.
info
(
"Test sendPasswordResetEmailTest passed!"
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment