/** Test the save method deletes items in between saves */ @Test public void testSaveDeletesItems() { Client client = createClient(); Group group = createGroup(client); // create 4 tags in a group List<Tag> tagListComplete = createTagList(group, 4); // split into two groups List<Tag> tagListFirstHalf = tagListComplete.subList(0, 2); List<Tag> tagListSecondHalf = tagListComplete.subList(2, 4); // make a team Team team1 = createTeam(client); // associate half of the tags to this team Set<Tag> tagSet = new HashSet<>(); tagSet.addAll(tagListFirstHalf); teamTagService.save(team1, tagSet); Page<TeamTag> tags = teamTagService.findAllTeamTagsWithTeam(null, team1); List<Tag> savedTags = new ArrayList<>(); for (TeamTag tag : tags) { savedTags.add(tag.getTag()); } assertThat( "tags should be found", savedTags, hasItems(tagListFirstHalf.toArray(new Tag[tagListFirstHalf.size()]))); // check that new tag save, overwrites the first save Set<Tag> overwriteTags = new HashSet<>(); overwriteTags.addAll(tagListSecondHalf); teamTagService.save(team1, overwriteTags); // load the tags again savedTags = new ArrayList<>(); tags = teamTagService.findAllTeamTagsWithTeam(null, team1); for (TeamTag tag : tags) { savedTags.add(tag.getTag()); } assertThat( "first set should not be found", savedTags, not(hasItems(tagListFirstHalf.toArray(new Tag[tagListFirstHalf.size()])))); assertThat( "second set should be found", savedTags, hasItems(tagListSecondHalf.toArray(new Tag[tagListSecondHalf.size()]))); }
/** Test List tags by group id */ @Test public void testSaveAndFind() { Client client = createClient(); Group group = createGroup(client); List<Tag> tagList = createTagList(group, 2); Team team1 = createTeam(client); Set<Tag> tagSet = new HashSet<>(); tagSet.add(tagList.get(0)); tagSet.add(tagList.get(1)); teamTagService.save(team1, tagSet); Page<TeamTag> teamTagPage = teamTagService.findAllTeamTagsWithTeam(null, team1); assertThat("teamTagPage has two teams", teamTagPage.getTotalElements(), is(2L)); }