View Javadoc

1   package it;
2   
3   import com.atlassian.jira.rest.client.IntegrationTestUtil;
4   import com.atlassian.jira.rest.client.api.IssueRestClient;
5   import com.atlassian.jira.rest.client.api.domain.BasicVotes;
6   import com.atlassian.jira.rest.client.api.domain.BasicWatchers;
7   import com.atlassian.jira.rest.client.api.domain.ChangelogGroup;
8   import com.atlassian.jira.rest.client.api.domain.Comment;
9   import com.atlassian.jira.rest.client.api.domain.Issue;
10  import com.atlassian.jira.rest.client.api.domain.Resolution;
11  import com.atlassian.jira.rest.client.internal.json.TestConstants;
12  import com.google.common.collect.ImmutableList;
13  import com.google.common.collect.Iterables;
14  import com.google.common.collect.Lists;
15  import org.codehaus.jettison.json.JSONException;
16  import org.junit.Before;
17  import org.junit.Test;
18  import samples.Example1;
19  
20  import java.io.IOException;
21  import java.net.URISyntaxException;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  
26  // Ignore "May produce NPE" warnings, as we know what we are doing in tests
27  @SuppressWarnings("ConstantConditions")
28  public class ExamplesTest extends AbstractAsynchronousRestClientTest {
29  
30      private static boolean alreadyRestored;
31  
32      @Before
33      public void setup() {
34          if (!alreadyRestored) {
35              IntegrationTestUtil.restoreAppropriateJiraData(TestConstants.DEFAULT_JIRA_DUMP_FILE, administration);
36              alreadyRestored = true;
37          }
38      }
39  
40      @Test
41      public void testExample1() throws URISyntaxException, JSONException, IOException {
42          // -- run the example
43          Example1.main(new String[]{environmentData.getBaseUrl().toString(), "-q"});
44  
45          // -- check state after example
46          final Issue issue = client.getIssueClient().getIssue("TST-7", ImmutableList.copyOf(Lists.newArrayList(IssueRestClient
47                  .Expandos.values()))).claim();
48  
49          // votes
50          final BasicVotes votes = issue.getVotes();
51          assertNotNull(votes);
52          assertEquals(1, votes.getVotes());
53          assertEquals(true, votes.hasVoted());
54  
55          // watchers
56          final BasicWatchers watchers = issue.getWatchers();
57          assertNotNull(watchers);
58          assertEquals(1, watchers.getNumWatchers());
59  
60          // resolution
61          final Resolution resolution = issue.getResolution();
62          assertNotNull(resolution);
63          assertEquals("Incomplete", resolution.getName());
64  
65          if (isJira5xOrNewer()) {
66              // changelog
67              final Iterable<ChangelogGroup> changelog = issue.getChangelog();
68              assertEquals(2, Iterables.size(changelog));
69          }
70  
71          // comments
72          final Iterable<Comment> comments = issue.getComments();
73          assertNotNull(comments);
74          assertEquals(1, Iterables.size(comments));
75          final Comment comment = comments.iterator().next();
76          assertEquals("My comment", comment.getBody());
77          assertEquals("Administrator", comment.getAuthor().getDisplayName());
78      }
79  
80  }