11package org .baeldung .persistence .repository ;
22
33import org .baeldung .config .StudentJpaConfig ;
4+ import org .baeldung .inmemory .persistence .dao .ManyStudentRepository ;
5+ import org .baeldung .inmemory .persistence .dao .ManyTagRepository ;
46import org .baeldung .inmemory .persistence .dao .StudentRepository ;
5- import org .baeldung .inmemory .persistence .model .Student ;
7+ import org .baeldung .inmemory .persistence .model .* ;
68import org .junit .Test ;
79import org .junit .runner .RunWith ;
810import org .springframework .test .context .ContextConfiguration ;
1315import javax .annotation .Resource ;
1416
1517import java .util .Arrays ;
18+ import java .util .Collections ;
1619import java .util .List ;
1720
1821import static org .junit .Assert .assertEquals ;
@@ -24,6 +27,12 @@ public class InMemoryDBIntegrationTest {
2427
2528 @ Resource
2629 private StudentRepository studentRepository ;
30+
31+ @ Resource
32+ private ManyStudentRepository manyStudentRepository ;
33+
34+ @ Resource
35+ private ManyTagRepository manyTagRepository ;
2736
2837 private static final long ID = 1 ;
2938 private static final String NAME ="john" ;
@@ -79,4 +88,47 @@ public void givenStudentWithTags_whenSave_thenGetByNameAndTagOk(){
7988 assertEquals ("name incorrect" , NAME , student2 .getName ());
8089 }
8190
91+ @ Test
92+ public void givenStudenWithSkillTags_whenSave_thenGetByNameAndSkillTag () {
93+ Student student = new Student (1 , "Will" );
94+ SkillTag skill1 = new SkillTag ("java" , 5 );
95+ student .setSkillTags (Arrays .asList (skill1 ));
96+ studentRepository .save (student );
97+
98+ Student student2 = new Student (2 , "Joe" );
99+ SkillTag skill2 = new SkillTag ("java" , 1 );
100+ student2 .setSkillTags (Arrays .asList (skill2 ));
101+ studentRepository .save (student2 );
102+
103+ List <Student > students = studentRepository .retrieveByNameFilterByMinimumSkillTag ("java" , 3 );
104+ assertEquals ("size incorrect" , 1 , students .size ());
105+ }
106+
107+ @ Test
108+ public void givenStudentWithKVTags_whenSave_thenGetByTagOk (){
109+ Student student = new Student (0 , "John" );
110+ student .setKVTags (Arrays .asList (new KVTag ("department" , "computer science" )));
111+ studentRepository .save (student );
112+
113+ Student student2 = new Student (1 , "James" );
114+ student2 .setKVTags (Arrays .asList (new KVTag ("department" , "humanities" )));
115+ studentRepository .save (student2 );
116+
117+ List <Student > students = studentRepository .retrieveByKeyTag ("department" );
118+ assertEquals ("size incorrect" , 2 , students .size ());
119+ }
120+
121+ @ Test
122+ public void givenStudentWithManyTags_whenSave_theyGetByTagOk () {
123+ ManyTag tag = new ManyTag ("full time" );
124+ manyTagRepository .save (tag );
125+
126+ ManyStudent student = new ManyStudent ("John" );
127+ student .setManyTags (Collections .singleton (tag ));
128+ manyStudentRepository .save (student );
129+
130+ List <ManyStudent > students = manyStudentRepository .findByManyTags_Name ("full time" );
131+ assertEquals ("size incorrect" , 1 , students .size ());
132+ }
133+
82134}
0 commit comments