Commit 36fed77e authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Add unit tests for ContentService

parent 0f9e7235
......@@ -172,6 +172,42 @@ public class CMSControllerTest extends AbstractApiTest {
/*@formatter:on*/
}
/**
* Expect an error when try to create two global articles
* for the same slug and language
*/
@Test
public void failToCreateGlobalArticleTest() throws Exception {
Article article = new Article();
article.setLang("en");
article.setSlug("test-slug");
/*@formatter:off*/
mockMvc
.perform(post(CMSController.CONTROLLER_URL.concat("/create-article"))
.content(objectMapper.writeValueAsString(article))
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())))
.andExpect(jsonPath("$.slug", is(article.getSlug())))
.andExpect(jsonPath("$.lang", is(article.getLang())));
/*@formatter:on*/
// must not save, because already exists
/*@formatter:off*/
mockMvc
.perform(post(CMSController.CONTROLLER_URL.concat("/create-article"))
.content(objectMapper.writeValueAsString(article))
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isBadRequest())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", not(nullValue())));
/*@formatter:on*/
}
@Test
public void listArticlesTest() throws Exception {
final ArticleFilter filter = new ArticleFilter();
......
......@@ -58,7 +58,7 @@ public class ContentServiceTest extends AbstractServicesTest {
contentService.createActivityPost("title of activity post", "summary of activity post", "body of activity post");
// create article for test
testArticle = contentService.createGlobalArticle(ContentService.SMTP_EMAIL_VERIFICATION, contentService.getDefaultLocale(), "title of article", null, "<h3>body of article</h3>", false);
testArticle = contentService.createGlobalArticle(ContentService.SMTP_EMAIL_PASSWORD, contentService.getDefaultLocale(), "title of article", null, "<h3>body of article</h3>", false);
}
@Transactional
......@@ -120,7 +120,7 @@ public class ContentServiceTest extends AbstractServicesTest {
public void getGlobalArticleTets() {
LOG.info("Start test-method getGlobalArticleTets");
assertNotNull(contentService.getGlobalArticle(ContentService.SMTP_EMAIL_VERIFICATION, Locale.ENGLISH));
assertNotNull(contentService.getGlobalArticle(ContentService.SMTP_EMAIL_PASSWORD, Locale.ENGLISH));
LOG.info("Test getGlobalArticleTets is passed!");
}
......@@ -141,7 +141,7 @@ public class ContentServiceTest extends AbstractServicesTest {
@Test
public void getArticleBySlugAndLangTest() {
LOG.info("Start test-method getArticleBySlugAndLangTest");
Article article = contentService.getArticleBySlugAndLang(ContentService.SMTP_EMAIL_VERIFICATION, "en");
Article article = contentService.getArticleBySlugAndLang(ContentService.SMTP_EMAIL_PASSWORD, "en");
assertNotNull(article);
LOG.info("Test getArticleBySlugAndLangTest is passed!");
......@@ -178,6 +178,26 @@ public class ContentServiceTest extends AbstractServicesTest {
LOG.info("Test createGlobalArticleTest is passed!");
}
/**
* Expect an error when try to create two global articles
* for the same slug and language
*/
@Test(expected = CRMException.class)
public void failToCreateSecondGlobalArticleTest() throws CRMException {
String slug = "create_global_article";
Locale locale = Locale.ENGLISH;
String title = "Create Global Article";
String body = "<h1>Create Global Article</h1>";
Article globalArticle = contentService.createGlobalArticle(slug, locale, title, null, body, false);
assertNotNull(globalArticle);
assertEquals(2, contentService.listArticles(new PageRequest(0, 6)).getContent().size());
// expect an error
contentService.createGlobalArticle(slug, locale, title, null, body, false);
}
@Test
public void updateGlobalArticleTest() throws CRMException {
LOG.info("Start test-method updateGlobalArticleTest");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment