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", ""))));
}
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();
}
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\"}}");
}
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\"]");
}
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));
}
Aggregations