Search in sources :

Example 6 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class PostsController method tags.

@RequestMapping(value = "/tag/{tagValue}", method = GET)
public String tags(@PathVariable("tagValue") String tagValue, Model model) throws TagNotFoundException, UnsupportedEncodingException {
    Tag tag = postService.getTag(URLDecoder.decode(tagValue, "UTF-8"));
    boolean showMore = postService.getPublishedPostsByTagId(tag.getTagId()).size() > POST_PAGING_SIZE;
    model.addAttribute("tag", tag);
    model.addAttribute("showmore", showMore);
    return POSTS_TAGS_VIEW;
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class PostRepoTests method savePostWithTags.

@Test
public void savePostWithTags() {
    Post post = Post.getBuilder(1L, "Post With Tags", "post-with-tags", null, "New post with tags!", PostType.POST, PostDisplayType.POST).build();
    Tag tag1 = new Tag("third tag");
    tag1 = tagRepository.save(tag1);
    Tag tag2 = new Tag("fourth tag");
    tag2 = tagRepository.save(tag2);
    Post saved = postRepository.save(post);
    saved.setTags(new HashSet<>());
    saved.getTags().add(tag1);
    saved.getTags().add(tag2);
    assertEquals(saved.getTags().size(), 2);
    postRepository.save(saved);
    List<Post> posts = postRepository.findAllWithDetail();
    Optional<Post> found = posts.stream().filter(p -> p.getPostId().equals(saved.getPostId())).findFirst();
    if (found.isPresent()) {
        assertEquals(found.get().getTags().size(), 2);
    }
}
Also used : PostTestUtils.getTestTags(com.nixmash.blog.jpa.utils.PostTestUtils.getTestTags) PostDisplayType(com.nixmash.blog.jpa.enums.PostDisplayType) Matchers.isA(org.hamcrest.Matchers.isA) DataConfigProfile(com.nixmash.blog.jpa.enums.DataConfigProfile) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) PostType(com.nixmash.blog.jpa.enums.PostType) Test(org.junit.Test) ActiveProfiles(org.springframework.test.context.ActiveProfiles) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Post(com.nixmash.blog.jpa.model.Post) HashSet(java.util.HashSet) ApplicationConfig(com.nixmash.blog.jpa.config.ApplicationConfig) List(java.util.List) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) Tag(com.nixmash.blog.jpa.model.Tag) Assert(org.junit.Assert) PostTestUtils.getTestCategory(com.nixmash.blog.jpa.utils.PostTestUtils.getTestCategory) Before(org.junit.Before) Post(com.nixmash.blog.jpa.model.Post) Tag(com.nixmash.blog.jpa.model.Tag) Test(org.junit.Test)

Example 8 with Tag

use of com.nixmash.blog.jpa.model.Tag in project nixmash-blog by mintster.

the class PostRepoTests method addTags.

@Test
public void addTags() {
    Integer startTagCount = tagRepository.findAll().size();
    Tag tag = new Tag("tag one");
    tagRepository.save(tag);
    tag = new Tag("tag two ");
    tagRepository.save(tag);
    Set<Tag> found = tagRepository.findAll();
    assertEquals(found.size(), startTagCount + 2);
}
Also used : Tag(com.nixmash.blog.jpa.model.Tag) Test(org.junit.Test)

Aggregations

Tag (com.nixmash.blog.jpa.model.Tag)8 Test (org.junit.Test)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ApplicationConfig (com.nixmash.blog.jpa.config.ApplicationConfig)1 DataConfigProfile (com.nixmash.blog.jpa.enums.DataConfigProfile)1 PostDisplayType (com.nixmash.blog.jpa.enums.PostDisplayType)1 PostType (com.nixmash.blog.jpa.enums.PostType)1 Post (com.nixmash.blog.jpa.model.Post)1 PostTestUtils.getTestCategory (com.nixmash.blog.jpa.utils.PostTestUtils.getTestCategory)1 PostTestUtils.getTestTags (com.nixmash.blog.jpa.utils.PostTestUtils.getTestTags)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 EntityManager (javax.persistence.EntityManager)1 PersistenceContext (javax.persistence.PersistenceContext)1 Matchers.isA (org.hamcrest.Matchers.isA)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 RunWith (org.junit.runner.RunWith)1