[Notice] Announcing the End of Demo Server [Read me]

Merge branch 'bugfix/import' of kjkmadness/yobi
from pull request 717
@2c5256a4bc39b0ee879a29d2b36d810be4647847
--- app/controllers/ImportApp.java
+++ app/controllers/ImportApp.java
... | ... | @@ -13,6 +13,7 @@ |
13 | 13 |
import utils.FileUtil; |
14 | 14 |
import views.html.project.importing; |
15 | 15 |
|
16 |
+import org.apache.commons.lang3.StringUtils; |
|
16 | 17 |
import org.eclipse.jgit.api.errors.*; |
17 | 18 |
import java.io.IOException; |
18 | 19 |
|
... | ... | @@ -50,8 +51,8 @@ |
50 | 51 |
|
51 | 52 |
Form<Project> filledNewProjectForm = form(Project.class).bindFromRequest(); |
52 | 53 |
|
53 |
- String gitUrl = filledNewProjectForm.data().get("url"); |
|
54 |
- if(gitUrl == null || gitUrl.trim().isEmpty()) { |
|
54 |
+ String gitUrl = StringUtils.trim(filledNewProjectForm.data().get("url")); |
|
55 |
+ if(StringUtils.isBlank(gitUrl)) { |
|
55 | 56 |
flash(Constants.WARNING, "project.import.error.empty.url"); |
56 | 57 |
return badRequest(importing.render("title.newProject", filledNewProjectForm)); |
57 | 58 |
} |
--- app/views/project/overview.scala.html
+++ app/views/project/overview.scala.html
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 |
</div> |
46 | 46 |
</div> |
47 | 47 |
<div class="project-clone-wrap span3"> |
48 |
- <input type="text" class="project-clone-url" id="cloneURL" readonly="readonly" value="@if(project.isGit){ @CodeApp.getURLWithLoginId(project) } else { @CodeApp.getURL(project) }"> |
|
48 |
+ <input type="text" class="project-clone-url" id="cloneURL" readonly="readonly" value="@if(project.isGit){@CodeApp.getURLWithLoginId(project)} else {@CodeApp.getURL(project)}"> |
|
49 | 49 |
<button class="ybtn project-clone-button" id="cloneURLBtn">@Messages("code.copyUrl")</button> |
50 | 50 |
</div> |
51 | 51 |
</div> |
+++ test/controllers/ImportAppTest.java
... | ... | @@ -0,0 +1,192 @@ |
1 | +/** | |
2 | + * Yobi, Project Hosting SW | |
3 | + * | |
4 | + * Copyright 2013 NAVER Corp. | |
5 | + * http://yobi.io | |
6 | + * | |
7 | + * @Author kjkmadness | |
8 | + * | |
9 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
10 | + * you may not use this file except in compliance with the License. | |
11 | + * You may obtain a copy of the License at | |
12 | + * | |
13 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | + * | |
15 | + * Unless required by applicable law or agreed to in writing, software | |
16 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
17 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
18 | + * See the License for the specific language governing permissions and | |
19 | + * limitations under the License. | |
20 | + */ | |
21 | +package controllers; | |
22 | + | |
23 | +import static org.fest.assertions.Assertions.*; | |
24 | +import static play.test.Helpers.*; | |
25 | + | |
26 | +import java.io.File; | |
27 | +import java.util.HashMap; | |
28 | +import java.util.Map; | |
29 | + | |
30 | +import models.Project; | |
31 | +import models.User; | |
32 | + | |
33 | +import org.junit.After; | |
34 | +import org.junit.Before; | |
35 | +import org.junit.Test; | |
36 | + | |
37 | +import controllers.routes.ref; | |
38 | + | |
39 | +import play.mvc.Result; | |
40 | +import play.test.FakeApplication; | |
41 | +import playRepository.GitRepository; | |
42 | +import utils.Constants; | |
43 | + | |
44 | +public class ImportAppTest { | |
45 | + private FakeApplication application; | |
46 | + private User yobi; | |
47 | + private Project src; | |
48 | + private Project dest; | |
49 | + private Map<String, String> formData; | |
50 | + | |
51 | + @Before | |
52 | + public void before() throws Exception { | |
53 | + GitRepository.setRepoPrefix("resources/test/repo/git/"); | |
54 | + GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); | |
55 | + application = support.Helpers.makeTestApplication(); | |
56 | + start(application); | |
57 | + yobi = User.findByLoginId("yobi"); | |
58 | + src = project(yobi.loginId, "src"); | |
59 | + dest = project(yobi.loginId, "dest"); | |
60 | + createRepository(src); | |
61 | + formData = new HashMap<>(); | |
62 | + } | |
63 | + | |
64 | + @After | |
65 | + public void after() { | |
66 | + stop(application); | |
67 | + support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); | |
68 | + support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); | |
69 | + } | |
70 | + | |
71 | + @Test | |
72 | + public void importFormAnonymous() { | |
73 | + // When | |
74 | + Result result = callAction(ref.ImportApp.importForm()); | |
75 | + | |
76 | + // Then | |
77 | + assertThat(status(result)).isEqualTo(SEE_OTHER); | |
78 | + assertThat(header(LOCATION, result)).isEqualTo(routes.UserApp.loginForm().url()); | |
79 | + } | |
80 | + | |
81 | + @Test | |
82 | + public void importForm() { | |
83 | + // Given | |
84 | + User user = User.find.byId(2L); | |
85 | + | |
86 | + // When | |
87 | + Result result = callAction(ref.ImportApp.importForm(), | |
88 | + fakeRequest().withSession(UserApp.SESSION_USERID, String.valueOf(user.id))); | |
89 | + | |
90 | + // Then | |
91 | + assertThat(status(result)).isEqualTo(OK); | |
92 | + } | |
93 | + | |
94 | + @Test | |
95 | + public void newProject() throws Exception { | |
96 | + // Given | |
97 | + formData.put("url", GitRepository.getGitDirectoryURL(src)); | |
98 | + formData.put("name", dest.name); | |
99 | + formData.put("isPublic", "true"); | |
100 | + formData.put("vcs", "GIT"); | |
101 | + | |
102 | + // When | |
103 | + Result result = callAction(ref.ImportApp.newProject(), | |
104 | + fakeRequest() | |
105 | + .withSession(UserApp.SESSION_USERID, String.valueOf(yobi.id)) | |
106 | + .withFormUrlEncodedBody(formData)); | |
107 | + | |
108 | + // Then | |
109 | + assertThat(status(result)).isEqualTo(SEE_OTHER); | |
110 | + assertThat(header(LOCATION, result)).isEqualTo(routes.ProjectApp.project(dest.owner, dest.name).url()); | |
111 | + assertThat(Project.findByOwnerAndProjectName(dest.owner, dest.name)).isNotNull(); | |
112 | + assertThat(new File(GitRepository.getGitDirectoryURL(dest)).exists()).isTrue(); | |
113 | + } | |
114 | + | |
115 | + @Test | |
116 | + public void newProjectAnonymous() { | |
117 | + // When | |
118 | + Result result = callAction(ref.ImportApp.newProject()); | |
119 | + | |
120 | + // Then | |
121 | + assertThat(status(result)).isEqualTo(FORBIDDEN); | |
122 | + } | |
123 | + | |
124 | + @Test | |
125 | + public void newProjectNoUrl() { | |
126 | + // Given | |
127 | + formData.put("name", dest.name); | |
128 | + formData.put("isPublic", "true"); | |
129 | + formData.put("vcs", "GIT"); | |
130 | + | |
131 | + // When | |
132 | + Result result = callAction(ref.ImportApp.newProject(), | |
133 | + fakeRequest() | |
134 | + .withSession(UserApp.SESSION_USERID, String.valueOf(yobi.id)) | |
135 | + .withFormUrlEncodedBody(formData)); | |
136 | + | |
137 | + // Then | |
138 | + assertThat(status(result)).isEqualTo(BAD_REQUEST); | |
139 | + assertThat(flash(result).get(Constants.WARNING)).isEqualTo("project.import.error.empty.url"); | |
140 | + } | |
141 | + | |
142 | + @Test | |
143 | + public void newProjectDuplicatedName() throws Exception { | |
144 | + // Given | |
145 | + formData.put("url", GitRepository.getGitDirectoryURL(src)); | |
146 | + formData.put("name", "projectYobi"); | |
147 | + formData.put("isPublic", "true"); | |
148 | + formData.put("vcs", "GIT"); | |
149 | + | |
150 | + // When | |
151 | + Result result = callAction(ref.ImportApp.newProject(), | |
152 | + fakeRequest() | |
153 | + .withSession(UserApp.SESSION_USERID, String.valueOf(yobi.id)) | |
154 | + .withFormUrlEncodedBody(formData)); | |
155 | + | |
156 | + // Then | |
157 | + assertThat(status(result)).isEqualTo(BAD_REQUEST); | |
158 | + assertThat(flash(result).get(Constants.WARNING)).isEqualTo("project.name.duplicate"); | |
159 | + } | |
160 | + | |
161 | + @Test | |
162 | + public void newProjectWrongName() throws Exception { | |
163 | + // Given | |
164 | + formData.put("url", GitRepository.getGitDirectoryURL(src)); | |
165 | + formData.put("name", "!@#$%"); | |
166 | + formData.put("isPublic", "true"); | |
167 | + formData.put("vcs", "GIT"); | |
168 | + | |
169 | + // When | |
170 | + Result result = callAction(ref.ImportApp.newProject(), | |
171 | + fakeRequest() | |
172 | + .withSession(UserApp.SESSION_USERID, String.valueOf(yobi.id)) | |
173 | + .withFormUrlEncodedBody(formData)); | |
174 | + | |
175 | + // Then | |
176 | + assertThat(status(result)).isEqualTo(BAD_REQUEST); | |
177 | + assertThat(flash(result).get(Constants.WARNING)).isEqualTo("project.name.alert"); | |
178 | + } | |
179 | + | |
180 | + private Project project(String owner, String name) { | |
181 | + Project project = new Project(); | |
182 | + project.owner = owner; | |
183 | + project.name = name; | |
184 | + return project; | |
185 | + } | |
186 | + | |
187 | + private void createRepository(Project project) throws Exception { | |
188 | + GitRepository gitRepository = new GitRepository(project); | |
189 | + gitRepository.create(); | |
190 | + gitRepository.close(); | |
191 | + } | |
192 | +} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?