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.JSONObjectMatcher;
20  import com.atlassian.jira.rest.client.domain.Comment;
21  import com.atlassian.jira.rest.client.domain.ServerInfo;
22  import com.atlassian.jira.rest.client.domain.input.LinkIssuesInput;
23  import com.atlassian.jira.rest.client.internal.ServerVersionConstants;
24  import com.atlassian.jira.rest.client.internal.json.ResourceUtil;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertThat;
28  
29  public class LinkIssuesInputGeneratorTest {
30  
31  	private final ServerInfo serverInfo = new ServerInfo(null, "1.2.3", ServerVersionConstants.BN_JIRA_4_3, null, null, null, null);
32  	private final LinkIssuesInputGenerator inputGenerator = new LinkIssuesInputGenerator(serverInfo);
33  
34  	@Test
35  	public void testGenerateWithoutComment() throws Exception {
36  		LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType");
37  		assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.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  		assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/simple.json")));
44  	}
45  
46  	@Test
47  	public void testGenerateWithRoleLevel() throws Exception {
48  		LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.createWithRoleLevel("simple comment", "Users"));
49  		assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/with-project-role.json")));
50  	}
51  
52  	@Test
53  	public void testGenerateWithGroupLevel() throws Exception {
54  		LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.createWithGroupLevel("simple comment", "jira-users"));
55  		assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/with-user-group.json")));
56  	}
57  
58  }