Search in sources :

Example 16 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldReturnBranchesNotDifferResultIfNoChangesetsInDiff.

@Test
@SubjectAware(username = "dent")
public void shouldReturnBranchesNotDifferResultIfNoChangesetsInDiff() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    mockLogCommandForPullRequestCheck(emptyList());
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/check?source=feature&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"BRANCHES_NOT_DIFFER\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=feature&target=master\"}}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 17 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method mockPrincipal.

private void mockPrincipal() {
    ThreadContext.bind(subject);
    PrincipalCollection principals = mock(PrincipalCollection.class);
    when(subject.getPrincipals()).thenReturn(principals);
    User user1 = new User();
    user1.setName("user1");
    user1.setDisplayName("User 1");
    when(principals.oneByType(User.class)).thenReturn(user1);
}
Also used : DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection)

Example 18 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldNotReturnAnySubscriptionLinkOnMissingUserMail.

@Test
public void shouldNotReturnAnySubscriptionLinkOnMissingUserMail() throws URISyntaxException, IOException {
    // the PR has no subscriber
    mockLoggedInUser(new User("user1", "User 1", null));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/subscription");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).isNullOrEmpty();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) Test(org.junit.Test)

Example 19 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldGetTheSubscriptionLink.

@Test
public void shouldGetTheSubscriptionLink() throws URISyntaxException, IOException {
    // the PR has no subscriber
    PullRequest pullRequest = createPullRequest();
    when(store.get("1")).thenReturn(pullRequest);
    mockLoggedInUser(new User("user1", "User 1", "email@d.de"));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/subscription");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    assertThat(jsonNode.path("_links").get("subscribe")).isNotNull();
    assertThat(jsonNode.path("_links").get("unsubscribe")).isNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 20 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldGetTheUnsubscribeLink.

@Test
public void shouldGetTheUnsubscribeLink() throws URISyntaxException, IOException {
    PullRequest pullRequest = createPullRequest();
    pullRequest.setSubscriber(singleton("user1"));
    when(store.get("1")).thenReturn(pullRequest);
    mockLoggedInUser(new User("user1", "User 1", "email@d.de"));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/subscription");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
    assertThat(jsonNode.path("_links").get("subscribe")).isNull();
    assertThat(jsonNode.path("_links").get("unsubscribe")).isNotNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

User (sonia.scm.user.User)27 DisplayUser (sonia.scm.user.DisplayUser)23 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)15 Test (org.junit.Test)11 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)9 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)8 Test (org.junit.jupiter.api.Test)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Changeset (sonia.scm.repository.Changeset)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)3 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)3 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)3 DefaultPullRequestService (com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService)2 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Person (sonia.scm.repository.Person)2