|
| 1 | +package com.asana.resources; |
| 2 | + |
| 3 | +import com.asana.AsanaTest; |
| 4 | +import com.asana.models.Attachment; |
| 5 | +import com.asana.models.Task; |
| 6 | + |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.Arrays; |
| 12 | + |
| 13 | +import static org.junit.Assert.assertEquals; |
| 14 | + |
| 15 | +public class TasksTest extends AsanaTest { |
| 16 | + @Test |
| 17 | + public void testGetTaskWithAttachments() throws IOException { |
| 18 | + String res = "{ \"data\": {\"gid\": 1, \"name\": \"test task\", \"attachments\": " + |
| 19 | + "[{\"gid\": 2, \"name\": \"test attachment\"}] } }"; |
| 20 | + dispatcher |
| 21 | + .registerResponse("GET", "http://app/tasks/1?opt_fields=gid,name,attachments.name") |
| 22 | + .code(200) |
| 23 | + .content(res); |
| 24 | + |
| 25 | + Task task = client.tasks |
| 26 | + .findById("1") |
| 27 | + .option("fields", Arrays.asList("gid", "name", "attachments.name")) |
| 28 | + .execute(); |
| 29 | + |
| 30 | + assertEquals("1", task.gid); |
| 31 | + assertEquals("test task", task.name); |
| 32 | + assertEquals(1, task.attachments.size()); |
| 33 | + Attachment attachment = new ArrayList<>(task.attachments).get(0); |
| 34 | + assertEquals("2", attachment.gid); |
| 35 | + assertEquals("test attachment", attachment.name); |
| 36 | + } |
| 37 | +} |
0 commit comments