use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldReply.
@Test
public void shouldReply() throws URISyntaxException {
String newComment = "haha ";
when(service.reply(eq("space"), eq("name"), eq("1"), eq("1"), argThat(t -> t.getComment().equals(newComment)))).thenReturn("new");
byte[] pullRequestCommentJson = ("{\"comment\" : \"" + newComment + "\"}").getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1/replies").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
verify(service).reply(eq("space"), eq("name"), eq("1"), any(), any());
assertEquals(create("https://scm-manager.org/scm/api/v2/pull-requests/space/name/1/comments/1/replies/new"), response.getOutputHeaders().getFirst("Location"));
assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldUpdateReply.
@Test
public void shouldUpdateReply() throws URISyntaxException {
String newComment = "haha";
byte[] pullRequestCommentJson = ("{\"comment\" : \"" + newComment + "\"}").getBytes();
MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1/replies/x").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus());
verify(service).modifyReply(eq("space"), eq("name"), eq("1"), eq("x"), argThat((Reply r) -> r.getComment().equals(newComment)));
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class CommentResourceTest method shouldNotReplyIfPullRequestHasChanged.
@Test
public void shouldNotReplyIfPullRequestHasChanged() throws URISyntaxException, UnsupportedEncodingException {
String newComment = "haha ";
when(service.reply(eq("space"), eq("name"), eq("1"), eq("1"), argThat(t -> t.getComment().equals(newComment)))).thenReturn("new");
byte[] pullRequestCommentJson = ("{\"comment\" : \"" + newComment + "\"}").getBytes();
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments/1/replies?sourceRevision=wrong").content(pullRequestCommentJson).contentType(MediaType.APPLICATION_JSON);
dispatcher.invoke(request, response);
verify(service, never()).reply(any(), any(), any(), any(), any());
Assertions.assertThat(response.getContentAsString()).contains("modified concurrently");
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class MergeResourceTest method shouldEmergencyMergeWithFastForward.
@Test
void shouldEmergencyMergeWithFastForward() throws URISyntaxException, IOException {
byte[] mergeCommitJson = loadJson("com/cloudogu/scm/review/mergeCommit.json");
MockHttpRequest request = createHttpPostRequest(MERGE_URL + "/emergency" + "?strategy=FAST_FORWARD_IF_POSSIBLE", mergeCommitJson);
dispatcher.invoke(request, response);
verify(mergeService).merge(eq(new NamespaceAndName("space", "name")), eq("1"), any(), eq(FAST_FORWARD_IF_POSSIBLE), anyBoolean());
assertThat(response.getStatus()).isEqualTo(204);
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class MergeResourceTest method shouldGetRebaseMergeStrategyInfo.
@Test
void shouldGetRebaseMergeStrategyInfo() throws URISyntaxException, UnsupportedEncodingException {
CommitDefaults commitDefaults = new CommitDefaults("happy days", DisplayUser.from(new User("Arthur Dent")));
when(mergeService.createCommitDefaults(any(), any(), eq(REBASE))).thenReturn(commitDefaults);
when(mergeService.isCommitMessageDisabled(REBASE)).thenReturn(true);
when(mergeService.createMergeCommitMessageHint(REBASE)).thenReturn(null);
MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=REBASE");
MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("happy days").contains("true").doesNotContain("commitMessageHint");
}
Aggregations