Skip to content

Commit 8e8e87e

Browse files
committed
Add answer to TROPO JSON helper library with support for RPID parameters - WebAPI Java
1 parent 88cb754 commit 8e8e87e

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

src/main/java/com/voxeo/tropo/Tropo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.apache.http.client.HttpClient;
3131

32+
import com.voxeo.tropo.actions.AnswerAction;
3233
import com.voxeo.tropo.actions.ArrayBackedJsonAction;
3334
import com.voxeo.tropo.actions.AskAction;
3435
import com.voxeo.tropo.actions.CallAction;
@@ -66,6 +67,7 @@ public class Tropo extends ArrayBackedJsonAction {
6667
private ActionSupportHandler<CallAction> callActionSupportHandler = new ActionSupportHandler<CallAction>(CallAction.class);
6768
private ActionSupportHandler<MessageAction> messageActionSupportHandler = new ActionSupportHandler<MessageAction>(MessageAction.class);
6869
private ActionSupportHandler<WaitAction> waitActionSupportHandler = new ActionSupportHandler<WaitAction>(WaitAction.class);
70+
private ActionSupportHandler<AnswerAction> answerActionSupportHandler = new ActionSupportHandler<AnswerAction>(AnswerAction.class);
6971

7072
public Tropo() {
7173

@@ -384,6 +386,11 @@ public void generalLogSecurity(LogSecurityState value) {
384386
addObject("tropo", "generalLogSecurity", value.toString());
385387
}
386388

389+
public AnswerAction answer(Key... keys) {
390+
391+
return answerActionSupportHandler.build(this, "tropo", keys);
392+
}
393+
387394
public String getBaseUrl() {
388395
return baseUrl;
389396
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.voxeo.tropo.actions;
2+
3+
import com.voxeo.tropo.Key;
4+
import com.voxeo.tropo.annotations.ValidKeys;
5+
6+
import support.HeadersSupportHandler;
7+
8+
@ValidKeys(keys = {"headers"})
9+
public class AnswerAction extends JsonAction {
10+
11+
private HeadersSupportHandler headersSupportHandler = new HeadersSupportHandler();
12+
13+
public AnswerAction() {
14+
15+
super();
16+
setName("answer");
17+
}
18+
19+
public AnswerAction(Key... keys) {
20+
21+
super(keys);
22+
setName("answer");
23+
}
24+
25+
public HeadersAction headers(String[]... keys) {
26+
27+
return headersSupportHandler.headers(this, keys);
28+
}
29+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.voxeo.tropo;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
5+
6+
import java.util.LinkedHashMap;
7+
import java.util.Map;
8+
9+
import org.junit.Test;
10+
11+
import com.voxeo.tropo.actions.AnswerAction;
12+
13+
public class AnswerActionTest {
14+
15+
@Test
16+
public void testAnswer() {
17+
18+
Tropo tropo = new Tropo();
19+
tropo.answer();
20+
tropo.say("Hello, you were the first to answer.", "say");
21+
22+
assertEquals(tropo.text(),
23+
"{\"tropo\":[{\"answer\":{}},{\"say\":[{\"value\":\"Hello, you were the first to answer.\",\"name\":\"say\"}]}]}");
24+
}
25+
26+
@Test
27+
public void testAnswerFailsWithInvalidElement() {
28+
29+
Tropo tropo = new Tropo();
30+
try {
31+
tropo.answer(Key.NAME("foo"));
32+
fail("Expected exception in test");
33+
}
34+
catch (TropoException te) {
35+
assertEquals(te.getMessage(), "Invalid key 'name' for action");
36+
}
37+
}
38+
39+
@Test
40+
public void testAnswerWithHeadersTraditional() {
41+
42+
Tropo tropo = new Tropo();
43+
AnswerAction answer = tropo.answer();
44+
answer.headers(new String[] {"P-Header", "value goes here"}, new String[] {"Remote-Party-ID",
45+
"\"John Doe\"<sip:jdoe@foo.com>;party=calling;id-type=subscriber;privacy=full;screen=yes"});
46+
tropo.say("Hello, you were the first to answer.", "say");
47+
48+
assertEquals(tropo.text(),
49+
"{\"tropo\":[{\"answer\":{\"headers\":{\"P-Header\":\"value goes here\",\"Remote-Party-ID\":\"\\\"John Doe\\\"<sip:jdoe@foo.com>;party=calling;id-type=subscriber;privacy=full;screen=yes\"}}},{\"say\":[{\"value\":\"Hello, you were the first to answer.\",\"name\":\"say\"}]}]}");
50+
}
51+
52+
@Test
53+
public void testNewAnswerWithHeadersTraditional() {
54+
55+
Tropo tropo = new Tropo();
56+
Map<String, String> map = new LinkedHashMap<String, String>();
57+
map.put("P-Header", "value goes here");
58+
map.put("Remote-Party-ID",
59+
"\"John Doe\"<sip:jdoe@foo.com>;party=calling;id-type=subscriber;privacy=full;screen=yes");
60+
tropo.answer(Key.HEADERS(map));
61+
tropo.say("Hello, you were the first to answer.", "say");
62+
63+
assertEquals(tropo.text(),
64+
"{\"tropo\":[{\"answer\":{\"headers\":{\"P-Header\":\"value goes here\",\"Remote-Party-ID\":\"\\\"John Doe\\\"<sip:jdoe@foo.com>;party=calling;id-type=subscriber;privacy=full;screen=yes\"}}},{\"say\":[{\"value\":\"Hello, you were the first to answer.\",\"name\":\"say\"}]}]}");
65+
}
66+
67+
}

0 commit comments

Comments
 (0)