|
| 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