@Test public void testGetRelatedEntities() throws IOException { handler.addRequest("POST", "/qcbin/rest/domains/domain/projects/project/workspace/1000/ali/linked-items/commits", 200) .expectXmlBody(handler.getContent("devMotiveServiceTest_input.xml")) .content("devMotiveServiceTest_output.xml"); Commit commit1 = new Commit(new MyFileRevision(new MyRevisionNumber("1"), "commit1", new Date(0)), "authorName1", "authorEmail1", "committerName1", "committerEmail1"); Commit commit2 = new Commit(new MyFileRevision(new MyRevisionNumber("2"), "commit2", new Date(1000)), "authorName2", "authorEmail2", null, null); Commit commit3 = new Commit(new MyFileRevision(new MyRevisionNumber("3"), "commit3", new Date(1000000)), "authorName3", null, "committerName3", null); Commit commit4 = new Commit(new MyFileRevision(new MyRevisionNumber("4"), "commit4", new Date(1000000000)), "authorName4", "authorEmail4", "committerName4", "committerEmail4"); Map<Commit, List<EntityRef>> result = devMotiveService.getRelatedEntities(Arrays.asList(commit1, commit2, commit3, commit4)); Assert.assertNull(result.get(commit1)); Assert.assertTrue(result.get(commit2).isEmpty()); Assert.assertEquals(Collections.singletonList(new EntityRef("defect", 1)), result.get(commit3)); Assert.assertEquals(Collections.singletonList(new EntityRef("requirement", 2)), result.get(commit4)); }
public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) { HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>(); Integer workspaceId = workspaceConfiguration.getWorkspaceId(); if (workspaceId == null) { return noResponse(ret, commits); } Element commitsElem = new Element("commits"); for (Commit commit: commits) { Element commitElem = new Element("commit"); setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName()); setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName()); commitElem.setAttribute("revision", commit.getRevisionString()); commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate())); Element messageElem = new Element("message"); messageElem.setText(commit.getMessage()); commitElem.addContent(messageElem); commitsElem.addContent(commitElem); } String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem)); MyResultInfo result = new MyResultInfo(); int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId); if (code != HttpStatus.SC_OK) { return noResponse(ret, commits); } Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator(); for (Commit commit: commits) { CommitInfo next = commitInfoIterator.next(); LinkedList<EntityRef> list; if (next.getId() != null) { list = new LinkedList<EntityRef>(); for (int id: next.getDefects()) { list.add(new EntityRef("defect", id)); } for (int id: next.getRequirements()) { list.add(new EntityRef("requirement", id)); } } else { list = null; } ret.put(commit, list); } return ret; }
DevMotiveService { public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) { HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>(); Integer workspaceId = workspaceConfiguration.getWorkspaceId(); if (workspaceId == null) { return noResponse(ret, commits); } Element commitsElem = new Element("commits"); for (Commit commit: commits) { Element commitElem = new Element("commit"); setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName()); setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName()); commitElem.setAttribute("revision", commit.getRevisionString()); commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate())); Element messageElem = new Element("message"); messageElem.setText(commit.getMessage()); commitElem.addContent(messageElem); commitsElem.addContent(commitElem); } String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem)); MyResultInfo result = new MyResultInfo(); int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId); if (code != HttpStatus.SC_OK) { return noResponse(ret, commits); } Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator(); for (Commit commit: commits) { CommitInfo next = commitInfoIterator.next(); LinkedList<EntityRef> list; if (next.getId() != null) { list = new LinkedList<EntityRef>(); for (int id: next.getDefects()) { list.add(new EntityRef("defect", id)); } for (int id: next.getRequirements()) { list.add(new EntityRef("requirement", id)); } } else { list = null; } ret.put(commit, list); } return ret; } }
DevMotiveService { public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) { HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>(); Integer workspaceId = workspaceConfiguration.getWorkspaceId(); if (workspaceId == null) { return noResponse(ret, commits); } Element commitsElem = new Element("commits"); for (Commit commit: commits) { Element commitElem = new Element("commit"); setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName()); setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName()); commitElem.setAttribute("revision", commit.getRevisionString()); commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate())); Element messageElem = new Element("message"); messageElem.setText(commit.getMessage()); commitElem.addContent(messageElem); commitsElem.addContent(commitElem); } String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem)); MyResultInfo result = new MyResultInfo(); int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId); if (code != HttpStatus.SC_OK) { return noResponse(ret, commits); } Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator(); for (Commit commit: commits) { CommitInfo next = commitInfoIterator.next(); LinkedList<EntityRef> list; if (next.getId() != null) { list = new LinkedList<EntityRef>(); for (int id: next.getDefects()) { list.add(new EntityRef("defect", id)); } for (int id: next.getRequirements()) { list.add(new EntityRef("requirement", id)); } } else { list = null; } ret.put(commit, list); } return ret; } DevMotiveService(RestService restService, WorkspaceConfiguration workspaceConfiguration); }
DevMotiveService { public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) { HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>(); Integer workspaceId = workspaceConfiguration.getWorkspaceId(); if (workspaceId == null) { return noResponse(ret, commits); } Element commitsElem = new Element("commits"); for (Commit commit: commits) { Element commitElem = new Element("commit"); setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName()); setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName()); commitElem.setAttribute("revision", commit.getRevisionString()); commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate())); Element messageElem = new Element("message"); messageElem.setText(commit.getMessage()); commitElem.addContent(messageElem); commitsElem.addContent(commitElem); } String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem)); MyResultInfo result = new MyResultInfo(); int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId); if (code != HttpStatus.SC_OK) { return noResponse(ret, commits); } Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator(); for (Commit commit: commits) { CommitInfo next = commitInfoIterator.next(); LinkedList<EntityRef> list; if (next.getId() != null) { list = new LinkedList<EntityRef>(); for (int id: next.getDefects()) { list.add(new EntityRef("defect", id)); } for (int id: next.getRequirements()) { list.add(new EntityRef("requirement", id)); } } else { list = null; } ret.put(commit, list); } return ret; } DevMotiveService(RestService restService, WorkspaceConfiguration workspaceConfiguration); Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits); }
DevMotiveService { public Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits) { HashMap<Commit, List<EntityRef>> ret = new HashMap<Commit, List<EntityRef>>(); Integer workspaceId = workspaceConfiguration.getWorkspaceId(); if (workspaceId == null) { return noResponse(ret, commits); } Element commitsElem = new Element("commits"); for (Commit commit: commits) { Element commitElem = new Element("commit"); setAttribute(commitElem, "committer", commit.getCommitterEmail(), commit.getCommitterName()); setAttribute(commitElem, "author", commit.getAuthorEmail(), commit.getAuthorName()); commitElem.setAttribute("revision", commit.getRevisionString()); commitElem.setAttribute("date", CommentField.dateTimeFormat.format(commit.getDate())); Element messageElem = new Element("message"); messageElem.setText(commit.getMessage()); commitElem.addContent(messageElem); commitsElem.addContent(commitElem); } String commitRequest = XMLOutputterFactory.getXMLOutputter().outputString(new Document(commitsElem)); MyResultInfo result = new MyResultInfo(); int code = restService.post(commitRequest, result, "workspace/{0}/ali/linked-items/commits", workspaceId); if (code != HttpStatus.SC_OK) { return noResponse(ret, commits); } Iterator<CommitInfo> commitInfoIterator = CommitInfoList.create(result.getBodyAsStream()).iterator(); for (Commit commit: commits) { CommitInfo next = commitInfoIterator.next(); LinkedList<EntityRef> list; if (next.getId() != null) { list = new LinkedList<EntityRef>(); for (int id: next.getDefects()) { list.add(new EntityRef("defect", id)); } for (int id: next.getRequirements()) { list.add(new EntityRef("requirement", id)); } } else { list = null; } ret.put(commit, list); } return ret; } DevMotiveService(RestService restService, WorkspaceConfiguration workspaceConfiguration); Map<Commit, List<EntityRef>> getRelatedEntities(List<Commit> commits);  }