|
6 | 6 |
|
7 | 7 | import org.junit.Test; |
8 | 8 |
|
| 9 | +import java.text.DateFormat; |
9 | 10 | import java.text.SimpleDateFormat; |
10 | 11 | import java.util.Calendar; |
11 | 12 | import java.util.Date; |
12 | 13 | import java.util.Locale; |
13 | 14 | import java.util.Map.Entry; |
14 | 15 |
|
15 | 16 | import ai.api.GsonFactory; |
| 17 | +import ai.api.util.ParametersConverter; |
16 | 18 |
|
17 | 19 | import static org.junit.Assert.assertEquals; |
18 | 20 | import static org.junit.Assert.assertFalse; |
|
21 | 23 |
|
22 | 24 | public class AIResponseTest { |
23 | 25 |
|
24 | | - public static final String TEST_JSON = "{\n" + |
25 | | - " \"id\": \"d872e7d9-d2ee-4ebd-aaff-655bfc8fbf33\",\n" + |
26 | | - " \"timestamp\": \"2015-03-18T09:54:36.216Z\",\n" + |
27 | | - " \"lang\":\"en\",\n" + |
28 | | - " \"result\": {\n" + |
29 | | - " \"resolvedQuery\": \"remind feed cat tomorrow 7 am\",\n" + |
30 | | - " \"action\": \"task_create\",\n" + |
31 | | - " \"parameters\": {\n" + |
32 | | - " \"date\": \"\",\n" + |
33 | | - " \"date-time\": \"2016-12-21T07:00:00"+(new SimpleDateFormat("Z", Locale.US).format(Calendar.getInstance().getTime()))+"\",\n" + |
34 | | - " \"time\": \"\",\n" + |
35 | | - " \"text\": \"feed cat\",\n" + |
36 | | - " \"priority\": \"\",\n" + |
37 | | - " \"remind\": \"remind\",\n" + |
38 | | - " \"complex_param\": {\"nested_key\": \"nested_value\"}\n" + |
39 | | - " },\n" + |
40 | | - " \"score\":0.875\n" + |
41 | | - " },\n" + |
42 | | - " \"status\": {\n" + |
43 | | - " \"code\": 200,\n" + |
44 | | - " \"errorType\": \"success\"\n" + |
45 | | - " },\n" + |
46 | | - " \"sessionId\":\"0123456789\"\n" + |
47 | | - "}"; |
| 26 | + public static final String TEST_JSON; |
48 | 27 |
|
49 | 28 | final static Gson gson = GsonFactory.getDefaultFactory().getGson(); |
50 | 29 |
|
| 30 | + static { |
| 31 | + Calendar testTime = Calendar.getInstance(Locale.US); |
| 32 | + testTime.set(2016, Calendar.DECEMBER, 21, 7, 0, 0); |
| 33 | + |
| 34 | + DateFormat DATE_TIME_FORMAT = |
| 35 | + new SimpleDateFormat(ParametersConverter.PROTOCOL_DATE_TIME_FORMAT, Locale.US); |
| 36 | + |
| 37 | + TEST_JSON = "{\n" + |
| 38 | + " \"id\": \"d872e7d9-d2ee-4ebd-aaff-655bfc8fbf33\",\n" + |
| 39 | + " \"timestamp\": \"2015-03-18T09:54:36.216Z\",\n" + |
| 40 | + " \"lang\":\"en\",\n" + |
| 41 | + " \"result\": {\n" + |
| 42 | + " \"resolvedQuery\": \"remind feed cat tomorrow 7 am\",\n" + |
| 43 | + " \"action\": \"task_create\",\n" + |
| 44 | + " \"parameters\": {\n" + |
| 45 | + " \"date\": \"\",\n" + |
| 46 | + " \"date-time\": \""+DATE_TIME_FORMAT.format(testTime.getTime())+"\",\n" + |
| 47 | + " \"time\": \"\",\n" + |
| 48 | + " \"text\": \"feed cat\",\n" + |
| 49 | + " \"priority\": \"\",\n" + |
| 50 | + " \"remind\": \"remind\",\n" + |
| 51 | + " \"complex_param\": {\"nested_key\": \"nested_value\"}\n" + |
| 52 | + " },\n" + |
| 53 | + " \"score\":0.875\n" + |
| 54 | + " },\n" + |
| 55 | + " \"status\": {\n" + |
| 56 | + " \"code\": 200,\n" + |
| 57 | + " \"errorType\": \"success\"\n" + |
| 58 | + " },\n" + |
| 59 | + " \"sessionId\":\"0123456789\"\n" + |
| 60 | + "}"; |
| 61 | + } |
| 62 | + |
51 | 63 | @Test |
52 | 64 | public void trimParametersTest() { |
53 | 65 | final AIResponse aiResponse = gson.fromJson(TEST_JSON, AIResponse.class); |
|
0 commit comments