Skip to content

Commit

Permalink
Issue #1138 - MENTION_COMMENT_ADD added
Browse files Browse the repository at this point in the history
  • Loading branch information
nbartels committed Feb 27, 2021
1 parent 5ef4007 commit c2635a7
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 21 deletions.
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2010-2021 Mark Allen, Norbert Bartels.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.restfb.types.webhook;

import com.restfb.Facebook;
import com.restfb.types.webhook.base.BaseChangeValue;
import lombok.Getter;
import lombok.Setter;

abstract public class AbstractMentionAddValue extends BaseChangeValue {

@Getter
@Setter
@Facebook("post_id")
private String postId;

@Deprecated
@Getter
@Setter
@Facebook("sender_id")
private String senderId;

@Deprecated
@Getter
@Setter
@Facebook("sender_name")
private String senderName;
}
Expand Up @@ -151,6 +151,7 @@ enum ChangeValueEnumeration {
FEED_LIKE_ADD(FeedLikeValue.class), //
FEED_LIKE_REMOVE(FeedLikeValue.class), //
MENTION_POST_ADD(MentionPostAddValue.class), //
MENTION_COMMENT_ADD(MentionCommentAddValue.class), //
RATINGS_RATING_ADD(RatingsRatingValue.class), //
RATINGS_RATING_EDIT(RatingsRatingValue.class), //
RATINGS_RATING_REMOVE(RatingsRatingValue.class), //
Expand Down
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2010-2021 Mark Allen, Norbert Bartels.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.restfb.types.webhook;

import com.restfb.Facebook;
import lombok.Getter;
import lombok.Setter;

public class MentionCommentAddValue extends AbstractMentionAddValue {

@Getter
@Setter
@Facebook("comment_id")
private String commentId;

}
Expand Up @@ -21,26 +21,6 @@
*/
package com.restfb.types.webhook;

import com.restfb.Facebook;
import com.restfb.types.webhook.base.BaseChangeValue;
public class MentionPostAddValue extends AbstractMentionAddValue {

import lombok.Getter;
import lombok.Setter;

public class MentionPostAddValue extends BaseChangeValue {

@Getter
@Setter
@Facebook("post_id")
private String postId;

@Getter
@Setter
@Facebook("sender_id")
private String senderId;

@Getter
@Setter
@Facebook("sender_name")
private String senderName;
}
Expand Up @@ -33,10 +33,12 @@ abstract public class AbstractFeedPostValue extends BaseChangeValue {
@Facebook("post_id")
private String postId;

@Deprecated
@Setter
@Facebook("sender_id")
private String senderId;

@Deprecated
@Setter
@Facebook("sender_name")
private String senderName;
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/restfb/types/WebhookTest.java
Expand Up @@ -1250,6 +1250,31 @@ void mentionPostAdd() {
assertEquals(ChangeValue.Verb.ADD, mentionPostAddValue.getVerb());
}

@Test
void mentionPostAdd_realData() {
WebhookObject webhookObject = openJson("mention-post-add-real");
Change change = webhookObject.getEntryList().get(0).getChanges().get(0);
assertEquals(change.getValue().getClass(), MentionPostAddValue.class, "change value class");
MentionPostAddValue mentionPostAddValue = (MentionPostAddValue) change.getValue();
assertNotNull(mentionPostAddValue);
assertEquals("1234567890321_98722536423179", mentionPostAddValue.getPostId());
assertEquals("post", mentionPostAddValue.getItem());
assertEquals(ChangeValue.Verb.ADD, mentionPostAddValue.getVerb());
}

@Test
void mentionCommentAdd() {
WebhookObject webhookObject = openJson("mention-comment-add");
Change change = webhookObject.getEntryList().get(0).getChanges().get(0);
assertEquals(change.getValue().getClass(), MentionCommentAddValue.class, "change value class");
MentionCommentAddValue mentionCommentAddValue = (MentionCommentAddValue) change.getValue();
assertNotNull(mentionCommentAddValue);
assertEquals("1234567890321_7363534231324", mentionCommentAddValue.getPostId());
assertEquals("7363534231324_3754798971271444", mentionCommentAddValue.getCommentId());
assertEquals("comment", mentionCommentAddValue.getItem());
assertEquals(ChangeValue.Verb.ADD, mentionCommentAddValue.getVerb());
}

@Test
void feedTwoEntries() {
WebhookObject webhookObject = openJson("feed-two-entries-25");
Expand Down
22 changes: 22 additions & 0 deletions src/test/resources/json/webhooks/mention-comment-add.json
@@ -0,0 +1,22 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1614340868,
"changes": [
{
"value": {
"message": "Just a test message",
"post_id": "1234567890321_7363534231324",
"comment_id": "7363534231324_3754798971271444",
"created_time": 1614340862,
"item": "comment",
"verb": "add"
},
"field": "mention"
}
]
}
]
}
21 changes: 21 additions & 0 deletions src/test/resources/json/webhooks/mention-post-add-real.json
@@ -0,0 +1,21 @@
{
"object": "page",
"entry": [
{
"id": "1234567890321",
"time": 1614340567,
"changes": [
{
"value": {
"message": "A test post message",
"post_id": "1234567890321_98722536423179",
"created_time": 1614340562,
"item": "post",
"verb": "add"
},
"field": "mention"
}
]
}
]
}

0 comments on commit c2635a7

Please sign in to comment.