Skip to content

Commit 6a716d5

Browse files
fixed broken Tests
1 parent 83e3e1c commit 6a716d5

File tree

8 files changed

+143
-22
lines changed

8 files changed

+143
-22
lines changed

src/main/java/org/woehlke/twitterwall/oodm/model/Mention.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public Mention(Task createdBy, Task updatedBy, String mentionString) {
123123
super(createdBy,updatedBy);
124124
this.idTwitter = ID_TWITTER_UNDEFINED;
125125
this.screenName = mentionString;
126-
if(screenName!=null) {
127-
this.screenNameUnique = screenName.toLowerCase();
126+
if(mentionString!=null) {
127+
this.screenNameUnique = mentionString.toLowerCase();
128128
}
129129
this.name = mentionString;
130130
}
@@ -136,13 +136,7 @@ private Mention() {
136136
@Override
137137
public String getUniqueId() {
138138

139-
boolean undefined = (idTwitter == ID_TWITTER_UNDEFINED);
140-
141-
String uniqueIdUndefined = "HAS_NO_USER_YET_" + id;
142-
143-
String uniqueIdHasUser = "" + idTwitter +"_"+ screenNameUnique;
144-
145-
return undefined ? uniqueIdUndefined : uniqueIdHasUser;
139+
return "" + idTwitter +"_"+ screenNameUnique;
146140
}
147141

148142
@Transient

src/main/java/org/woehlke/twitterwall/oodm/model/parts/AbstractDomainObject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ protected AbstractDomainObject(Task createdBy, Task updatedBy) {
7070
}
7171

7272
protected AbstractDomainObject() {
73+
this.createdBy = null;
74+
this.updatedBy = null;
75+
this.taskInfo = new TaskInfo();
76+
this.taskBasedCaching = new TaskBasedCaching();
7377
}
7478

7579
/**

src/main/java/org/woehlke/twitterwall/oodm/model/tasks/TaskBasedCaching.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class TaskBasedCaching implements Serializable {
7676
@Column(name=COLUMN_PREFIX+"start_garbage_collection")
7777
private Date startGarbageCollection;
7878

79+
@Column(name=COLUMN_PREFIX+"no_type")
80+
private Date noType;
81+
7982
@Transient
8083
public Boolean isCached(TaskType taskType, long timeToLive){
8184
Date lastApiCall = null;
@@ -140,6 +143,9 @@ public Boolean isCached(TaskType taskType, long timeToLive){
140143
case GARBAGE_COLLECTION:
141144
lastApiCall = startGarbageCollection;
142145
break;
146+
case NULL:
147+
lastApiCall = noType;
148+
break;
143149
default: break;
144150
}
145151
if(lastApiCall == null){
@@ -222,13 +228,16 @@ public void store(TaskType taskType){
222228
case GARBAGE_COLLECTION:
223229
startGarbageCollection = lastApiCall;
224230
break;
231+
case NULL:
232+
noType = lastApiCall;
233+
break;
225234
default:
226235
break;
227236
}
228237
}
229238
}
230239

231-
public TaskBasedCaching(Date fetchTweetsFromSearch, Date updateTweets, Date updateUsers, Date updateUsersFromMentions, Date fetchUsersFromList, Date controllerGetTestdataTweets, Date controllerGetTestdataUser, Date controllerAddUserForScreenName, Date controllerCreateImprintUser, Date removeOldDataFromStorage, Date fetchFollower, Date fetchFriends, Date getHomeTimeline, Date getUserTimeline, Date getMentions, Date getFavorites, Date getRetweetsOfMe, Date getLists,Date fetchUserlistOwners,Date startGarbageCollection, Date updatedUrls) {
240+
public TaskBasedCaching(Date fetchTweetsFromSearch, Date updateTweets, Date updateUsers, Date updateUsersFromMentions, Date fetchUsersFromList, Date controllerGetTestdataTweets, Date controllerGetTestdataUser, Date controllerAddUserForScreenName, Date controllerCreateImprintUser, Date removeOldDataFromStorage, Date fetchFollower, Date fetchFriends, Date getHomeTimeline, Date getUserTimeline, Date getMentions, Date getFavorites, Date getRetweetsOfMe, Date getLists,Date fetchUserlistOwners,Date startGarbageCollection, Date updatedUrls, Date noType) {
232241
this.fetchTweetsFromSearch = fetchTweetsFromSearch;
233242
this.updateTweets = updateTweets;
234243
this.updateUsers = updateUsers;
@@ -250,6 +259,7 @@ public TaskBasedCaching(Date fetchTweetsFromSearch, Date updateTweets, Date upda
250259
this.fetchUserlistOwners = fetchUserlistOwners;
251260
this.startGarbageCollection = startGarbageCollection;
252261
this.updatedUrls = updatedUrls;
262+
this.noType = noType;
253263
}
254264

255265
public TaskBasedCaching() {
@@ -273,6 +283,7 @@ public TaskBasedCaching() {
273283
this.fetchUserlistOwners = null;
274284
this.startGarbageCollection = null;
275285
this.updatedUrls = null;
286+
this.noType = null;
276287
}
277288

278289
public Date getFetchTweetsFromSearch() {
@@ -359,6 +370,10 @@ public Date getUpdatedUrls() {
359370
return updatedUrls;
360371
}
361372

373+
public Date getNoType() {
374+
return noType;
375+
}
376+
362377
@Override
363378
public boolean equals(Object o) {
364379
if (this == o) return true;
@@ -399,7 +414,9 @@ public boolean equals(Object o) {
399414
if (getLists != null ? !getLists.equals(that.getLists) : that.getLists != null) return false;
400415
if (fetchUserlistOwners != null ? !fetchUserlistOwners.equals(that.fetchUserlistOwners) : that.fetchUserlistOwners != null)
401416
return false;
402-
return startGarbageCollection != null ? startGarbageCollection.equals(that.startGarbageCollection) : that.startGarbageCollection == null;
417+
if (startGarbageCollection != null ? !startGarbageCollection.equals(that.startGarbageCollection) : that.startGarbageCollection != null)
418+
return false;
419+
return noType != null ? noType.equals(that.noType) : that.noType == null;
403420
}
404421

405422
@Override
@@ -425,6 +442,7 @@ public int hashCode() {
425442
result = 31 * result + (getLists != null ? getLists.hashCode() : 0);
426443
result = 31 * result + (fetchUserlistOwners != null ? fetchUserlistOwners.hashCode() : 0);
427444
result = 31 * result + (startGarbageCollection != null ? startGarbageCollection.hashCode() : 0);
445+
result = 31 * result + (noType != null ? noType.hashCode() : 0);
428446
return result;
429447
}
430448

@@ -452,6 +470,7 @@ public String toString() {
452470
", getLists=" + getLists +
453471
", fetchUserlistOwners=" + fetchUserlistOwners +
454472
", startGarbageCollection=" + startGarbageCollection +
473+
", noType=" + noType +
455474
'}';
456475
}
457476

src/main/java/org/woehlke/twitterwall/oodm/model/tasks/TaskInfo.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.persistence.Transient;
99
import javax.validation.constraints.NotNull;
1010
import java.io.Serializable;
11+
import java.util.Date;
1112

1213
/**
1314
* Created by tw on 10.07.17.
@@ -96,6 +97,10 @@ public class TaskInfo implements Serializable {
9697
@Column(nullable = false,name="start_garbage_collection")
9798
private Boolean startGarbageCollection = false;
9899

100+
@NotNull
101+
@Column(nullable = false,name="no_type")
102+
private Boolean noType = false;
103+
99104
@Transient
100105
public void setTaskInfoFromTask(Task task) {
101106
if(task!=null) {
@@ -161,6 +166,9 @@ public void setTaskInfoFromTask(Task task) {
161166
case GARBAGE_COLLECTION:
162167
startGarbageCollection = true;
163168
break;
169+
case NULL:
170+
noType = true;
171+
break;
164172
default:
165173
break;
166174
}
@@ -170,7 +178,7 @@ public void setTaskInfoFromTask(Task task) {
170178
public TaskInfo() {
171179
}
172180

173-
public TaskInfo(Boolean fetchTweetsFromSearch, Boolean updateTweets, Boolean updatedUsers, Boolean updateUsersFromMentions, Boolean fetchUsersFromList, Boolean controllerCreateTestdataTweets, Boolean controllerCreateTestdataUsers, Boolean controllerCreateImprintUser, Boolean removeOldDataFromStorage, Boolean fetchFollower, Boolean fetchFriends,Boolean fetchUserlistOwners, Boolean updatedUrls) {
181+
public TaskInfo(Boolean fetchTweetsFromSearch, Boolean updateTweets, Boolean updatedUsers, Boolean updateUsersFromMentions, Boolean fetchUsersFromList, Boolean controllerCreateTestdataTweets, Boolean controllerCreateTestdataUsers, Boolean controllerCreateImprintUser, Boolean removeOldDataFromStorage, Boolean fetchFollower, Boolean fetchFriends,Boolean fetchUserlistOwners, Boolean updatedUrls, Boolean noType) {
174182
this.fetchTweetsFromSearch = fetchTweetsFromSearch;
175183
this.updateTweets = updateTweets;
176184
this.updatedUsers = updatedUsers;
@@ -184,6 +192,7 @@ public TaskInfo(Boolean fetchTweetsFromSearch, Boolean updateTweets, Boolean upd
184192
this.fetchFriends = fetchFriends;
185193
this.fetchUserlistOwners = fetchUserlistOwners;
186194
this.updatedUrls = updatedUrls;
195+
this.noType = noType;
187196
}
188197

189198
public Boolean getFetchTweetsFromSearch() {
@@ -266,6 +275,10 @@ public Boolean getUpdatedUrls() {
266275
return updatedUrls;
267276
}
268277

278+
public Boolean getNoType() {
279+
return noType;
280+
}
281+
269282
@Override
270283
public boolean equals(Object o) {
271284
if (this == o) return true;
@@ -310,7 +323,9 @@ public boolean equals(Object o) {
310323
if (getLists != null ? !getLists.equals(taskInfo.getLists) : taskInfo.getLists != null) return false;
311324
if (fetchUserlistOwners != null ? !fetchUserlistOwners.equals(taskInfo.fetchUserlistOwners) : taskInfo.fetchUserlistOwners != null)
312325
return false;
313-
return startGarbageCollection != null ? startGarbageCollection.equals(taskInfo.startGarbageCollection) : taskInfo.startGarbageCollection == null;
326+
if (startGarbageCollection != null ? !startGarbageCollection.equals(taskInfo.startGarbageCollection) : taskInfo.startGarbageCollection != null)
327+
return false;
328+
return noType != null ? noType.equals(taskInfo.noType) : taskInfo.noType == null;
314329
}
315330

316331
@Override
@@ -335,6 +350,7 @@ public int hashCode() {
335350
result = 31 * result + (getLists != null ? getLists.hashCode() : 0);
336351
result = 31 * result + (fetchUserlistOwners != null ? fetchUserlistOwners.hashCode() : 0);
337352
result = 31 * result + (startGarbageCollection != null ? startGarbageCollection.hashCode() : 0);
353+
result = 31 * result + (noType != null ? noType.hashCode() : 0);
338354
return result;
339355
}
340356

@@ -361,6 +377,7 @@ public String toString() {
361377
", getLists=" + getLists +
362378
", fetchUserlistOwners=" + fetchUserlistOwners +
363379
", startGarbageCollection=" + startGarbageCollection +
380+
", noType=" + noType +
364381
'}';
365382
}
366383

src/main/java/org/woehlke/twitterwall/oodm/repositories/MentionRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public interface MentionRepository extends DomainRepository<Mention>,MentionRepo
1919

2020
List<Mention> findByIdTwitter(long idTwitter);
2121

22-
Mention findByScreenNameUnique(String screenNameUnique);
22+
@Query(name = "Mention.findByScreenNameUnique")
23+
Mention findByScreenNameUnique(@Param("screenNameUnique") String screenNameUnique);
2324

2425

2526
@Query(

src/test/java/org/woehlke/twitterwall/oodm/model/MentionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public void getUniqueIdTest() throws Exception {
3232
String name3 = "Java";
3333

3434
Mention mention1 = new Mention(createdBy,updatedBy,idTwitter1,screenName1,name1);
35-
String expectedUniqueId1 = idTwitter1.toString() +"_"+ screenNameUnique1.toString();
35+
String expectedUniqueId1 = idTwitter1.toString() +"_"+ screenNameUnique1;
3636
Assert.assertEquals(msg,expectedUniqueId1,mention1.getUniqueId());
3737

3838
Mention mention2 = new Mention(createdBy,updatedBy,screenName2);
39-
String expectedUniqueId2 = idTwitter2.toString() +"_"+ screenNameUnique2.toString();
39+
String expectedUniqueId2 = idTwitter2.toString() +"_"+ screenNameUnique2;
4040
Assert.assertEquals(msg,expectedUniqueId2,mention2.getUniqueId());
4141

4242
Mention mention3 = new Mention(createdBy,updatedBy,idTwitter3,screenName3,name3);

src/test/java/org/woehlke/twitterwall/oodm/service/MentionServiceTest.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,45 @@ public class MentionServiceTest implements DomainObjectMinimalServiceTest,Domain
3838
@Autowired
3939
private TestdataProperties testdataProperties;
4040

41+
@Commit
4142
@Test
4243
public void areDependenciesLoaded() throws Exception {
4344
Assert.assertNotNull(mentionService);
4445
Assert.assertNotNull(testdataProperties);
4546
Assert.assertNotNull(countedEntitiesService);
4647
}
4748

49+
@Commit
50+
@Test
51+
public void createTestData() throws Exception {
52+
String msg = "createTestData: ";
53+
CountedEntities countedEntities = countedEntitiesService.countAll();
54+
Task createdBy= taskService.create(msg, TaskType.NULL, TaskSendType.NO_MQ,countedEntities);
55+
Task updatedBy=null;
56+
57+
String screenName[] = {
58+
"port80guru",
59+
"ThomasWoehlke",
60+
"OracleDevs",
61+
"java"
62+
};
63+
long idTwitter[] = {242L, 1242L, 3242L, 4242L};
64+
String name[] = {
65+
"Natural Born Coder",
66+
"Thomas Woehlke",
67+
"Oracle Developer",
68+
"Java"
69+
};
70+
71+
for(int i=0;i<4;i++){
72+
Mention mentionTest = new Mention(createdBy,updatedBy,idTwitter[i], screenName[i], name[i]);
73+
mentionTest = mentionService.store(mentionTest,createdBy);
74+
Assert.assertNotNull(mentionTest);
75+
Assert.assertNotNull(mentionTest.getId());
76+
Assert.assertTrue(mentionTest.isValid());
77+
}
78+
}
79+
4880
@Commit
4981
@Test
5082
public void fetchTestData() throws Exception {
@@ -98,25 +130,28 @@ public void getAllWithoutPersistentUser() throws Exception {
98130
@Test
99131
public void findByIdTwitter() throws Exception {
100132
String msg = "findByIdTwitter: ";
133+
createTestData();
101134
int page=1;
102135
int size=20;
103136
Pageable pageRequest = new PageRequest(page,size);
104137
Page<Mention> myPage = mentionService.getAll(pageRequest);
105138
Assert.assertTrue(msg,myPage.getTotalElements()>0);
106139
for(Mention myMention:myPage.getContent()){
107-
long idTwitter = myMention.getIdTwitter();
108-
if(idTwitter > 0L) {
109-
Mention myFoundMention = mentionService.findByIdTwitter(idTwitter);
140+
long myIdTwitter = myMention.getIdTwitter();
141+
if(myIdTwitter > 0L) {
142+
Mention myFoundMention = mentionService.findByIdTwitter(myIdTwitter);
110143
Assert.assertNotNull(myFoundMention);
111-
Assert.assertEquals(msg, idTwitter, myFoundMention.getIdTwitter().longValue());
144+
Assert.assertEquals(msg, myIdTwitter, myFoundMention.getIdTwitter().longValue());
112145
}
113146
}
114147
}
115148

116149
@Commit
117150
@Test
151+
@Override
118152
public void findByScreenName() throws Exception {
119153
String msg = "findByScreenName: ";
154+
createTestData();
120155
int page=1;
121156
int size=1;
122157
Pageable pageRequest = new PageRequest(page,size);

0 commit comments

Comments
 (0)