Skip to content

Commit d6d3b5e

Browse files
committed
Merge branch 'matthewtckr-UnknownEventType'
2 parents d880569 + 005219d commit d6d3b5e

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

src/main/java/org/zendesk/client/v2/model/events/Event.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
import java.io.Serializable;
44

5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
56
import com.fasterxml.jackson.annotation.JsonSubTypes;
67
import com.fasterxml.jackson.annotation.JsonTypeInfo;
78

89
/**
910
* @author stephenc
1011
* @since 05/04/2013 11:53
1112
*/
12-
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
13+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type",
14+
visible = true, defaultImpl = UnknownEvent.class)
1315
@JsonSubTypes({
1416
@JsonSubTypes.Type(value = CommentEvent.class, name = "Comment"),
1517
@JsonSubTypes.Type(value = VoiceCommentEvent.class, name = "VoiceComment"),
@@ -31,7 +33,7 @@
3133
@JsonSubTypes.Type(value = OrganizationActivityEvent.class, name = "OrganizationActivity"),
3234
@JsonSubTypes.Type(value = AgentMacroReferenceEvent.class, name = "AgentMacroReference")
3335
})
34-
36+
@JsonIgnoreProperties(ignoreUnknown = true)
3537
public abstract class Event implements Serializable {
3638

3739
private static final long serialVersionUID = 1L;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.zendesk.client.v2.model.events;
2+
3+
public class UnknownEvent extends Event {
4+
5+
private static final long serialVersionUID = 1L;
6+
7+
private String type;
8+
9+
public String getType() {
10+
return type;
11+
}
12+
13+
public void setType(String type) {
14+
this.type = type;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
final StringBuilder sb = new StringBuilder();
20+
sb.append("UnknownEvent");
21+
sb.append("{id=").append(getId());
22+
sb.append(", type=\"").append(getType()).append("\"");
23+
sb.append('}');
24+
return sb.toString();
25+
}
26+
}

src/test/java/org/zendesk/client/v2/model/EventTest.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
56

67
import org.junit.Test;
78
import org.zendesk.client.v2.model.events.AgentMacroReferenceEvent;
89
import org.zendesk.client.v2.model.events.AttachmentRedactionEvent;
910
import org.zendesk.client.v2.model.events.CommentRedactionEvent;
1011
import org.zendesk.client.v2.model.events.Event;
1112
import org.zendesk.client.v2.model.events.OrganizationActivityEvent;
13+
import org.zendesk.client.v2.model.events.UnknownEvent;
1214

1315
import com.fasterxml.jackson.databind.ObjectMapper;
1416

@@ -62,16 +64,26 @@ public void testCommentRedactionEvent() {
6264
assertEquals( "CommentRedactionEvent{commentId=18974155255}", ev.toString() );
6365
}
6466

65-
@Test
66-
public void testAgentMacroReferenceEvent() {
67-
String json = "{ \"id\": 789, \"type\": \"AgentMacroReference\", \"via\": { \"channel\": \"web\", \"source\": {"
68-
+ "\"from\": {}, \"to\": {}, \"rel\": null } }, \"macro_title\": \"TheMacroTitle\", \"macro_id\": \"123\" }";
69-
Event ev = parseJson( json.getBytes() );
70-
assertNotNull(ev);
71-
assertEquals(AgentMacroReferenceEvent.class, ev.getClass());
72-
assertEquals(new Long(789L), ev.getId());
73-
assertEquals(new Long(123L), ((AgentMacroReferenceEvent) ev).getMacroId());
74-
assertEquals("TheMacroTitle", ((AgentMacroReferenceEvent) ev).getMacroTitle());
75-
assertNotNull(((AgentMacroReferenceEvent) ev).getVia());
76-
}
67+
@Test
68+
public void testAgentMacroReferenceEvent() {
69+
String json = "{ \"id\": 789, \"type\": \"AgentMacroReference\", \"via\": { \"channel\": \"web\", \"source\": {"
70+
+ "\"from\": {}, \"to\": {}, \"rel\": null } }, \"macro_title\": \"TheMacroTitle\", \"macro_id\": \"123\" }";
71+
Event ev = parseJson( json.getBytes() );
72+
assertNotNull(ev);
73+
assertEquals(AgentMacroReferenceEvent.class, ev.getClass());
74+
assertEquals(new Long(789L), ev.getId());
75+
assertEquals(new Long(123L), ((AgentMacroReferenceEvent) ev).getMacroId());
76+
assertEquals("TheMacroTitle", ((AgentMacroReferenceEvent) ev).getMacroTitle());
77+
assertNotNull(((AgentMacroReferenceEvent) ev).getVia());
78+
}
79+
80+
@Test
81+
public void testUnknownEvent() {
82+
String json = "{ \"id\": 123, \"type\": \"NotARealEventType\" }";
83+
Event ev = parseJson(json.getBytes());
84+
assertNotNull(ev);
85+
assertEquals(UnknownEvent.class, ev.getClass());
86+
assertEquals("NotARealEventType", ((UnknownEvent) ev).getType());
87+
assertTrue(ev.toString().contains("NotARealEventType"));
88+
}
7789
}

0 commit comments

Comments
 (0)