
test: refactoring which is aimed for testing time and efficiency
@85ca03e511afe3d788aced7571860668dc57d605
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
... | ... | @@ -935,4 +935,9 @@ |
935 | 935 |
this.mergedCommitIdFrom != null && this.mergedCommitIdTo != null; |
936 | 936 |
} |
937 | 937 |
|
938 |
+ @Override |
|
939 |
+ public Object clone() throws CloneNotSupportedException { |
|
940 |
+ PullRequest cloned = (PullRequest)super.clone(); |
|
941 |
+ return cloned; |
|
942 |
+ } |
|
938 | 943 |
} |
--- app/utils/PasswordReset.java
+++ app/utils/PasswordReset.java
... | ... | @@ -48,20 +48,16 @@ |
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
public static void addHashToResetTable(String userId, String hashString) { |
51 |
- Logger.debug(">> add to HashTable " + userId + ":" + hashString); |
|
52 | 51 |
PasswordReset.resetHashMap.put(userId, hashString); |
53 | 52 |
resetHashTimetable.put(hashString, new DateTime().getMillis()); |
54 | 53 |
} |
55 | 54 |
|
56 | 55 |
public static boolean isValidResetHash(String hashString) { |
57 |
- Logger.debug("Reset hash entry size:" + resetHashMap.size()); |
|
58 | 56 |
if( !resetHashMap.containsValue(hashString) ) { |
59 |
- Logger.debug("HashString doesn't exists in resetHashMap: " + hashString); |
|
60 | 57 |
return false; |
61 | 58 |
} |
62 | 59 |
|
63 | 60 |
if(isExpired(hashString)) { |
64 |
- Logger.debug("HashString was expired: " + hashString); |
|
65 | 61 |
return false; |
66 | 62 |
} |
67 | 63 |
|
--- conf/test-data.yml
+++ conf/test-data.yml
... | ... | @@ -24,6 +24,7 @@ |
24 | 24 |
state: ACTIVE |
25 | 25 |
email: doortts@gmail.com |
26 | 26 |
createdDate: 2012-07-01 08:00:00 |
27 |
+ state: ACTIVE |
|
27 | 28 |
- !!models.User |
28 | 29 |
name: eungjun |
29 | 30 |
loginId: nori |
--- project/Build.scala
+++ project/Build.scala
... | ... | @@ -1,5 +1,5 @@ |
1 | 1 |
import sbt._ |
2 |
-import Keys._ |
|
2 |
+import sbt.Keys._ |
|
3 | 3 |
import play.Project.javaCore |
4 | 4 |
import play.Project.javaJdbc |
5 | 5 |
import play.Project.javaEbean |
... | ... | @@ -65,7 +65,7 @@ |
65 | 65 |
templatesImport += "models.enumeration._", |
66 | 66 |
lessEntryPoints <<= baseDirectory(_ / "app" / "assets" / "stylesheets" ** "yobi.less"), |
67 | 67 |
// jacoco.settings:_*, |
68 |
- javaOptions in test ++= Seq("-Xmx512m", "-XX:MaxPermSize=512m", "-Dfile.encoding=UTF-8"), |
|
68 |
+ javaOptions in test ++= Seq("-Xmx2g", "-Xms1g", "-XX:MaxPermSize=1g", "-Dfile.encoding=UTF-8"), |
|
69 | 69 |
javacOptions ++= Seq("-Xlint:all", "-Xlint:-path"), |
70 | 70 |
scalacOptions ++= Seq("-feature") |
71 | 71 |
) |
--- test/controllers/CommentAppTest.java
+++ test/controllers/CommentAppTest.java
... | ... | @@ -56,13 +56,12 @@ |
56 | 56 |
callAction( |
57 | 57 |
routes.ref.Application.init() |
58 | 58 |
); |
59 |
+ app = support.Helpers.makeTestApplication(); |
|
60 |
+ Helpers.start(app); |
|
59 | 61 |
} |
60 | 62 |
|
61 | 63 |
@Before |
62 | 64 |
public void before() { |
63 |
- app = support.Helpers.makeTestApplication(); |
|
64 |
- Helpers.start(app); |
|
65 |
- |
|
66 | 65 |
admin = User.findByLoginId("admin"); |
67 | 66 |
manager = User.findByLoginId("yobi"); |
68 | 67 |
member = User.findByLoginId("laziel"); |
--- test/controllers/EnrollProjectAppTest.java
+++ test/controllers/EnrollProjectAppTest.java
... | ... | @@ -33,16 +33,16 @@ |
33 | 33 |
import play.test.FakeApplication; |
34 | 34 |
|
35 | 35 |
public class EnrollProjectAppTest { |
36 |
- private FakeApplication application; |
|
36 |
+ private static FakeApplication application; |
|
37 | 37 |
|
38 |
- @Before |
|
39 |
- public void before() { |
|
38 |
+ @BeforeClass |
|
39 |
+ public static void beforeClass() { |
|
40 | 40 |
application = support.Helpers.makeTestApplication(); |
41 | 41 |
start(application); |
42 | 42 |
} |
43 | 43 |
|
44 |
- @After |
|
45 |
- public void after() { |
|
44 |
+ @AfterClass |
|
45 |
+ public static void afterClass() { |
|
46 | 46 |
stop(application); |
47 | 47 |
} |
48 | 48 |
|
--- test/controllers/ImportAppTest.java
+++ test/controllers/ImportAppTest.java
... | ... | @@ -31,9 +31,7 @@ |
31 | 31 |
import models.Project; |
32 | 32 |
import models.User; |
33 | 33 |
|
34 |
-import org.junit.After; |
|
35 |
-import org.junit.Before; |
|
36 |
-import org.junit.Test; |
|
34 |
+import org.junit.*; |
|
37 | 35 |
|
38 | 36 |
import controllers.routes.ref; |
39 | 37 |
|
... | ... | @@ -46,14 +44,14 @@ |
46 | 44 |
import utils.Constants; |
47 | 45 |
|
48 | 46 |
public class ImportAppTest { |
49 |
- private FakeApplication application; |
|
50 |
- private User yobi; |
|
51 |
- private Project src; |
|
52 |
- private Project dest; |
|
53 |
- private Map<String, String> formData; |
|
47 |
+ private static FakeApplication application; |
|
48 |
+ private static User yobi; |
|
49 |
+ private static Project src; |
|
50 |
+ private static Project dest; |
|
51 |
+ private static Map<String, String> formData; |
|
54 | 52 |
|
55 |
- @Before |
|
56 |
- public void before() throws Exception { |
|
53 |
+ @BeforeClass |
|
54 |
+ public static void before() throws Exception { |
|
57 | 55 |
GitRepository.setRepoPrefix("resources/test/repo/git/"); |
58 | 56 |
GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
59 | 57 |
application = support.Helpers.makeTestApplication(); |
... | ... | @@ -65,8 +63,8 @@ |
65 | 63 |
formData = new HashMap<>(); |
66 | 64 |
} |
67 | 65 |
|
68 |
- @After |
|
69 |
- public void after() { |
|
66 |
+ @AfterClass |
|
67 |
+ public static void after() { |
|
70 | 68 |
stop(application); |
71 | 69 |
support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
72 | 70 |
support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
... | ... | @@ -191,14 +189,14 @@ |
191 | 189 |
assertThat(contentAsString(result)).contains(Messages.get(Lang.defaultLang(), "project.name.alert")); |
192 | 190 |
} |
193 | 191 |
|
194 |
- private Project project(String owner, String name) { |
|
192 |
+ private static Project project(String owner, String name) { |
|
195 | 193 |
Project project = new Project(); |
196 | 194 |
project.owner = owner; |
197 | 195 |
project.name = name; |
198 | 196 |
return project; |
199 | 197 |
} |
200 | 198 |
|
201 |
- private void createRepository(Project project) throws Exception { |
|
199 |
+ private static void createRepository(Project project) throws Exception { |
|
202 | 200 |
GitRepository gitRepository = new GitRepository(project); |
203 | 201 |
gitRepository.create(); |
204 | 202 |
gitRepository.close(); |
--- test/controllers/ProjectAppTest.java
+++ test/controllers/ProjectAppTest.java
... | ... | @@ -67,11 +67,6 @@ |
67 | 67 |
Helpers.start(app); |
68 | 68 |
} |
69 | 69 |
|
70 |
- @After |
|
71 |
- public void after() { |
|
72 |
- Helpers.stop(app); |
|
73 |
- } |
|
74 |
- |
|
75 | 70 |
@Test |
76 | 71 |
public void label() { |
77 | 72 |
//Given |
--- test/controllers/PullRequestAppTest.java
+++ test/controllers/PullRequestAppTest.java
... | ... | @@ -40,22 +40,52 @@ |
40 | 40 |
import org.eclipse.jgit.api.Git; |
41 | 41 |
import org.eclipse.jgit.lib.Repository; |
42 | 42 |
import org.eclipse.jgit.transport.RefSpec; |
43 |
-import org.junit.After; |
|
44 |
-import org.junit.Before; |
|
45 |
-import org.junit.BeforeClass; |
|
46 |
-import org.junit.Test; |
|
43 |
+import org.junit.*; |
|
47 | 44 |
|
45 |
+import org.junit.rules.TestWatcher; |
|
48 | 46 |
import play.mvc.Result; |
49 | 47 |
import play.test.FakeApplication; |
50 | 48 |
import play.test.Helpers; |
49 |
+import support.ExecutionTimeWatcher; |
|
51 | 50 |
import playRepository.GitRepository; |
52 | 51 |
|
53 | 52 |
public class PullRequestAppTest { |
54 |
- protected FakeApplication app; |
|
53 |
+ protected static FakeApplication app; |
|
55 | 54 |
|
56 | 55 |
private String ownerLoginId; |
57 | 56 |
private String projectName; |
58 | 57 |
private Long pullRequestNumber; |
58 |
+ private static PullRequest pullRequest; |
|
59 |
+ private static boolean isInit = false; |
|
60 |
+ |
|
61 |
+ @Rule |
|
62 |
+ public TestWatcher watcher = new ExecutionTimeWatcher(); |
|
63 |
+ |
|
64 |
+ @BeforeClass |
|
65 |
+ public static void beforeClass() { |
|
66 |
+ callAction( |
|
67 |
+ routes.ref.Application.init() |
|
68 |
+ ); |
|
69 |
+ app = support.Helpers.makeTestApplication(); |
|
70 |
+ Helpers.start(app); |
|
71 |
+ } |
|
72 |
+ |
|
73 |
+ @Before |
|
74 |
+ public void before() { |
|
75 |
+ GitRepository.setRepoPrefix("resources/test/repo/git/"); |
|
76 |
+ GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
|
77 |
+ } |
|
78 |
+ |
|
79 |
+ @AfterClass |
|
80 |
+ public static void afterClase(){ |
|
81 |
+ Helpers.stop(app); |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ @After |
|
85 |
+ public void after() { |
|
86 |
+ support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
|
87 |
+ support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
|
88 |
+ } |
|
59 | 89 |
|
60 | 90 |
@Test |
61 | 91 |
public void testCloseAnonymous() throws Exception { |
... | ... | @@ -103,8 +133,8 @@ |
103 | 133 |
Result result = callAction( |
104 | 134 |
controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), |
105 | 135 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) |
106 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
107 |
- ); |
|
136 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
137 |
+ ); |
|
108 | 138 |
|
109 | 139 |
assertThat(status(result)).isEqualTo(SEE_OTHER); |
110 | 140 |
assertThat(PullRequest.findById(pullRequestNumber).state).isEqualTo(State.CLOSED); |
... | ... | @@ -114,6 +144,13 @@ |
114 | 144 |
public void testClosePullRequestNotAllow() throws Exception { |
115 | 145 |
initParameters("yobi", "projectYobi", 1L); |
116 | 146 |
User currentUser = User.findByLoginId("alecsiel"); |
147 |
+ User projectOwner = User.findByLoginId("yobi"); |
|
148 |
+ |
|
149 |
+ callAction( |
|
150 |
+ controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), |
|
151 |
+ fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) |
|
152 |
+ .withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) |
|
153 |
+ ); |
|
117 | 154 |
|
118 | 155 |
Result result = callAction( |
119 | 156 |
controllers.routes.ref.PullRequestApp.close(ownerLoginId, projectName, pullRequestNumber), |
... | ... | @@ -222,8 +259,8 @@ |
222 | 259 |
Result result = callAction( |
223 | 260 |
controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), |
224 | 261 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") |
225 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
226 |
- ); |
|
262 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
263 |
+ ); |
|
227 | 264 |
|
228 | 265 |
assertThat(status(result)).isEqualTo(OK); |
229 | 266 |
} |
... | ... | @@ -236,8 +273,8 @@ |
236 | 273 |
Result result = callAction( |
237 | 274 |
controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), |
238 | 275 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") |
239 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
240 |
- ); |
|
276 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
277 |
+ ); |
|
241 | 278 |
|
242 | 279 |
assertThat(status(result)).isEqualTo(FORBIDDEN); |
243 | 280 |
} |
... | ... | @@ -255,9 +292,9 @@ |
255 | 292 |
Result result = callAction( |
256 | 293 |
controllers.routes.ref.PullRequestApp.fork(ownerLoginId, projectName), |
257 | 294 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/fork") |
258 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
259 |
- .withFormUrlEncodedBody(data) |
|
260 |
- ); |
|
295 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
296 |
+ .withFormUrlEncodedBody(data) |
|
297 |
+ ); |
|
261 | 298 |
|
262 | 299 |
assertThat(status(result)).isEqualTo(OK); |
263 | 300 |
} |
... | ... | @@ -310,41 +347,30 @@ |
310 | 347 |
|
311 | 348 |
@Test |
312 | 349 |
public void testOpenRoute() throws Exception { |
350 |
+ //Given |
|
313 | 351 |
initParameters("yobi", "projectYobi", 1L); |
314 |
- String url = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber + "/open"; |
|
315 | 352 |
User currentUser = User.findByLoginId("yobi"); |
353 |
+ User projectOwner = User.findByLoginId("yobi"); |
|
316 | 354 |
|
355 |
+ String url = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber + "/open"; |
|
356 |
+ callAction( |
|
357 |
+ controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), |
|
358 |
+ fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) |
|
359 |
+ .withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) |
|
360 |
+ ); |
|
361 |
+ |
|
362 |
+ //When |
|
317 | 363 |
Result result = route( |
318 | 364 |
fakeRequest(POST, url).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
319 | 365 |
); |
366 |
+ |
|
367 |
+ //Then |
|
320 | 368 |
assertThat(status(result)).isEqualTo(BAD_REQUEST); |
321 | 369 |
|
322 | 370 |
Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName); |
323 | 371 |
PullRequest pullRequest = PullRequest.findOne(project, pullRequestNumber); |
324 | 372 |
|
325 | 373 |
assertThat(pullRequest.state).isEqualTo(State.OPEN); |
326 |
- } |
|
327 |
- |
|
328 |
- @BeforeClass |
|
329 |
- public static void beforeClass() { |
|
330 |
- callAction( |
|
331 |
- routes.ref.Application.init() |
|
332 |
- ); |
|
333 |
- } |
|
334 |
- |
|
335 |
- @Before |
|
336 |
- public void before() { |
|
337 |
- GitRepository.setRepoPrefix("resources/test/repo/git/"); |
|
338 |
- GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
|
339 |
- app = support.Helpers.makeTestApplication(); |
|
340 |
- Helpers.start(app); |
|
341 |
- } |
|
342 |
- |
|
343 |
- @After |
|
344 |
- public void after() { |
|
345 |
- Helpers.stop(app); |
|
346 |
- support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
|
347 |
- support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
|
348 | 374 |
} |
349 | 375 |
|
350 | 376 |
private void initParameters(String ownerLoginId, String projectName, Long pullRequestNumber) |
--- test/controllers/ReviewThreadAppTest.java
+++ test/controllers/ReviewThreadAppTest.java
... | ... | @@ -35,6 +35,20 @@ |
35 | 35 |
protected static FakeApplication app; |
36 | 36 |
|
37 | 37 |
/** |
38 |
+ * 테스트를 위해 메모리 DB로 전환 |
|
39 |
+ */ |
|
40 |
+ @BeforeClass |
|
41 |
+ public static void beforeClass() { |
|
42 |
+ app = support.Helpers.makeTestApplication(); |
|
43 |
+ Helpers.start(app); |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+ @AfterClass |
|
47 |
+ public static void afterClass() { |
|
48 |
+ Helpers.stop(app); |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ /** |
|
38 | 52 |
* 잘못된 URL을 입력하여 not found return을 테스트 |
39 | 53 |
*/ |
40 | 54 |
@Test |
... | ... | @@ -57,19 +71,5 @@ |
57 | 71 |
); |
58 | 72 |
|
59 | 73 |
assertThat(status(result)).isEqualTo(SEE_OTHER); |
60 |
- } |
|
61 |
- |
|
62 |
- /** |
|
63 |
- * 테스트를 위해 메모리 DB로 전환 |
|
64 |
- */ |
|
65 |
- @BeforeClass |
|
66 |
- public static void beforeClass() { |
|
67 |
- app = support.Helpers.makeTestApplication(); |
|
68 |
- Helpers.start(app); |
|
69 |
- } |
|
70 |
- |
|
71 |
- @AfterClass |
|
72 |
- public static void afterClass() { |
|
73 |
- Helpers.stop(app); |
|
74 | 74 |
} |
75 | 75 |
} |
--- test/controllers/SearchAppTest.java
... | ... | @@ -1,35 +0,0 @@ |
1 | -/** | |
2 | - * Yobi, Project Hosting SW | |
3 | - * | |
4 | - * Copyright 2012 NAVER Corp. | |
5 | - * http://yobi.io | |
6 | - * | |
7 | - * @Author Suwon Chae | |
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 org.junit.Ignore; | |
24 | -import org.junit.Test; | |
25 | - | |
26 | -public class SearchAppTest { | |
27 | - @Test | |
28 | - @Ignore | |
29 | - public void testContentsSearch_fromTitle() { | |
30 | - } | |
31 | - | |
32 | - @Test @Ignore | |
33 | - public void findById() { | |
34 | - } | |
35 | -} |
--- test/controllers/SiteAppTest.java
+++ test/controllers/SiteAppTest.java
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 |
import models.*; |
24 | 24 |
import models.enumeration.UserState; |
25 | 25 |
import org.junit.*; |
26 |
+import play.mvc.Result; |
|
26 | 27 |
import play.test.FakeApplication; |
27 | 28 |
import play.test.Helpers; |
28 | 29 |
|
... | ... | @@ -30,52 +31,46 @@ |
30 | 31 |
import java.util.Map; |
31 | 32 |
|
32 | 33 |
import static org.fest.assertions.Assertions.assertThat; |
33 |
-import static play.test.Helpers.callAction; |
|
34 |
-import static play.test.Helpers.fakeRequest; |
|
34 |
+import static play.test.Helpers.*; |
|
35 | 35 |
|
36 | 36 |
public class SiteAppTest { |
37 | 37 |
protected static FakeApplication app; |
38 |
- private User admin; |
|
39 |
- private User notAdmin; |
|
40 | 38 |
|
41 | 39 |
@BeforeClass |
42 | 40 |
public static void beforeClass() { |
43 | 41 |
callAction( |
44 | 42 |
routes.ref.Application.init() |
45 | 43 |
); |
46 |
- } |
|
47 |
- |
|
48 |
- @Before |
|
49 |
- public void before() { |
|
50 |
- Map<String, String> config = support.Helpers.makeTestConfig(); |
|
51 |
- config.put("signup.require.confirm", "true"); |
|
52 |
- app = support.Helpers.makeTestApplication(config); |
|
44 |
+ app = support.Helpers.makeTestApplication(); |
|
53 | 45 |
Helpers.start(app); |
54 | 46 |
} |
55 | 47 |
|
56 |
- @After |
|
57 |
- public void after() { |
|
48 |
+ @AfterClass |
|
49 |
+ public static void afterClass() { |
|
58 | 50 |
Helpers.stop(app); |
59 | 51 |
} |
60 | 52 |
|
61 |
- @Test @Ignore //FixMe I don't know how to make a assert |
|
53 |
+ |
|
54 |
+ @Test |
|
62 | 55 |
public void testToggleUserAccountLock() { |
63 | 56 |
//Given |
64 | 57 |
Map<String,String> data = new HashMap<>(); |
65 | 58 |
final String loginId= "doortts"; |
66 | 59 |
data.put("loginId", loginId); |
60 |
+ User admin = User.find.byId(1L); |
|
67 | 61 |
|
68 |
- User targetUser = User.findByLoginId(loginId); |
|
69 |
- UserState currentIsLocked = targetUser.state; |
|
70 |
- |
|
62 |
+ System.out.println(User.findByLoginId(loginId).state); |
|
71 | 63 |
//When |
72 |
- callAction( |
|
64 |
+ |
|
65 |
+ Result result = callAction( |
|
73 | 66 |
controllers.routes.ref.SiteApp.toggleAccountLock(loginId, "", ""), |
74 |
- fakeRequest() |
|
67 |
+ fakeRequest(POST, routes.SiteApp.toggleAccountLock(loginId, "", "").url()) |
|
75 | 68 |
.withFormUrlEncodedBody(data) |
76 |
- .withSession("loginId", "admin") |
|
77 |
- ); |
|
69 |
+ .withSession("loginId", admin.loginId) |
|
70 |
+ .withSession(UserApp.SESSION_USERID, admin.id.toString())); |
|
78 | 71 |
//Then |
79 |
- assertThat(User.findByLoginId(loginId).state).isNotEqualTo(currentIsLocked); |
|
72 |
+ assertThat(status(result)).isEqualTo(OK); |
|
73 |
+ assertThat(flash(result)).isEmpty(); |
|
74 |
+ assertThat(User.findByLoginId(loginId).state).isEqualTo(UserState.LOCKED); |
|
80 | 75 |
} |
81 | 76 |
} |
--- test/controllers/UserAppTest.java
+++ test/controllers/UserAppTest.java
... | ... | @@ -27,8 +27,12 @@ |
27 | 27 |
|
28 | 28 |
import java.util.*; |
29 | 29 |
|
30 |
+import org.junit.rules.TestWatcher; |
|
30 | 31 |
import play.mvc.*; |
31 | 32 |
import play.mvc.Http.*; |
33 |
+import play.test.FakeApplication; |
|
34 |
+import play.test.Helpers; |
|
35 |
+import support.ExecutionTimeWatcher; |
|
32 | 36 |
import support.ContextTest; |
33 | 37 |
import utils.JodaDateUtil; |
34 | 38 |
|
... | ... | @@ -38,528 +42,417 @@ |
38 | 42 |
import static org.mockito.Mockito.*; |
39 | 43 |
|
40 | 44 |
public class UserAppTest extends ContextTest { |
45 |
+ protected static FakeApplication app; |
|
46 |
+ |
|
47 |
+ @Rule |
|
48 |
+ public TestWatcher watcher = new ExecutionTimeWatcher(); |
|
49 |
+ |
|
41 | 50 |
@BeforeClass |
42 | 51 |
public static void beforeClass() { |
43 | 52 |
callAction( |
44 | 53 |
routes.ref.Application.init() |
45 | 54 |
); |
55 |
+ Map<String, String> config = support.Helpers.makeTestConfig(); |
|
56 |
+ config.put("signup.require.confirm", "true"); |
|
57 |
+ |
|
58 |
+ app = support.Helpers.makeTestApplication(config); |
|
59 |
+ Helpers.start(app); |
|
60 |
+ } |
|
61 |
+ |
|
62 |
+ @AfterClass |
|
63 |
+ public static void afterClass() { |
|
64 |
+ Helpers.stop(app); |
|
46 | 65 |
} |
47 | 66 |
|
48 | 67 |
@Test |
49 | 68 |
public void findById_doesntExist() { |
50 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
51 |
- @Override |
|
52 |
- public void run() { |
|
53 |
- //Given |
|
54 |
- Map<String,String> data = new HashMap<>(); |
|
55 |
- data.put("loginId", "nekure"); |
|
69 |
+ //Given |
|
70 |
+ Map<String,String> data = new HashMap<>(); |
|
71 |
+ data.put("loginId", "nekure"); |
|
56 | 72 |
|
57 |
- //When |
|
58 |
- Result result = callAction( |
|
59 |
- controllers.routes.ref.UserApp.isUsed("nekure"), |
|
60 |
- fakeRequest().withFormUrlEncodedBody(data) |
|
61 |
- ); // fakeRequest doesn't need here, but remains for example |
|
73 |
+ //When |
|
74 |
+ Result result = callAction( |
|
75 |
+ controllers.routes.ref.UserApp.isUsed("nekure"), |
|
76 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
77 |
+ ); // fakeRequest doesn't need here, but remains for example |
|
62 | 78 |
|
63 |
- //Then |
|
64 |
- assertThat(status(result)).isEqualTo(OK); |
|
65 |
- assertThat(contentAsString(result)).contains("\"isExist\":false"); |
|
66 |
- assertThat(contentType(result)).contains("json"); |
|
67 |
- } |
|
68 |
- }); |
|
79 |
+ //Then |
|
80 |
+ assertThat(status(result)).isEqualTo(OK); |
|
81 |
+ assertThat(contentAsString(result)).contains("\"isExist\":false"); |
|
82 |
+ assertThat(contentType(result)).contains("json"); |
|
69 | 83 |
} |
70 | 84 |
|
71 | 85 |
@Test |
72 | 86 |
public void findById_alreadyExist() { |
73 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
74 |
- @Override |
|
75 |
- public void run() { |
|
76 |
- //Given |
|
77 |
- Map<String,String> data = new HashMap<>(); |
|
78 |
- data.put("loginId", "yobi"); |
|
87 |
+ //Given |
|
88 |
+ Map<String,String> data = new HashMap<>(); |
|
89 |
+ data.put("loginId", "yobi"); |
|
79 | 90 |
|
80 |
- //When |
|
81 |
- Result result = callAction( |
|
82 |
- controllers.routes.ref.UserApp.isUsed("yobi"), |
|
83 |
- fakeRequest().withFormUrlEncodedBody(data) |
|
84 |
- ); // fakeRequest doesn't need here, but remains for example |
|
91 |
+ //When |
|
92 |
+ Result result = callAction( |
|
93 |
+ controllers.routes.ref.UserApp.isUsed("yobi"), |
|
94 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
95 |
+ ); // fakeRequest doesn't need here, but remains for example |
|
85 | 96 |
|
86 |
- //Then |
|
87 |
- assertThat(status(result)).isEqualTo(OK); |
|
88 |
- assertThat(contentAsString(result)).contains("\"isExist\":true"); |
|
89 |
- assertThat(contentType(result)).contains("json"); |
|
90 |
- } |
|
91 |
- }); |
|
97 |
+ //Then |
|
98 |
+ assertThat(status(result)).isEqualTo(OK); |
|
99 |
+ assertThat(contentAsString(result)).contains("\"isExist\":true"); |
|
100 |
+ assertThat(contentType(result)).contains("json"); |
|
92 | 101 |
} |
93 | 102 |
|
94 | 103 |
@Test |
95 | 104 |
public void findById_alreadyExistGroupName() { |
96 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
97 |
- @Override |
|
98 |
- public void run() { |
|
99 |
- //Given |
|
100 |
- String loginId = "labs"; |
|
105 |
+ //Given |
|
106 |
+ String loginId = "labs"; |
|
101 | 107 |
|
102 |
- //When |
|
103 |
- Result result = callAction(controllers.routes.ref.UserApp.isUsed(loginId)); |
|
108 |
+ //When |
|
109 |
+ Result result = callAction(controllers.routes.ref.UserApp.isUsed(loginId)); |
|
104 | 110 |
|
105 |
- //Then |
|
106 |
- assertThat(status(result)).isEqualTo(OK); |
|
107 |
- assertThat(contentAsString(result)).contains("\"isExist\":true"); |
|
108 |
- assertThat(contentType(result)).contains("json"); |
|
109 |
- } |
|
110 |
- }); |
|
111 |
+ //Then |
|
112 |
+ assertThat(status(result)).isEqualTo(OK); |
|
113 |
+ assertThat(contentAsString(result)).contains("\"isExist\":true"); |
|
114 |
+ assertThat(contentType(result)).contains("json"); |
|
111 | 115 |
} |
112 | 116 |
|
113 | 117 |
@Test |
114 | 118 |
public void isEmailExist() { |
115 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
116 |
- @Override |
|
117 |
- public void run() { |
|
118 |
- //Given |
|
119 |
- //When |
|
120 |
- Result result = callAction( |
|
121 |
- controllers.routes.ref.UserApp.isEmailExist("doortts@gmail.com") |
|
122 |
- ); |
|
119 |
+ //Given |
|
120 |
+ //When |
|
121 |
+ Result result = callAction( |
|
122 |
+ controllers.routes.ref.UserApp.isEmailExist("doortts@gmail.com") |
|
123 |
+ ); |
|
123 | 124 |
|
124 |
- //Then |
|
125 |
- assertThat(status(result)).isEqualTo(OK); |
|
126 |
- assertThat(contentAsString(result)).contains("{\"isExist\":true}"); |
|
127 |
- } |
|
128 |
- }); |
|
125 |
+ //Then |
|
126 |
+ assertThat(status(result)).isEqualTo(OK); |
|
127 |
+ assertThat(contentAsString(result)).contains("{\"isExist\":true}"); |
|
129 | 128 |
} |
130 | 129 |
|
131 | 130 |
@Test |
132 | 131 |
public void login_notComfirmedUser() { |
133 |
- Map<String, String> config = support.Helpers.makeTestConfig(); |
|
134 |
- config.put("signup.require.confirm", "true"); |
|
132 |
+ //Given |
|
133 |
+ User user = new User(-31l); |
|
134 |
+ user.loginId = "fakeUser"; |
|
135 |
+ user.email = "fakeuser@fake.com"; |
|
136 |
+ user.name = "racoon"; |
|
137 |
+ user.password = "somefakepassword"; |
|
138 |
+ user.createdDate = JodaDateUtil.now(); |
|
139 |
+ user.state = UserState.LOCKED; |
|
140 |
+ user.save(); |
|
135 | 141 |
|
136 |
- running(support.Helpers.makeTestApplication(config), new Runnable() { |
|
137 |
- @Override |
|
138 |
- public void run() { |
|
139 |
- //Given |
|
140 |
- User user = new User(-31l); |
|
141 |
- user.loginId = "fakeUser"; |
|
142 |
- user.email = "fakeuser@fake.com"; |
|
143 |
- user.name = "racoon"; |
|
144 |
- user.password = "somefakepassword"; |
|
145 |
- user.createdDate = JodaDateUtil.now(); |
|
146 |
- user.state = UserState.LOCKED; |
|
147 |
- user.save(); |
|
142 |
+ Map<String, String> data = new HashMap<>(); |
|
143 |
+ data.put("loginIdOrEmail", user.loginId); |
|
144 |
+ data.put("password", user.password); |
|
148 | 145 |
|
149 |
- Map<String, String> data = new HashMap<>(); |
|
150 |
- data.put("loginIdOrEmail", user.loginId); |
|
151 |
- data.put("password", user.password); |
|
146 |
+ //When |
|
147 |
+ Result result = callAction( |
|
148 |
+ controllers.routes.ref.UserApp.login(), |
|
149 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
150 |
+ ); |
|
152 | 151 |
|
153 |
- //When |
|
154 |
- Result result = callAction( |
|
155 |
- controllers.routes.ref.UserApp.login(), |
|
156 |
- fakeRequest().withFormUrlEncodedBody(data) |
|
157 |
- ); |
|
158 |
- |
|
159 |
- //Then |
|
160 |
- assertThat(status(result)).describedAs("result status should '303 see other'").isEqualTo(303); |
|
161 |
- } |
|
162 |
- }); |
|
152 |
+ //Then |
|
153 |
+ assertThat(status(result)).describedAs("result status should '303 see other'").isEqualTo(303); |
|
163 | 154 |
} |
164 | 155 |
|
165 | 156 |
@Test |
166 | 157 |
public void newUser_AlreadyExistGroupName() { |
167 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
168 |
- @Override |
|
169 |
- public void run() { |
|
170 |
- //Given |
|
171 |
- Map<String, String> data = new HashMap<>(); |
|
172 |
- data.put("loginId", "labs"); |
|
173 |
- data.put("password", "somefakepassword"); |
|
174 |
- data.put("email", "labs@fake.com"); |
|
175 |
- data.put("name", "labs"); |
|
158 |
+ //Given |
|
159 |
+ Map<String, String> data = new HashMap<>(); |
|
160 |
+ data.put("loginId", "labs"); |
|
161 |
+ data.put("password", "somefakepassword"); |
|
162 |
+ data.put("email", "labs@fake.com"); |
|
163 |
+ data.put("name", "labs"); |
|
176 | 164 |
|
177 |
- //When |
|
178 |
- Result result = callAction( |
|
179 |
- controllers.routes.ref.UserApp.newUser(), |
|
180 |
- fakeRequest().withFormUrlEncodedBody(data) |
|
181 |
- ); |
|
165 |
+ //When |
|
166 |
+ Result result = callAction( |
|
167 |
+ controllers.routes.ref.UserApp.newUser(), |
|
168 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
169 |
+ ); |
|
182 | 170 |
|
183 |
- //Then |
|
184 |
- assertThat(status(result)).describedAs("result status should '400 bad request'").isEqualTo(BAD_REQUEST); |
|
185 |
- } |
|
186 |
- }); |
|
171 |
+ //Then |
|
172 |
+ assertThat(status(result)).describedAs("result status should '400 bad request'").isEqualTo(BAD_REQUEST); |
|
187 | 173 |
} |
188 | 174 |
|
189 | 175 |
@Test |
190 | 176 |
public void newUser_confirmSignUpMode() { |
191 |
- Map<String, String> config = support.Helpers.makeTestConfig(); |
|
192 |
- config.put("signup.require.confirm", "true"); |
|
177 |
+ //Given |
|
178 |
+ final String loginId = "somefakeuserid"; |
|
179 |
+ Map<String, String> data = new HashMap<>(); |
|
180 |
+ data.put("loginId", loginId); |
|
181 |
+ data.put("password", "somefakepassword"); |
|
182 |
+ data.put("email", "somefakeuserid@fake.com"); |
|
183 |
+ data.put("name", "racoon"); |
|
193 | 184 |
|
194 |
- running(support.Helpers.makeTestApplication(config), new Runnable() { |
|
195 |
- @Override |
|
196 |
- public void run() { |
|
197 |
- //Given |
|
198 |
- final String loginId = "somefakeuserid"; |
|
199 |
- Map<String, String> data = new HashMap<>(); |
|
200 |
- data.put("loginId", loginId); |
|
201 |
- data.put("password", "somefakepassword"); |
|
202 |
- data.put("email", "fakeuser@fake.com"); |
|
203 |
- data.put("name", "racoon"); |
|
185 |
+ //When |
|
186 |
+ Result result = callAction( |
|
187 |
+ controllers.routes.ref.UserApp.newUser(), |
|
188 |
+ fakeRequest().withFormUrlEncodedBody(data) |
|
189 |
+ ); |
|
204 | 190 |
|
205 |
- //When |
|
206 |
- Result result = callAction( |
|
207 |
- controllers.routes.ref.UserApp.newUser(), |
|
208 |
- fakeRequest().withFormUrlEncodedBody(data) |
|
209 |
- ); |
|
210 |
- |
|
211 |
- //Then |
|
212 |
- assertThat(status(result)).describedAs("result status should '303 see other'").isEqualTo(303); |
|
213 |
- } |
|
214 |
- }); |
|
191 |
+ //Then |
|
192 |
+ assertThat(status(result)).describedAs("result status should '303 see other'").isEqualTo(303); |
|
215 | 193 |
} |
216 | 194 |
|
217 | 195 |
@Test |
218 | 196 |
public void findById_reserved() { |
219 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
220 |
- @Override |
|
221 |
- public void run() { |
|
222 |
- //Given |
|
223 |
- Map<String,String> data = new HashMap<>(); |
|
224 |
- data.put("loginId", "messages.js"); |
|
197 |
+ //Given |
|
198 |
+ Map<String,String> data = new HashMap<>(); |
|
199 |
+ data.put("loginId", "messages.js"); |
|
225 | 200 |
|
226 |
- //When |
|
227 |
- Result result = callAction(controllers.routes.ref.UserApp.isUsed("messages.js")); |
|
201 |
+ //When |
|
202 |
+ Result result = callAction(controllers.routes.ref.UserApp.isUsed("messages.js")); |
|
228 | 203 |
|
229 |
- //Then |
|
230 |
- assertThat(status(result)).isEqualTo(OK); |
|
231 |
- assertThat(contentAsString(result)).contains("\"isReserved\":true"); |
|
232 |
- assertThat(contentType(result)).contains("json"); |
|
233 |
- } |
|
234 |
- }); |
|
204 |
+ //Then |
|
205 |
+ assertThat(status(result)).isEqualTo(OK); |
|
206 |
+ assertThat(contentAsString(result)).contains("\"isReserved\":true"); |
|
207 |
+ assertThat(contentType(result)).contains("json"); |
|
235 | 208 |
} |
236 | 209 |
|
237 | 210 |
@Test |
238 | 211 |
public void authenticateWithPlainPassword() { |
239 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
240 |
- @Override |
|
241 |
- public void run() { |
|
242 |
- // Given |
|
243 |
- String loginId = "kjkmadness"; |
|
244 |
- String password = "pass"; |
|
212 |
+ // Given |
|
213 |
+ String loginId = "kjkmadness"; |
|
214 |
+ String password = "pass"; |
|
245 | 215 |
|
246 |
- // When |
|
247 |
- User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
216 |
+ // When |
|
217 |
+ User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
248 | 218 |
|
249 |
- // Then |
|
250 |
- assertThat(user).isNotNull(); |
|
251 |
- assertThat(user.isAnonymous()).isFalse(); |
|
252 |
- assertThat(user.loginId).isEqualTo(loginId); |
|
253 |
- } |
|
254 |
- }); |
|
219 |
+ // Then |
|
220 |
+ assertThat(user).isNotNull(); |
|
221 |
+ assertThat(user.isAnonymous()).isFalse(); |
|
222 |
+ assertThat(user.loginId).isEqualTo(loginId); |
|
255 | 223 |
} |
256 | 224 |
|
257 | 225 |
@Test |
258 | 226 |
public void authenticateWithPlainPasswordWrongPassword() { |
259 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
260 |
- @Override |
|
261 |
- public void run() { |
|
262 |
- // Given |
|
263 |
- String loginId = "kjkmadness"; |
|
264 |
- String password = "wrong"; |
|
227 |
+ // Given |
|
228 |
+ String loginId = "kjkmadness"; |
|
229 |
+ String password = "wrong"; |
|
265 | 230 |
|
266 |
- // When |
|
267 |
- User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
231 |
+ // When |
|
232 |
+ User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
268 | 233 |
|
269 |
- // Then |
|
270 |
- assertThat(user).isNotNull(); |
|
271 |
- assertThat(user.isAnonymous()).isTrue(); |
|
272 |
- } |
|
273 |
- }); |
|
234 |
+ // Then |
|
235 |
+ assertThat(user).isNotNull(); |
|
236 |
+ assertThat(user.isAnonymous()).isTrue(); |
|
274 | 237 |
} |
275 | 238 |
|
276 | 239 |
@Test |
277 | 240 |
public void authenticateWithPlainPasswordNotExist() { |
278 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
279 |
- @Override |
|
280 |
- public void run() { |
|
281 |
- // Given |
|
282 |
- String loginId = "notexist"; |
|
283 |
- String password = "pass"; |
|
241 |
+ // Given |
|
242 |
+ String loginId = "notexist"; |
|
243 |
+ String password = "pass"; |
|
284 | 244 |
|
285 |
- // When |
|
286 |
- User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
245 |
+ // When |
|
246 |
+ User user = UserApp.authenticateWithPlainPassword(loginId, password); |
|
287 | 247 |
|
288 |
- // Then |
|
289 |
- assertThat(user).isNotNull(); |
|
290 |
- assertThat(user.isAnonymous()).isTrue(); |
|
291 |
- } |
|
292 |
- }); |
|
248 |
+ // Then |
|
249 |
+ assertThat(user).isNotNull(); |
|
250 |
+ assertThat(user.isAnonymous()).isTrue(); |
|
293 | 251 |
} |
294 | 252 |
|
295 | 253 |
@Test |
296 | 254 |
public void authenticateWithHashedPassword() { |
297 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
298 |
- @Override |
|
299 |
- public void run() { |
|
300 |
- // Given |
|
301 |
- String loginId = "kjkmadness"; |
|
302 |
- String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
255 |
+ // Given |
|
256 |
+ String loginId = "kjkmadness"; |
|
257 |
+ String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
303 | 258 |
|
304 |
- // When |
|
305 |
- User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
259 |
+ // When |
|
260 |
+ User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
306 | 261 |
|
307 |
- // Then |
|
308 |
- assertThat(user).isNotNull(); |
|
309 |
- assertThat(user.isAnonymous()).isFalse(); |
|
310 |
- assertThat(user.loginId).isEqualTo(loginId); |
|
311 |
- } |
|
312 |
- }); |
|
262 |
+ // Then |
|
263 |
+ assertThat(user).isNotNull(); |
|
264 |
+ assertThat(user.isAnonymous()).isFalse(); |
|
265 |
+ assertThat(user.loginId).isEqualTo(loginId); |
|
313 | 266 |
} |
314 | 267 |
|
315 | 268 |
@Test |
316 | 269 |
public void authenticateWithHashedPasswordWrongPassword() { |
317 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
318 |
- @Override |
|
319 |
- public void run() { |
|
320 |
- // Given |
|
321 |
- String loginId = "kjkmadness"; |
|
322 |
- String password = "wrong"; |
|
270 |
+ // Given |
|
271 |
+ String loginId = "kjkmadness"; |
|
272 |
+ String password = "wrong"; |
|
323 | 273 |
|
324 |
- // When |
|
325 |
- User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
274 |
+ // When |
|
275 |
+ User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
326 | 276 |
|
327 |
- // Then |
|
328 |
- assertThat(user).isNotNull(); |
|
329 |
- assertThat(user.isAnonymous()).isTrue(); |
|
330 |
- } |
|
331 |
- }); |
|
277 |
+ // Then |
|
278 |
+ assertThat(user).isNotNull(); |
|
279 |
+ assertThat(user.isAnonymous()).isTrue(); |
|
332 | 280 |
} |
333 | 281 |
|
334 | 282 |
@Test |
335 | 283 |
public void authenticateWithHashedPasswordNotExist() { |
336 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
337 |
- @Override |
|
338 |
- public void run() { |
|
339 |
- // Given |
|
340 |
- String loginId = "notexist"; |
|
341 |
- String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
284 |
+ // Given |
|
285 |
+ String loginId = "notexist"; |
|
286 |
+ String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
342 | 287 |
|
343 |
- // When |
|
344 |
- User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
288 |
+ // When |
|
289 |
+ User user = UserApp.authenticateWithHashedPassword(loginId, password); |
|
345 | 290 |
|
346 |
- // Then |
|
347 |
- assertThat(user).isNotNull(); |
|
348 |
- assertThat(user.isAnonymous()).isTrue(); |
|
349 |
- } |
|
350 |
- }); |
|
291 |
+ // Then |
|
292 |
+ assertThat(user).isNotNull(); |
|
293 |
+ assertThat(user.isAnonymous()).isTrue(); |
|
351 | 294 |
} |
352 | 295 |
|
353 | 296 |
@Test |
354 | 297 |
public void login() { |
355 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
356 |
- @Override |
|
357 |
- public void run() { |
|
358 |
- // Given |
|
359 |
- String loginId = "kjkmadness"; |
|
360 |
- String password = "pass"; |
|
361 |
- User user = User.findByLoginId(loginId); |
|
362 |
- Map<String, String> data = new HashMap<>(); |
|
363 |
- data.put("loginIdOrEmail", loginId); |
|
364 |
- data.put("password", password); |
|
298 |
+ // Given |
|
299 |
+ String loginId = "kjkmadness"; |
|
300 |
+ String password = "pass"; |
|
301 |
+ User user = User.findByLoginId(loginId); |
|
302 |
+ Map<String, String> data = new HashMap<>(); |
|
303 |
+ data.put("loginIdOrEmail", loginId); |
|
304 |
+ data.put("password", password); |
|
365 | 305 |
|
366 |
- // When |
|
367 |
- Result result = callAction(controllers.routes.ref.UserApp.login(), fakeRequest() |
|
368 |
- .withFormUrlEncodedBody(data)); |
|
306 |
+ // When |
|
307 |
+ Result result = callAction(controllers.routes.ref.UserApp.login(), fakeRequest() |
|
308 |
+ .withFormUrlEncodedBody(data)); |
|
369 | 309 |
|
370 |
- // Then |
|
371 |
- assertThat(status(result)).isEqualTo(SEE_OTHER); |
|
372 |
- assertThat(header(LOCATION, result)).isEqualTo(routes.Application.index().url()); |
|
373 |
- assertThat(session(result)).includes( |
|
374 |
- entry(UserApp.SESSION_USERID, String.valueOf(user.id)), |
|
375 |
- entry(UserApp.SESSION_LOGINID, user.loginId), |
|
376 |
- entry(UserApp.SESSION_USERNAME, user.name)); |
|
377 |
- } |
|
378 |
- }); |
|
310 |
+ // Then |
|
311 |
+ assertThat(status(result)).isEqualTo(SEE_OTHER); |
|
312 |
+ assertThat(header(LOCATION, result)).isEqualTo(routes.Application.index().url()); |
|
313 |
+ assertThat(session(result)).includes( |
|
314 |
+ entry(UserApp.SESSION_USERID, String.valueOf(user.id)), |
|
315 |
+ entry(UserApp.SESSION_LOGINID, user.loginId), |
|
316 |
+ entry(UserApp.SESSION_USERNAME, user.name)); |
|
379 | 317 |
} |
380 | 318 |
|
381 | 319 |
@Test |
382 | 320 |
public void loginWrongPassword() { |
383 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
384 |
- @Override |
|
385 |
- public void run() { |
|
386 |
- // Given |
|
387 |
- String loginId = "kjkmadness"; |
|
388 |
- String password = "wrong"; |
|
389 |
- Map<String, String> data = new HashMap<>(); |
|
390 |
- data.put("loginIdOrEmail", loginId); |
|
391 |
- data.put("password", password); |
|
321 |
+ // Given |
|
322 |
+ String loginId = "kjkmadness"; |
|
323 |
+ String password = "wrong"; |
|
324 |
+ Map<String, String> data = new HashMap<>(); |
|
325 |
+ data.put("loginIdOrEmail", loginId); |
|
326 |
+ data.put("password", password); |
|
392 | 327 |
|
393 |
- // When |
|
394 |
- Result result = callAction(controllers.routes.ref.UserApp.login(), fakeRequest() |
|
395 |
- .withFormUrlEncodedBody(data)); |
|
328 |
+ // When |
|
329 |
+ Result result = callAction(controllers.routes.ref.UserApp.login(), fakeRequest() |
|
330 |
+ .withFormUrlEncodedBody(data)); |
|
396 | 331 |
|
397 |
- // Then |
|
398 |
- assertThat(status(result)).isEqualTo(SEE_OTHER); |
|
399 |
- assertThat(header(LOCATION, result)).isEqualTo(routes.UserApp.loginForm().url()); |
|
400 |
- assertThat(session(result)).isEmpty(); |
|
401 |
- } |
|
402 |
- }); |
|
332 |
+ // Then |
|
333 |
+ assertThat(status(result)).isEqualTo(SEE_OTHER); |
|
334 |
+ assertThat(header(LOCATION, result)).isEqualTo(routes.UserApp.loginForm().url()); |
|
335 |
+ assertThat(session(result)).isEmpty(); |
|
403 | 336 |
} |
404 | 337 |
|
405 | 338 |
@Test |
406 | 339 |
public void currentUserContext() { |
407 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
408 |
- @Override |
|
409 |
- public void run() { |
|
410 |
- // Given |
|
411 |
- User expected = User.find.byId(1L); |
|
412 |
- context().withArg(UserApp.TOKEN_USER, expected); |
|
340 |
+ // Given |
|
341 |
+ User expected = User.find.byId(1L); |
|
342 |
+ context().withArg(UserApp.TOKEN_USER, expected); |
|
413 | 343 |
|
414 |
- // When |
|
415 |
- User user = UserApp.currentUser(); |
|
344 |
+ // When |
|
345 |
+ User user = UserApp.currentUser(); |
|
416 | 346 |
|
417 |
- // Then |
|
418 |
- assertThat(user).isEqualTo(expected); |
|
419 |
- } |
|
420 |
- }); |
|
347 |
+ // Then |
|
348 |
+ assertThat(user).isEqualTo(expected); |
|
421 | 349 |
} |
422 | 350 |
|
423 | 351 |
@Test |
424 | 352 |
public void currentUserSession() { |
425 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
426 |
- @Override |
|
427 |
- public void run() { |
|
428 |
- // Given |
|
429 |
- Long id = 1L; |
|
430 |
- context().withSession(UserApp.SESSION_USERID, String.valueOf(id)); |
|
353 |
+ // Given |
|
354 |
+ Long id = 1L; |
|
355 |
+ context().withSession(UserApp.SESSION_USERID, String.valueOf(id)); |
|
431 | 356 |
|
432 |
- // When |
|
433 |
- User user = UserApp.currentUser(); |
|
357 |
+ // When |
|
358 |
+ User user = UserApp.currentUser(); |
|
434 | 359 |
|
435 |
- // Then |
|
436 |
- assertThat(user).isNotEqualTo(User.anonymous); |
|
437 |
- assertThat(user.id).isEqualTo(id); |
|
438 |
- } |
|
439 |
- }); |
|
360 |
+ // Then |
|
361 |
+ assertThat(user).isNotEqualTo(User.anonymous); |
|
362 |
+ assertThat(user.id).isEqualTo(id); |
|
440 | 363 |
} |
441 | 364 |
|
442 | 365 |
@Test |
443 | 366 |
public void currentUserSessionNotNumeric() { |
444 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
445 |
- @Override |
|
446 |
- public void run() { |
|
447 |
- // Given |
|
448 |
- Context context = context().withSession(UserApp.SESSION_USERID, "string"); |
|
367 |
+ // Given |
|
368 |
+ Context context = context().withSession(UserApp.SESSION_USERID, "string"); |
|
449 | 369 |
|
450 |
- // When |
|
451 |
- User user = UserApp.currentUser(); |
|
370 |
+ // When |
|
371 |
+ User user = UserApp.currentUser(); |
|
452 | 372 |
|
453 |
- // Then |
|
454 |
- assertThat(user).isEqualTo(User.anonymous); |
|
455 |
- assertThat(context.session()).isEmpty(); |
|
456 |
- } |
|
457 |
- }); |
|
373 |
+ // Then |
|
374 |
+ assertThat(user).isEqualTo(User.anonymous); |
|
375 |
+ assertThat(context.session()).isEmpty(); |
|
458 | 376 |
} |
459 | 377 |
|
460 | 378 |
@Test |
461 | 379 |
public void currentUserSessionNoUser() { |
462 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
463 |
- @Override |
|
464 |
- public void run() { |
|
465 |
- // Given |
|
466 |
- Context context = context().withSession(UserApp.SESSION_USERID, "0"); |
|
380 |
+ // Given |
|
381 |
+ Context context = context().withSession(UserApp.SESSION_USERID, "0"); |
|
467 | 382 |
|
468 |
- // When |
|
469 |
- User user = UserApp.currentUser(); |
|
383 |
+ // When |
|
384 |
+ User user = UserApp.currentUser(); |
|
470 | 385 |
|
471 |
- // Then |
|
472 |
- assertThat(user).isEqualTo(User.anonymous); |
|
473 |
- assertThat(context.session()).isEmpty(); |
|
474 |
- } |
|
475 |
- }); |
|
386 |
+ // Then |
|
387 |
+ assertThat(user).isEqualTo(User.anonymous); |
|
388 |
+ assertThat(context.session()).isEmpty(); |
|
476 | 389 |
} |
477 | 390 |
|
478 | 391 |
@Test |
479 | 392 |
public void currentUserToken() { |
480 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
481 |
- @Override |
|
482 |
- public void run() { |
|
483 |
- // Given |
|
484 |
- String loginId = "kjkmadness"; |
|
485 |
- String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
486 |
- String token = loginId + UserApp.TOKEN_SEPARATOR + password; |
|
487 |
- Context context = context().withCookie(UserApp.TOKEN, token); |
|
393 |
+ // Given |
|
394 |
+ String loginId = "kjkmadness"; |
|
395 |
+ String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
396 |
+ String token = loginId + UserApp.TOKEN_SEPARATOR + password; |
|
397 |
+ Context context = context().withCookie(UserApp.TOKEN, token); |
|
488 | 398 |
|
489 |
- // When |
|
490 |
- User user = UserApp.currentUser(); |
|
399 |
+ // When |
|
400 |
+ User user = UserApp.currentUser(); |
|
491 | 401 |
|
492 |
- // Then |
|
493 |
- assertThat(user).isNotEqualTo(User.anonymous); |
|
494 |
- assertThat(user.loginId).isEqualTo(loginId); |
|
495 |
- assertThat(context.session()).includes( |
|
496 |
- entry(UserApp.SESSION_USERID, String.valueOf(user.id)), |
|
497 |
- entry(UserApp.SESSION_LOGINID, user.loginId), |
|
498 |
- entry(UserApp.SESSION_USERNAME, user.name)); |
|
499 |
- } |
|
500 |
- }); |
|
402 |
+ // Then |
|
403 |
+ assertThat(user).isNotEqualTo(User.anonymous); |
|
404 |
+ assertThat(user.loginId).isEqualTo(loginId); |
|
405 |
+ assertThat(context.session()).includes( |
|
406 |
+ entry(UserApp.SESSION_USERID, String.valueOf(user.id)), |
|
407 |
+ entry(UserApp.SESSION_LOGINID, user.loginId), |
|
408 |
+ entry(UserApp.SESSION_USERNAME, user.name)); |
|
501 | 409 |
} |
502 | 410 |
|
503 | 411 |
@Test |
504 | 412 |
public void currentUserTokenInvalidLength() { |
505 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
506 |
- @Override |
|
507 |
- public void run() { |
|
508 |
- // Given |
|
509 |
- String loginId = "kjkmadness"; |
|
510 |
- String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
511 |
- String token = loginId + UserApp.TOKEN_SEPARATOR + password |
|
512 |
- + UserApp.TOKEN_SEPARATOR + "dummy"; |
|
513 |
- Context context = context().withCookie(UserApp.TOKEN, token); |
|
413 |
+ // Given |
|
414 |
+ String loginId = "kjkmadness"; |
|
415 |
+ String password = "ckJUVVaOHhRDNqwbeF+j4RNqXzodXO95+aQRIbJnDK4="; |
|
416 |
+ String token = loginId + UserApp.TOKEN_SEPARATOR + password |
|
417 |
+ + UserApp.TOKEN_SEPARATOR + "dummy"; |
|
418 |
+ Context context = context().withCookie(UserApp.TOKEN, token); |
|
514 | 419 |
|
515 |
- // When |
|
516 |
- User user = UserApp.currentUser(); |
|
420 |
+ // When |
|
421 |
+ User user = UserApp.currentUser(); |
|
517 | 422 |
|
518 |
- // Then |
|
519 |
- assertThat(user).isEqualTo(User.anonymous); |
|
520 |
- assertThat(context.session()).isEmpty(); |
|
521 |
- verify(context.response()).discardCookie(UserApp.TOKEN); |
|
522 |
- } |
|
523 |
- }); |
|
423 |
+ // Then |
|
424 |
+ assertThat(user).isEqualTo(User.anonymous); |
|
425 |
+ assertThat(context.session()).isEmpty(); |
|
426 |
+ verify(context.response()).discardCookie(UserApp.TOKEN); |
|
524 | 427 |
} |
525 | 428 |
|
526 | 429 |
@Test |
527 | 430 |
public void currentUserTokenNoUser() { |
528 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
529 |
- @Override |
|
530 |
- public void run() { |
|
531 |
- // Given |
|
532 |
- String loginId = "kjkmadness"; |
|
533 |
- String password = "dummy"; |
|
534 |
- String token = loginId + UserApp.TOKEN_SEPARATOR + password; |
|
535 |
- Context context = context().withCookie(UserApp.TOKEN, token); |
|
431 |
+ // Given |
|
432 |
+ String loginId = "kjkmadness"; |
|
433 |
+ String password = "dummy"; |
|
434 |
+ String token = loginId + UserApp.TOKEN_SEPARATOR + password; |
|
435 |
+ Context context = context().withCookie(UserApp.TOKEN, token); |
|
536 | 436 |
|
537 |
- // When |
|
538 |
- User user = UserApp.currentUser(); |
|
437 |
+ // When |
|
438 |
+ User user = UserApp.currentUser(); |
|
539 | 439 |
|
540 |
- // Then |
|
541 |
- assertThat(user).isEqualTo(User.anonymous); |
|
542 |
- assertThat(context.session()).isEmpty(); |
|
543 |
- verify(context.response()).discardCookie(UserApp.TOKEN); |
|
544 |
- } |
|
545 |
- }); |
|
440 |
+ // Then |
|
441 |
+ assertThat(user).isEqualTo(User.anonymous); |
|
442 |
+ assertThat(context.session()).isEmpty(); |
|
443 |
+ verify(context.response()).discardCookie(UserApp.TOKEN); |
|
546 | 444 |
} |
547 | 445 |
|
548 | 446 |
@Test |
549 | 447 |
public void currentUserAnonymous() { |
550 |
- running(support.Helpers.makeTestApplication(), new Runnable() { |
|
551 |
- @Override |
|
552 |
- public void run() { |
|
553 |
- // Given |
|
554 |
- Context context = context(); |
|
448 |
+ // Given |
|
449 |
+ Context context = context(); |
|
555 | 450 |
|
556 |
- // When |
|
557 |
- User user = UserApp.currentUser(); |
|
451 |
+ // When |
|
452 |
+ User user = UserApp.currentUser(); |
|
558 | 453 |
|
559 |
- // Then |
|
560 |
- assertThat(user).isEqualTo(User.anonymous); |
|
561 |
- assertThat(context.session()).isEmpty(); |
|
562 |
- } |
|
563 |
- }); |
|
454 |
+ // Then |
|
455 |
+ assertThat(user).isEqualTo(User.anonymous); |
|
456 |
+ assertThat(context.session()).isEmpty(); |
|
564 | 457 |
} |
565 | 458 |
} |
--- test/controllers/WatchProjectAppTest.java
+++ test/controllers/WatchProjectAppTest.java
... | ... | @@ -31,27 +31,32 @@ |
31 | 31 |
import models.enumeration.EventType; |
32 | 32 |
import models.enumeration.ProjectScope; |
33 | 33 |
|
34 |
-import org.junit.After; |
|
35 |
-import org.junit.Before; |
|
36 |
-import org.junit.Test; |
|
34 |
+import org.junit.*; |
|
37 | 35 |
|
38 | 36 |
import play.mvc.Http; |
39 | 37 |
import play.mvc.Result; |
40 | 38 |
import play.test.FakeApplication; |
41 | 39 |
import play.test.FakeRequest; |
40 |
+import play.test.Helpers; |
|
41 |
+ |
|
42 |
+import java.util.Map; |
|
42 | 43 |
|
43 | 44 |
public class WatchProjectAppTest { |
44 |
- private static FakeApplication app; |
|
45 |
+ protected static FakeApplication app; |
|
45 | 46 |
|
46 |
- @Before |
|
47 |
- public void before() { |
|
47 |
+ @BeforeClass |
|
48 |
+ public static void beforeClass() { |
|
49 |
+ callAction( |
|
50 |
+ routes.ref.Application.init() |
|
51 |
+ ); |
|
52 |
+ |
|
48 | 53 |
app = support.Helpers.makeTestApplication(); |
49 |
- start(app); |
|
54 |
+ Helpers.start(app); |
|
50 | 55 |
} |
51 | 56 |
|
52 |
- @After |
|
53 |
- public void after() { |
|
54 |
- stop(app); |
|
57 |
+ @AfterClass |
|
58 |
+ public static void afterClass() { |
|
59 |
+ Helpers.stop(app); |
|
55 | 60 |
} |
56 | 61 |
|
57 | 62 |
@Test |
--- test/models/ModelTest.java
+++ test/models/ModelTest.java
... | ... | @@ -21,7 +21,9 @@ |
21 | 21 |
package models; |
22 | 22 |
|
23 | 23 |
import org.junit.After; |
24 |
+import org.junit.AfterClass; |
|
24 | 25 |
import org.junit.Before; |
26 |
+import org.junit.BeforeClass; |
|
25 | 27 |
import play.test.FakeApplication; |
26 | 28 |
import play.test.Helpers; |
27 | 29 |
//import support.EbeanUtil; |
... | ... | @@ -36,7 +38,7 @@ |
36 | 38 |
} |
37 | 39 |
|
38 | 40 |
@Before |
39 |
- public void startApp() { |
|
41 |
+ public void startApp() { |
|
40 | 42 |
app = support.Helpers.makeTestApplication(); |
41 | 43 |
Helpers.start(app); |
42 | 44 |
} |
--- test/models/PasswordResetTest.java
+++ test/models/PasswordResetTest.java
... | ... | @@ -156,14 +156,14 @@ |
156 | 156 |
|
157 | 157 |
//Then |
158 | 158 |
assertThat(result).isTrue(); |
159 |
- assertThat(UserApp.authenticateWithPlainPassword(userId, newPassword).isAnonymous()).isFalse(); |
|
159 |
+ assertThat(UserApp.authenticateWithPlainPassword(userId, newPassword)).isEqualTo(User.findByLoginId(userId)); |
|
160 | 160 |
} |
161 | 161 |
|
162 | 162 |
@Test |
163 | 163 |
public void testResetPassword_wrongHash() { |
164 | 164 |
//Given |
165 | 165 |
String userId = "doortts"; |
166 |
- String newPassword = "whffudy"; |
|
166 |
+ String newPassword = "gomdol"; |
|
167 | 167 |
String hashString = PasswordReset.generateResetHash(userId); |
168 | 168 |
PasswordReset.addHashToResetTable(userId, hashString); |
169 | 169 |
|
... | ... | @@ -173,7 +173,7 @@ |
173 | 173 |
|
174 | 174 |
//Then |
175 | 175 |
assertThat(result).isFalse(); |
176 |
- assertThat(UserApp.authenticateWithPlainPassword(userId, newPassword).isAnonymous()).isTrue(); |
|
176 |
+ assertThat(UserApp.authenticateWithPlainPassword(userId, newPassword)).isEqualTo(User.anonymous); |
|
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
private static boolean hashStringExist(String loginId) { |
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
... | ... | @@ -30,18 +30,15 @@ |
30 | 30 |
import org.eclipse.jgit.api.CommitCommand; |
31 | 31 |
import org.eclipse.jgit.api.Git; |
32 | 32 |
import org.eclipse.jgit.api.errors.GitAPIException; |
33 |
-import org.eclipse.jgit.api.errors.NoFilepatternException; |
|
34 | 33 |
import org.eclipse.jgit.lib.*; |
35 | 34 |
import org.eclipse.jgit.revwalk.RevCommit; |
36 | 35 |
import org.eclipse.jgit.revwalk.RevTree; |
37 | 36 |
import org.eclipse.jgit.revwalk.RevWalk; |
38 | 37 |
import org.eclipse.jgit.transport.RefSpec; |
39 | 38 |
import org.eclipse.jgit.treewalk.TreeWalk; |
40 |
-import org.junit.After; |
|
41 |
-import org.junit.Before; |
|
42 |
-import org.junit.Ignore; |
|
43 |
-import org.junit.Test; |
|
39 |
+import org.junit.*; |
|
44 | 40 |
|
41 |
+import org.junit.rules.TestWatcher; |
|
45 | 42 |
import play.test.FakeApplication; |
46 | 43 |
import play.test.Helpers; |
47 | 44 |
|
... | ... | @@ -57,6 +54,9 @@ |
57 | 54 |
import static org.fest.assertions.Fail.fail; |
58 | 55 |
|
59 | 56 |
public class GitRepositoryTest { |
57 |
+ |
|
58 |
+ @Rule |
|
59 |
+ public TestWatcher watcher = new ExecutionTimeWatcher(); |
|
60 | 60 |
|
61 | 61 |
@Before |
62 | 62 |
public void before() { |
... | ... | @@ -321,18 +321,6 @@ |
321 | 321 |
} |
322 | 322 |
} |
323 | 323 |
}); |
324 |
- } |
|
325 |
- |
|
326 |
- @Ignore |
|
327 |
- @Test |
|
328 |
- public void getRawFile() throws Exception { |
|
329 |
- // Given |
|
330 |
- String userName = "yobi"; |
|
331 |
- String projectName = "testProject"; |
|
332 |
- GitRepository repo = new GitRepository(userName, projectName); |
|
333 |
- // When |
|
334 |
- repo.getRawFile("HEAD", "readme"); |
|
335 |
- // Then |
|
336 | 324 |
} |
337 | 325 |
|
338 | 326 |
@Test |
--- test/playRepository/ExecutionTimeWatcher.java
+++ test/support/ExecutionTimeWatcher.java
... | ... | @@ -1,4 +1,4 @@ |
1 |
-package playRepository; |
|
1 |
+package support; |
|
2 | 2 |
|
3 | 3 |
import org.joda.time.DateTime; |
4 | 4 |
import org.joda.time.Interval; |
--- test/support/Helpers.java
+++ test/support/Helpers.java
... | ... | @@ -70,11 +70,11 @@ |
70 | 70 |
return makeTestApplicationWithServiceGlobal(makeTestConfig()); |
71 | 71 |
} |
72 | 72 |
|
73 |
- private static void insertInitialData() { |
|
73 |
+ public static void insertInitialData() { |
|
74 | 74 |
YamlUtil.insertDataFromYaml("initial-data.yml", new String[] {"users", "roles", "siteAdmins"}); |
75 | 75 |
} |
76 | 76 |
|
77 |
- private static void insertTestData() { |
|
77 |
+ public static void insertTestData() { |
|
78 | 78 |
YamlUtil.insertDataFromYaml("test-data.yml", new String[] { |
79 | 79 |
"users", "projects", "pullRequests", "milestones", |
80 | 80 |
"issues", "issueComments", "postings", |
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?