View Javadoc

1   /*
2    * Copyright (C) 2011 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.internal.json.gen;
18  
19  import com.atlassian.jira.rest.client.api.domain.Comment;
20  import com.atlassian.jira.rest.client.api.domain.ServerInfo;
21  import com.atlassian.jira.rest.client.api.domain.input.LinkIssuesInput;
22  import com.atlassian.jira.rest.client.internal.ServerVersionConstants;
23  import com.atlassian.jira.rest.client.internal.json.ResourceUtil;
24  import com.atlassian.jira.rest.client.test.matchers.JSONObjectMatcher;
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  public class LinkIssuesInputGeneratorTest {
29  
30      private final ServerInfo serverInfo = new ServerInfo(null, "1.2.3", ServerVersionConstants.BN_JIRA_4_3, null, null, null, null);
31      private final LinkIssuesInputGenerator inputGenerator = new LinkIssuesInputGenerator(serverInfo);
32  
33      @Test
34      public void testGenerateWithoutComment() throws Exception {
35          LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType");
36          Assert.assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil
37                  .getJsonObjectFromResource("/json/issueLinkInput/no-comment.json")));
38      }
39  
40      @Test
41      public void testGenerate() throws Exception {
42          LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.valueOf("simple comment"));
43          Assert.assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil
44                  .getJsonObjectFromResource("/json/issueLinkInput/simple.json")));
45      }
46  
47      @Test
48      public void testGenerateWithRoleLevel() throws Exception {
49          LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment
50                  .createWithRoleLevel("simple comment", "Users"));
51          Assert.assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil
52                  .getJsonObjectFromResource("/json/issueLinkInput/with-project-role.json")));
53      }
54  
55      @Test
56      public void testGenerateWithGroupLevel() throws Exception {
57          LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment
58                  .createWithGroupLevel("simple comment", "jira-users"));
59          Assert.assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil
60                  .getJsonObjectFromResource("/json/issueLinkInput/with-user-group.json")));
61      }
62  
63  }