LinkIssuesInputGenerator implements JsonGenerator<LinkIssuesInput> { @Override public JSONObject generate(LinkIssuesInput linkIssuesInput) throws JSONException { JSONObject res = new JSONObject(); final int buildNumber = serverInfo.getBuildNumber(); if (buildNumber >= ServerVersionConstants.BN_JIRA_5) { res.put("type", new JSONObject().put("name", linkIssuesInput.getLinkType())); res.put("inwardIssue", new JSONObject().put("key", linkIssuesInput.getFromIssueKey())); res.put("outwardIssue", new JSONObject().put("key", linkIssuesInput.getToIssueKey())); } else { res.put("linkType", linkIssuesInput.getLinkType()); res.put("fromIssueKey", linkIssuesInput.getFromIssueKey()); res.put("toIssueKey", linkIssuesInput.getToIssueKey()); } if (linkIssuesInput.getComment() != null) { res.put("comment", new CommentJsonGenerator(serverInfo).generate(linkIssuesInput.getComment())); } return res; } LinkIssuesInputGenerator(ServerInfo serverInfo); @Override JSONObject generate(LinkIssuesInput linkIssuesInput);  }
@Test public void testGenerateWithoutComment() throws Exception { LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType"); assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/no-comment.json"))); }
@Test public void testGenerate() throws Exception { LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.valueOf("simple comment")); assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/simple.json"))); }
@Test public void testGenerateWithRoleLevel() throws Exception { LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.createWithRoleLevel("simple comment", "Users")); assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/with-project-role.json"))); }
@Test public void testGenerateWithGroupLevel() throws Exception { LinkIssuesInput input1 = new LinkIssuesInput("TST-1", "TST-2", "MyLinkType", Comment.createWithGroupLevel("simple comment", "jira-users")); assertThat(inputGenerator.generate(input1), JSONObjectMatcher.isEqual(ResourceUtil.getJsonObjectFromResource("/json/issueLinkInput/with-user-group.json"))); }