use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldGetMarkAsReviewedLink.
@Test
@SubjectAware(username = "dent")
public void shouldGetMarkAsReviewedLink() throws URISyntaxException, IOException {
PullRequest pullRequest = createPullRequest();
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);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readValue(response.getContentAsString(), JsonNode.class);
assertThat(jsonNode.path("_links").get("reviewMark")).isNotNull();
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldSetPullRequestToStatusRejected.
@Test
public void shouldSetPullRequestToStatusRejected() throws URISyntaxException {
Subject subject = mock(Subject.class, RETURNS_DEEP_STUBS);
shiroRule.setSubject(subject);
User currentUser = new User("currentUser");
when(subject.getPrincipals().oneByType(User.class)).thenReturn(currentUser);
when(store.get("1")).thenReturn(createPullRequest("opened_1", PullRequestStatus.OPEN));
when(branchResolver.resolve(any(), any())).thenReturn(Branch.normalBranch("master", "123"));
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/1/reject");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_NO_CONTENT);
verify(store).update(argThat(pullRequest -> {
assertThat(pullRequest.getStatus()).isEqualTo(REJECTED);
return true;
}));
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class EngineResultResourceTest method shouldGetEmptyResultWithoutRules.
@Test
void shouldGetEmptyResultWithoutRules() throws URISyntaxException, UnsupportedEncodingException, JsonProcessingException {
when(engine.validate(REPOSITORY, PULL_REQUEST)).thenReturn(new Results(emptyList()));
MockHttpRequest request = MockHttpRequest.get("/v2/pull-requests/space/X/42/workflow");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
JsonNode jsonNode = getJsonNode();
JsonNode results = jsonNode.get("results");
assertThat(results).isNotNull();
assertThat(results.size()).isEqualTo(0);
JsonNode links = jsonNode.get("_links");
assertThat(links).isNotNull();
assertThat(links.get("self")).isNotNull();
assertThat(links.get("self").get("href")).isNotNull();
assertThat(links.get("self").get("href").asText()).isEqualTo("/v2/pull-requests/space/X/42/workflow/");
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class GlobalEngineConfigResourceTest method shouldReturnConfigurationWithUpdateLink.
@Test
void shouldReturnConfigurationWithUpdateLink() throws URISyntaxException, UnsupportedEncodingException {
when(configurator.getEngineConfiguration()).thenReturn(new GlobalEngineConfiguration(ImmutableList.of(AppliedRule.of(SuccessRule.class)), true, false));
when(subject.isPermitted("configuration:write:workflowConfig")).thenReturn(true);
MockHttpRequest request = MockHttpRequest.get("/v2/workflow/config");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("\"update\":{\"href\":\"/v2/workflow/config\"}").contains("\"availableRules\":{\"href\":\"/v2/workflow/rules\"}");
}
use of org.jboss.resteasy.mock.MockHttpRequest in project scm-review-plugin by scm-manager.
the class GlobalEngineConfigResourceTest method shouldReturnConfiguration.
@Test
void shouldReturnConfiguration() throws URISyntaxException, UnsupportedEncodingException {
when(configurator.getEngineConfiguration()).thenReturn(new GlobalEngineConfiguration(ImmutableList.of(AppliedRule.of(SuccessRule.class)), true, false));
when(subject.isPermitted("configuration:write:workflowConfig")).thenReturn(true);
MockHttpRequest request = MockHttpRequest.get("/v2/workflow/config");
dispatcher.invoke(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).contains("\"rules\":[{\"rule\":\"SuccessRule\"}]").contains("\"enabled\":true").contains("\"self\":{\"href\":\"/v2/workflow/config\"}");
}
Aggregations