22
33
44import org .junit .Assert ;
5+ import org .junit .Ignore ;
56import org .junit .Test ;
67import org .junit .runner .RunWith ;
78import org .slf4j .Logger ;
1617import org .springframework .transaction .annotation .Propagation ;
1718import org .springframework .transaction .annotation .Transactional ;
1819import org .woehlke .twitterwall .conf .properties .TestdataProperties ;
19- import org .woehlke .twitterwall .oodm .entities .Media ;
2020import org .woehlke .twitterwall .oodm .entities .Mention ;
21+ import org .woehlke .twitterwall .oodm .entities .Task ;
22+ import org .woehlke .twitterwall .oodm .entities .parts .CountedEntities ;
23+ import org .woehlke .twitterwall .oodm .entities .parts .TaskType ;
24+ import org .woehlke .twitterwall .scheduled .service .persist .CountedEntitiesService ;
2125
2226@ RunWith (SpringRunner .class )
2327@ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .NONE )
@@ -29,6 +33,12 @@ public class MentionServiceTest {
2933 @ Autowired
3034 private MentionService mentionService ;
3135
36+ @ Autowired
37+ private TaskService taskService ;
38+
39+ @ Autowired
40+ private CountedEntitiesService countedEntitiesService ;
41+
3242 //TODO: #198 https://github.com/phasenraum2010/twitterwall2/issues/198
3343 @ Autowired
3444 private TestdataProperties testdataProperties ;
@@ -38,6 +48,7 @@ public class MentionServiceTest {
3848 public void areDependenciesLoaded () throws Exception {
3949 Assert .assertNotNull (mentionService );
4050 Assert .assertNotNull (testdataProperties );
51+ Assert .assertNotNull (countedEntitiesService );
4152 }
4253
4354 @ Commit
@@ -48,6 +59,7 @@ public void fetchTestData() throws Exception {
4859 int size =1 ;
4960 Pageable pageRequest = new PageRequest (page ,size );
5061 Page <Mention > myPage = mentionService .getAll (pageRequest );
62+ Assert .assertTrue (msg ,myPage .getTotalElements ()>0 );
5163 if (myPage .getTotalElements ()>0 ){
5264 Mention myMedia = myPage .getContent ().iterator ().next ();
5365 Assert .assertNotNull (msg ,myMedia );
@@ -58,9 +70,77 @@ public void fetchTestData() throws Exception {
5870 }
5971 }
6072
73+ @ Commit
6174 @ Test
6275 public void createProxyMention () throws Exception {
76+ String msg = "createProxyMention: " ;
77+ CountedEntities countedEntities = countedEntitiesService .countAll ();
78+ TaskType type = TaskType .FETCH_TWEETS_FROM_TWITTER_SEARCH ;
79+ Task task = taskService .create ("MentionServiceTest." +msg ,type ,countedEntities );
80+ String mentionString = "ddhgcvdghvsdhg" ;
81+ Mention mention = new Mention (task ,task , mentionString );
82+ Mention createdMention = mentionService .createProxyMention (mention ,task );
83+ Assert .assertEquals (mentionString ,createdMention .getScreenName ());
84+ Assert .assertTrue (createdMention .isProxy ());
85+ }
6386
87+ @ Commit
88+ @ Test
89+ public void getAllWithoutPersistentUser () throws Exception {
90+ String msg = "getAllWithoutPersistentUser: " ;
91+ int page =1 ;
92+ int size =10 ;
93+ Pageable pageRequest = new PageRequest (page ,size );
94+ Page <Mention > pageMention = mentionService .getAllWithoutPersistentUser (pageRequest );
95+ Assert .assertTrue (msg ,pageMention .getTotalElements ()>0 );
96+ if (pageMention .getTotalElements ()>0 ){
97+ for (Mention mention : pageMention .getContent ()){
98+ Assert .assertFalse (msg ,mention .hasPersistentUser ());
99+ Assert .assertNotNull (msg ,mention .getIdTwitterOfUser ());
100+ }
101+ } else {
102+ log .debug (msg +" found: mentionService.getAllWithoutPersistentUser() == 0" );
103+ }
64104 }
65105
106+ //TODO: #215 https://github.com/phasenraum2010/twitterwall2/issues/215
107+ @ Ignore
108+ @ Commit
109+ @ Test
110+ public void findByIdTwitter () throws Exception {
111+ String msg = "findByIdTwitter: " ;
112+ int page =1 ;
113+ int size =1 ;
114+ Pageable pageRequest = new PageRequest (page ,size );
115+ Page <Mention > myPage = mentionService .getAll (pageRequest );
116+ Assert .assertTrue (msg ,myPage .getTotalElements ()>0 );
117+ if (myPage .getTotalElements ()>0 ) {
118+ Mention myMention = myPage .getContent ().iterator ().next ();
119+ long idTwitter = myMention .getIdTwitter ();
120+ Mention myFoundMention = mentionService .findByIdTwitter (idTwitter );
121+ Assert .assertNotNull (myFoundMention );
122+ Assert .assertEquals (msg ,idTwitter ,myFoundMention .getIdTwitter ().longValue ());
123+ }
124+ }
125+
126+ //TODO: #215 https://github.com/phasenraum2010/twitterwall2/issues/215
127+ @ Ignore
128+ @ Commit
129+ @ Test
130+ public void findByScreenName () throws Exception {
131+ String msg = "findByScreenName: " ;
132+ int page =1 ;
133+ int size =1 ;
134+ Pageable pageRequest = new PageRequest (page ,size );
135+ Page <Mention > myPage = mentionService .getAll (pageRequest );
136+ Assert .assertTrue (msg ,myPage .getTotalElements ()>0 );
137+ if (myPage .getTotalElements ()>0 ) {
138+ Mention myMention = myPage .getContent ().iterator ().next ();
139+ String expectedScreenName = myMention .getScreenName ();
140+ Mention myFoundMention = mentionService .findByScreenName (expectedScreenName );
141+ Assert .assertNotNull (myFoundMention );
142+ String foundScreenName =myFoundMention .getScreenName ();
143+ Assert .assertEquals (msg ,expectedScreenName ,foundScreenName );
144+ }
145+ }
66146}
0 commit comments