diff --git a/src/main/java/run/halo/app/service/CategoryService.java b/src/main/java/run/halo/app/service/CategoryService.java index 130c291e1..d0a76e021 100755 --- a/src/main/java/run/halo/app/service/CategoryService.java +++ b/src/main/java/run/halo/app/service/CategoryService.java @@ -18,6 +18,7 @@ import java.util.List; * @author ryanwang * @date : 2019-03-14 */ +@Transactional(readOnly = true) public interface CategoryService extends CrudService { /** diff --git a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java index 647620a37..e7da2c132 100644 --- a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java @@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Sort; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import run.halo.app.exception.AlreadyExistsException; @@ -46,6 +47,7 @@ public class CategoryServiceImpl extends AbstractCrudService } @Override + @Transactional public Category create(Category category) { Assert.notNull(category, "Category to create must not be null"); @@ -161,6 +163,7 @@ public class CategoryServiceImpl extends AbstractCrudService } @Override + @Transactional public void removeCategoryAndPostCategoryBy(Integer categoryId) { // Remove category removeById(categoryId); diff --git a/src/main/java/run/halo/app/service/impl/TagServiceImpl.java b/src/main/java/run/halo/app/service/impl/TagServiceImpl.java index a8f46fcae..066ba79e6 100644 --- a/src/main/java/run/halo/app/service/impl/TagServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/TagServiceImpl.java @@ -2,6 +2,7 @@ package run.halo.app.service.impl; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import run.halo.app.exception.AlreadyExistsException; @@ -35,6 +36,7 @@ public class TagServiceImpl extends AbstractCrudService implements } @Override + @Transactional public Tag create(Tag tag) { // Check if the tag is exist long count = tagRepository.countByNameOrSlugName(tag.getName(), tag.getSlugName()); diff --git a/src/test/java/run/halo/app/service/impl/PostServiceImplTest.java b/src/test/java/run/halo/app/service/impl/PostServiceImplTest.java index 5e1ca863c..23613eca5 100644 --- a/src/test/java/run/halo/app/service/impl/PostServiceImplTest.java +++ b/src/test/java/run/halo/app/service/impl/PostServiceImplTest.java @@ -1,24 +1,52 @@ -//package run.halo.app.service.impl; -// -//import org.junit.Assert; -//import org.junit.Test; -//import org.junit.runner.RunWith; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.boot.test.context.SpringBootTest; -//import org.springframework.test.context.ActiveProfiles; -//import org.springframework.test.context.junit4.SpringRunner; -// -//@RunWith(SpringRunner.class) -//@SpringBootTest -//@ActiveProfiles("dev") -//public class PostServiceImplTest { -// -// @Autowired -// private PostServiceImpl postService; -// -// @Test -// public void getContent(){ -// String exportMarkdown = postService.exportMarkdown(18); -// System.out.println(exportMarkdown); -// } -//} \ No newline at end of file +package run.halo.app.service.impl; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("dev") +public class PostServiceImplTest { + + String standardMdContent = "---\n" + + "title: springfox-swagger2配置成功但无法访问/swagger-ui.html\n" + + "tags:\n" + + " - spring boot\n" + + " - swagger\n" + + " - solution\n" + + "date: 2018-11-23 16:11:28\n" + + "---\n" + + "\n" + + "# Pre\n" + + "\n" + + "在前后端分离项目中,通常需要用到 API 文档,springfox 开发的 **[SpringFox](https://github.com/springfox/springfox)** 可以实现自动化 json API 文档。"; + + String nonStandardMdContent = "---\n" + + "title: Basic concepts of JPA\n" + + "date: 2018-08-03 11:57:00\n" + + "tags: ['spring', 'jpa', 'database', 'concept']\n" + + "---\n" + + "\n" + + "以下将讲解关系型数据的关系描述。仅仅是作为总结。"; + + @Autowired + private PostServiceImpl postService; + + @Test + @Ignore + public void getContent() { + String exportMarkdown = postService.exportMarkdown(18); + System.out.println(exportMarkdown); + } + + @Test + public void markdownImportTest() { + postService.importMarkdown(standardMdContent, "standard"); + postService.importMarkdown(nonStandardMdContent, "nonStandard"); + } +} \ No newline at end of file