Search in sources :

Example 6 with User

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

the class PullRequestRootResourceTest method init.

@Before
public void init() {
    when(repository.getId()).thenReturn(REPOSITORY_ID);
    when(repository.getName()).thenReturn(REPOSITORY_NAME);
    when(repository.getNamespace()).thenReturn(REPOSITORY_NAMESPACE);
    when(repository.getNamespaceAndName()).thenReturn(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME));
    when(repositoryResolver.resolve(any())).thenReturn(repository);
    when(pullRequestService.getRepository(repository.getNamespace(), repository.getName())).thenReturn(repository);
    DefaultPullRequestService service = new DefaultPullRequestService(repositoryResolver, branchResolver, storeFactory, eventBus, repositoryServiceFactory);
    pullRequestRootResource = new PullRequestRootResource(mapper, service, repositoryServiceFactory, Providers.of(new PullRequestResource(mapper, service, null, null, channelRegistry)));
    when(storeFactory.create(null)).thenReturn(store);
    when(storeFactory.create(any())).thenReturn(store);
    when(store.add(pullRequestStoreCaptor.capture())).thenReturn("1");
    when(branchLinkProvider.get(any(NamespaceAndName.class), anyString())).thenReturn("");
    dispatcher = new RestDispatcher();
    dispatcher.addSingletonResource(pullRequestRootResource);
    lenient().when(repositoryServiceFactory.create(any(Repository.class))).thenReturn(repositoryService);
    lenient().when(userDisplayManager.get("reviewer")).thenReturn(Optional.of(DisplayUser.from(new User("reviewer", "reviewer", ""))));
}
Also used : Repository(sonia.scm.repository.Repository) DefaultPullRequestService(com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) NamespaceAndName(sonia.scm.repository.NamespaceAndName) RestDispatcher(sonia.scm.web.RestDispatcher) Before(org.junit.Before)

Example 7 with User

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

the class PullRequestRootResourceTest method shouldGetTheApproveAndSubscriptionLink.

@Test
public void shouldGetTheApproveAndSubscriptionLink() throws URISyntaxException, IOException {
    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");
    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("approve")).isNotNull();
    assertThat(jsonNode.path("_links").get("subscription")).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)

Example 8 with User

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

the class PullRequestRootResourceTest method shouldReturnPullRequestIsValidResult.

@Test
@SubjectAware(username = "dent")
public void shouldReturnPullRequestIsValidResult() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    mockLogCommandForPullRequestCheck(ImmutableList.of(new Changeset()));
    PullRequest pullRequest = createPullRequest();
    when(store.getAll()).thenReturn(ImmutableList.of(pullRequest));
    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\":\"PR_VALID\"");
    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) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 9 with User

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

the class PullRequestRootResourceTest method shouldGetMarkedAsReviewedPaths.

@Test
@SubjectAware(username = "dent")
public void shouldGetMarkedAsReviewedPaths() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    PullRequest pullRequest = createPullRequest();
    pullRequest.setAuthor("slarti");
    pullRequest.setReviewMarks(ImmutableSet.of(new ReviewMark("/some/file", "dent"), new ReviewMark("/some/other/file", "trillian")));
    when(store.get("1")).thenReturn(pullRequest);
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"markedAsReviewed\":[\"/some/file\"]");
}
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) ReviewMark(com.cloudogu.scm.review.pullrequest.service.ReviewMark) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 10 with User

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

the class PreventMergeFromAuthorGuardTest method initSubject.

@BeforeEach
void initSubject() {
    ThreadContext.bind(subject);
    lenient().when(subject.getPrincipals().oneByType(User.class)).thenReturn(new User(CURRENT_USER));
}
Also used : User(sonia.scm.user.User) BeforeEach(org.junit.jupiter.api.BeforeEach)

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