• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account Log out
  • Favorite
  • Project
  • Recent History
Loading...
  • Log in
  • Sign up
kadrians / Testing_for_YONA star
  • Project homeH
  • CodeC
  • IssueI 1
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB 2
  • Files
  • Commit
  • Branches
Testing_for_YONAsourcetestcontrollersPullRequestAppTest.java
Download as .zip file
File name
Commit message
Commit date
bin
Yona 1.16.0 Upload
02-04
lib
Yona 1.16.0 Upload
02-04
share/doc/api
Yona 1.16.0 Upload
02-04
source
Source Code Upload
02-04
README.md
Yona 1.16.0 Upload
02-04
File name
Commit message
Commit date
app
Source Code Upload
02-04
conf
Source Code Upload
02-04
docs
Source Code Upload
02-04
lib
Source Code Upload
02-04
project
Source Code Upload
02-04
public
Source Code Upload
02-04
support-script
Source Code Upload
02-04
test
Source Code Upload
02-04
.gitignore
Source Code Upload
02-04
.mailmap
Source Code Upload
02-04
.travis.yml
Source Code Upload
02-04
AUTHORS
Source Code Upload
02-04
LICENSE
Source Code Upload
02-04
NOTICE
Source Code Upload
02-04
README.md
Source Code Upload
02-04
build.sbt
Source Code Upload
02-04
dev.sh
Source Code Upload
02-04
dist.sh
Source Code Upload
02-04
is-alive-bot.sh
Source Code Upload
02-04
minify-js.sh
Source Code Upload
02-04
restart.sh
Source Code Upload
02-04
File name
Commit message
Commit date
actions/support
Source Code Upload
02-04
actors
Source Code Upload
02-04
controllers
Source Code Upload
02-04
mailbox
Source Code Upload
02-04
models
Source Code Upload
02-04
playRepository
Source Code Upload
02-04
support
Source Code Upload
02-04
utils
Source Code Upload
02-04
validation
Source Code Upload
02-04
File name
Commit message
Commit date
api
Source Code Upload
02-04
ApplicationTest.java
Source Code Upload
02-04
CommentAppTest.java
Source Code Upload
02-04
EnrollProjectAppTest.java
Source Code Upload
02-04
ImportAppTest.java
Source Code Upload
02-04
IssueAppTest.java
Source Code Upload
02-04
MarkdownAppTest.java
Source Code Upload
02-04
PasswordResetAppTest.java
Source Code Upload
02-04
ProjectAppTest.java
Source Code Upload
02-04
PullRequestAppTest.java
Source Code Upload
02-04
ReviewThreadAppTest.java
Source Code Upload
02-04
SiteAppTest.java
Source Code Upload
02-04
UserAppTest.java
Source Code Upload
02-04
WatchProjectAppTest.java
Source Code Upload
02-04
Nell 02-04 2600fe6 Source Code Upload UNIX
Raw Open in browser Change history
/** * Yobi, Project Hosting SW * * Copyright 2013 NAVER Corp. * http://yobi.io * * @Author Wansoon Park * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package controllers; import static org.fest.assertions.Assertions.assertThat; import static play.mvc.Http.Status.*; import static play.test.Helpers.*; import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.Map; import models.Project; import models.PullRequest; import models.PushedBranch; import models.User; import models.enumeration.State; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.RefSpec; import org.junit.*; import org.junit.rules.TestWatcher; import play.mvc.Result; import play.test.FakeApplication; import play.test.Helpers; import support.ExecutionTimeWatcher; import playRepository.GitRepository; public class PullRequestAppTest { protected static FakeApplication app; private String ownerLoginId; private String projectName; private Long pullRequestNumber; private static PullRequest pullRequest; private static boolean isInit = false; @Rule public TestWatcher watcher = new ExecutionTimeWatcher(); @BeforeClass public static void beforeClass() { app = support.Helpers.makeTestApplication(); Helpers.start(app); } @Before public void before() { GitRepository.setRepoPrefix("resources/test/repo/git/"); } @AfterClass public static void afterClase(){ Helpers.stop(app); } @After public void after() { support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); } @Test public void testCloseAnonymous() throws Exception { initParameters("alecsiel", "sample", 10L); Result result = callAction( controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber) ); assertThat(status(result)).isEqualTo(SEE_OTHER); } @Test public void testCloseNotExistProject() throws Exception { initParameters("alecsiel", "sample", 10L); User currentUser = User.findByLoginId("admin"); Result result = callAction( controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(FORBIDDEN); } @Test public void testCloseNotExistPullRequest() throws Exception { initParameters("yobi", "projectYobi-1", 10L); User currentUser = User.findByLoginId("admin"); Result result = callAction( controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(NOT_FOUND); } @Test public void testClosePullRequest() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("admin"); Result result = callAction( controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(SEE_OTHER); assertThat(PullRequest.findById(pullRequestNumber).state).isEqualTo(State.CLOSED); } @Test public void testClosePullRequestNotAllow() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("alecsiel"); User projectOwner = User.findByLoginId("yobi"); callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) ); Result result = callAction( controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(FORBIDDEN); assertThat(PullRequest.findById(pullRequestNumber).state).isEqualTo(State.OPEN); } @Test public void testOpenAnonymous() throws Exception { initParameters("alecsiel", "sample", 10L); Result result = callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber) ); assertThat(status(result)).isEqualTo(SEE_OTHER); } @Test public void testOpenPullRequestBadRequest() throws Exception { //Given initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("admin"); User projectOwner = User.findByLoginId("yobi"); final String uri = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber; callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) ); //When Result result = callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); //Then assertThat(status(result)).isEqualTo(BAD_REQUEST).describedAs("open already opened"); } @Test public void testOpenPullRequest() throws Exception { // Given initParameters("yobi", "HelloSocialApp", 1L); User currentUser = User.findByLoginId("admin"); Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName); PullRequest pullRequest = PullRequest.findOne(project, pullRequestNumber); PushedBranch pushedBranch = new PushedBranch(new Date(), pullRequest.fromBranch, pullRequest.fromProject); pushedBranch.save(); // When Result result = callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); // Then assertThat(status(result)).isEqualTo(SEE_OTHER); assertThat(PullRequest.findOne(project, pullRequestNumber).state).isEqualTo(State.OPEN); assertThat( PushedBranch.find.where().eq("project", pullRequest.fromProject) .eq("name", pullRequest.fromBranch).findUnique()).isNull(); } @Test public void testAcceptAnonymous() throws Exception { initParameters("alecsiel", "sample", 10L); Result result = callAction( controllers.routes.ref.PullRequestApp.accept(ownerLoginId, projectName, pullRequestNumber) ); assertThat(status(result)).isEqualTo(SEE_OTHER); } @Test public void testNewForkByAdmin() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("admin"); Result result = callAction( controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(OK); } @Test public void testNewForkByMember() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("yobi"); Result result = callAction( controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(OK); } @Test public void testNewForkByNotMember() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("alecsiel"); Result result = callAction( controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(OK); } @Test public void testNewForkPrivateProjectAndNotMember() throws Exception { initParameters("laziel", "Jindo", 1L); User currentUser = User.findByLoginId("alecsiel"); Result result = callAction( controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(FORBIDDEN); } @Test public void testForkAlreadyExistForkProject() throws Exception { initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("yobi"); Map<String,String> data = new HashMap<>(); data.put("owner", "yobi"); data.put("name", "projectYobi-2"); data.put("projectScope", "PUBLIC"); Result result = callAction( controllers.routes.ref.PullRequestApp.fork(ownerLoginId, projectName), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/fork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) .withFormUrlEncodedBody(data) ); assertThat(status(result)).isEqualTo(OK); } @Test public void testForkSampleName() throws Exception { initParameters("yobi", "TestApp", 1L); User currentUser = User.findByLoginId("yobi"); Map<String,String> data = new HashMap<>(); data.put("name", "HelloSocialApp-1"); Result result = callAction( controllers.routes.ref.PullRequestApp.fork(ownerLoginId, projectName), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/fork") .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) .withFormUrlEncodedBody(data) ); assertThat(status(result)).isEqualTo(SEE_OTHER); } @Test public void testNewForkRoute() throws Exception { initParameters("yobi", "projectYobi", 1L); String url = "/" + ownerLoginId + "/" + projectName + "/newFork"; User currentUser = User.findByLoginId("yobi"); Result result = route( fakeRequest(GET, url).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(OK); } @Test public void testCloseRoute() throws Exception { initParameters("yobi", "projectYobi", 1L); String url = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber + "/close"; User currentUser = User.findByLoginId("yobi"); Result result = route( fakeRequest(POST, url).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); assertThat(status(result)).isEqualTo(SEE_OTHER); Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName); PullRequest pullRequest = PullRequest.findOne(project, pullRequestNumber); assertThat(pullRequest.state).isEqualTo(State.CLOSED); } @Test public void testOpenRoute() throws Exception { //Given initParameters("yobi", "projectYobi", 1L); User currentUser = User.findByLoginId("yobi"); User projectOwner = User.findByLoginId("yobi"); String url = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber + "/open"; callAction( controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) .withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) ); //When Result result = route( fakeRequest(POST, url).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) ); //Then assertThat(status(result)).isEqualTo(BAD_REQUEST); Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName); PullRequest pullRequest = PullRequest.findOne(project, pullRequestNumber); assertThat(pullRequest.state).isEqualTo(State.OPEN); } private void initParameters(String ownerLoginId, String projectName, Long pullRequestNumber) throws Exception { this.ownerLoginId = ownerLoginId; this.projectName = projectName; this.pullRequestNumber = pullRequestNumber; } }

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
login with Google Sign in with Google
Reset password | Sign up