Search in sources :

Example 16 with MockHttpRequest

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());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequestRootResource(com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource) Reply(com.cloudogu.scm.review.comment.service.Reply) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) MediaType(javax.ws.rs.core.MediaType) Comment(com.cloudogu.scm.review.comment.service.Comment) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Assertions(org.assertj.core.api.Assertions) UriBuilder(javax.ws.rs.core.UriBuilder) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Before(org.junit.Before) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) PullRequestResource(com.cloudogu.scm.review.pullrequest.api.PullRequestResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) ChannelRegistry(sonia.scm.sse.ChannelRegistry) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Mockito.never(org.mockito.Mockito.never) URI.create(java.net.URI.create) CommentService(com.cloudogu.scm.review.comment.service.CommentService) Providers(com.google.inject.util.Providers) UriInfo(javax.ws.rs.core.UriInfo) Location(com.cloudogu.scm.review.comment.service.Location) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test)

Example 17 with MockHttpRequest

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)));
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Reply(com.cloudogu.scm.review.comment.service.Reply) Test(org.junit.Test)

Example 18 with MockHttpRequest

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");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RestDispatcher(sonia.scm.web.RestDispatcher) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Repository(sonia.scm.repository.Repository) PullRequestRootResource(com.cloudogu.scm.review.pullrequest.api.PullRequestRootResource) Reply(com.cloudogu.scm.review.comment.service.Reply) PullRequestMapperImpl(com.cloudogu.scm.review.pullrequest.dto.PullRequestMapperImpl) MediaType(javax.ws.rs.core.MediaType) Comment(com.cloudogu.scm.review.comment.service.Comment) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) Assertions(org.assertj.core.api.Assertions) UriBuilder(javax.ws.rs.core.UriBuilder) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Before(org.junit.Before) RepositoryResolver(com.cloudogu.scm.review.RepositoryResolver) PullRequestResource(com.cloudogu.scm.review.pullrequest.api.PullRequestResource) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) ChannelRegistry(sonia.scm.sse.ChannelRegistry) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Mockito.never(org.mockito.Mockito.never) URI.create(java.net.URI.create) CommentService(com.cloudogu.scm.review.comment.service.CommentService) Providers(com.google.inject.util.Providers) UriInfo(javax.ws.rs.core.UriInfo) Location(com.cloudogu.scm.review.comment.service.Location) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Comment.createComment(com.cloudogu.scm.review.comment.service.Comment.createComment) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test)

Example 19 with MockHttpRequest

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);
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) NamespaceAndName(sonia.scm.repository.NamespaceAndName) Test(org.junit.jupiter.api.Test)

Example 20 with MockHttpRequest

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");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)108 Test (org.junit.Test)64 SubjectAware (com.github.sdorra.shiro.SubjectAware)46 Test (org.junit.jupiter.api.Test)41 JsonNode (com.fasterxml.jackson.databind.JsonNode)29 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)24 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)17 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)16 DisplayUser (sonia.scm.user.DisplayUser)16 User (sonia.scm.user.User)16 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)14 NamespaceAndName (sonia.scm.repository.NamespaceAndName)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Repository (sonia.scm.repository.Repository)9 Comment (com.cloudogu.scm.review.comment.service.Comment)8 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 URISyntaxException (java.net.URISyntaxException)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)8