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

Test: enhanced tests' performance for tests in models package
@94f0d9f733fbdada675538a0bf8f23e19d3c7bbb
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
... | ... | @@ -934,10 +934,4 @@ |
934 | 934 |
return this.isConflict == false && |
935 | 935 |
this.mergedCommitIdFrom != null && this.mergedCommitIdTo != null; |
936 | 936 |
} |
937 |
- |
|
938 |
- @Override |
|
939 |
- public Object clone() throws CloneNotSupportedException { |
|
940 |
- PullRequest cloned = (PullRequest)super.clone(); |
|
941 |
- return cloned; |
|
942 |
- } |
|
943 | 937 |
} |
--- app/models/Role.java
+++ app/models/Role.java
... | ... | @@ -34,7 +34,7 @@ |
34 | 34 |
@Entity |
35 | 35 |
public class Role extends Model { |
36 | 36 |
private static final long serialVersionUID = 1L; |
37 |
- private static Finder<Long, Role> find = new Finder<>(Long.class, |
|
37 |
+ public static Finder<Long, Role> find = new Finder<>(Long.class, |
|
38 | 38 |
Role.class); |
39 | 39 |
|
40 | 40 |
@Id |
--- conf/test-data.yml
+++ conf/test-data.yml
... | ... | @@ -24,7 +24,6 @@ |
24 | 24 |
state: ACTIVE |
25 | 25 |
email: doortts@gmail.com |
26 | 26 |
createdDate: 2012-07-01 08:00:00 |
27 |
- state: ACTIVE |
|
28 | 27 |
- !!models.User |
29 | 28 |
name: eungjun |
30 | 29 |
loginId: nori |
--- test/controllers/PullRequestAppTest.java
+++ test/controllers/PullRequestAppTest.java
... | ... | @@ -174,16 +174,26 @@ |
174 | 174 |
|
175 | 175 |
@Test |
176 | 176 |
public void testOpenPullRequestBadRequest() throws Exception { |
177 |
+ //Given |
|
177 | 178 |
initParameters("yobi", "projectYobi", 1L); |
178 | 179 |
User currentUser = User.findByLoginId("admin"); |
179 | 180 |
|
181 |
+ User projectOwner = User.findByLoginId("yobi"); |
|
182 |
+ |
|
183 |
+ final String uri = "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber; |
|
184 |
+ callAction( |
|
185 |
+ controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), |
|
186 |
+ fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, projectOwner.id.toString()) |
|
187 |
+ ); |
|
188 |
+ |
|
189 |
+ //When |
|
180 | 190 |
Result result = callAction( |
181 | 191 |
controllers.routes.ref.PullRequestApp.open(ownerLoginId, projectName, pullRequestNumber), |
182 |
- fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/pullRequest/" + pullRequestNumber) |
|
183 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
192 |
+ fakeRequest("GET", uri).withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
184 | 193 |
); |
185 | 194 |
|
186 |
- assertThat(status(result)).isEqualTo(BAD_REQUEST); |
|
195 |
+ //Then |
|
196 |
+ assertThat(status(result)).isEqualTo(BAD_REQUEST).describedAs("open already opened"); |
|
187 | 197 |
} |
188 | 198 |
|
189 | 199 |
@Test |
... | ... | @@ -230,8 +240,8 @@ |
230 | 240 |
Result result = callAction( |
231 | 241 |
controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), |
232 | 242 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") |
233 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
234 |
- ); |
|
243 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
244 |
+ ); |
|
235 | 245 |
|
236 | 246 |
assertThat(status(result)).isEqualTo(OK); |
237 | 247 |
} |
... | ... | @@ -244,8 +254,8 @@ |
244 | 254 |
Result result = callAction( |
245 | 255 |
controllers.routes.ref.PullRequestApp.newFork(ownerLoginId, projectName, null), |
246 | 256 |
fakeRequest("GET", "/" + ownerLoginId + "/" + projectName + "/newFork") |
247 |
- .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
248 |
- ); |
|
257 |
+ .withSession(UserApp.SESSION_USERID, currentUser.id.toString()) |
|
258 |
+ ); |
|
249 | 259 |
|
250 | 260 |
assertThat(status(result)).isEqualTo(OK); |
251 | 261 |
|
--- test/models/CommentThreadTest.java
+++ test/models/CommentThreadTest.java
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 |
package models; |
22 | 22 |
|
23 | 23 |
import org.apache.shiro.util.ThreadState; |
24 |
+import org.junit.After; |
|
24 | 25 |
import org.junit.Test; |
25 | 26 |
import org.junit.Before; |
26 | 27 |
import utils.JodaDateUtil; |
... | ... | @@ -45,6 +46,8 @@ |
45 | 46 |
private User anonymous; |
46 | 47 |
private Project project; |
47 | 48 |
private SimpleCommentThread thread; |
49 |
+ private List<Long> threadIds; |
|
50 |
+ String commitId = "123123"; |
|
48 | 51 |
|
49 | 52 |
@Before |
50 | 53 |
public void before() { |
... | ... | @@ -68,14 +71,20 @@ |
68 | 71 |
assertThat(ProjectUser.isMember(member.id, project.id)).describedAs("member is a member").isTrue(); |
69 | 72 |
assertThat(ProjectUser.isMember(author.id, project.id)).describedAs("author is not a member").isFalse(); |
70 | 73 |
assertThat(project.projectScope).isEqualTo(ProjectScope.PUBLIC); |
74 |
+ |
|
75 |
+ threadIds = addTestData(commitId); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ @After |
|
79 |
+ public void after() { |
|
80 |
+ thread.delete(); |
|
81 |
+ for(Long id : threadIds) { |
|
82 |
+ CommentThread.find.byId(id).delete(); |
|
83 |
+ } |
|
71 | 84 |
} |
72 | 85 |
|
73 | 86 |
@Test |
74 | 87 |
public void findByCommitId() { |
75 |
- // given |
|
76 |
- String commitId = "123123"; |
|
77 |
- addTestData(commitId); |
|
78 |
- |
|
79 | 88 |
// when |
80 | 89 |
List<CommentThread> threadList = CommentThread.findByCommitId(commitId); |
81 | 90 |
|
... | ... | @@ -87,10 +96,6 @@ |
87 | 96 |
|
88 | 97 |
@Test |
89 | 98 |
public void findByCommitIdAndState() { |
90 |
- // given |
|
91 |
- String commitId = "123123"; |
|
92 |
- List<Long> threadIds = addTestData(commitId); |
|
93 |
- |
|
94 | 99 |
// when and then |
95 | 100 |
List<CommentThread> threadList = CommentThread.findByCommitIdAndState(commitId, CommentThread.ThreadState.OPEN); |
96 | 101 |
assertThat(threadList.get(0).id).isEqualTo(threadIds.get(0)); |
--- test/models/IssueTest.java
+++ test/models/IssueTest.java
... | ... | @@ -31,6 +31,7 @@ |
31 | 31 |
import models.enumeration.State; |
32 | 32 |
|
33 | 33 |
import org.apache.commons.lang3.time.DateUtils; |
34 |
+import org.junit.After; |
|
34 | 35 |
import org.junit.Test; |
35 | 36 |
import org.junit.Before; |
36 | 37 |
|
... | ... | @@ -64,6 +65,16 @@ |
64 | 65 |
issue.save(); |
65 | 66 |
} |
66 | 67 |
|
68 |
+ @After |
|
69 |
+ public void after() { |
|
70 |
+ issue.setProject(project); |
|
71 |
+ issue.setTitle("hello"); |
|
72 |
+ issue.setBody("world"); |
|
73 |
+ issue.setAuthor(author); |
|
74 |
+ issue.state = State.OPEN; |
|
75 |
+ issue.update(); |
|
76 |
+ } |
|
77 |
+ |
|
67 | 78 |
@Test |
68 | 79 |
public void vote() { |
69 | 80 |
// when |
--- test/models/MilestoneTest.java
+++ test/models/MilestoneTest.java
... | ... | @@ -20,14 +20,21 @@ |
20 | 20 |
*/ |
21 | 21 |
package models; |
22 | 22 |
|
23 |
+import com.avaje.ebean.Ebean; |
|
23 | 24 |
import models.enumeration.State; |
24 | 25 |
|
25 | 26 |
import org.apache.commons.lang3.time.DateUtils; |
27 |
+import org.junit.After; |
|
28 |
+import org.junit.Before; |
|
26 | 29 |
import org.junit.Test; |
27 | 30 |
|
28 | 31 |
import play.i18n.Messages; |
32 |
+import play.libs.Yaml; |
|
33 |
+import support.Helpers; |
|
29 | 34 |
import utils.JodaDateUtil; |
35 |
+import utils.YamlUtil; |
|
30 | 36 |
|
37 |
+import java.io.IOException; |
|
31 | 38 |
import java.util.*; |
32 | 39 |
|
33 | 40 |
import static org.fest.assertions.Assertions.assertThat; |
... | ... | @@ -40,7 +47,7 @@ |
40 | 47 |
Milestone newMilestone = new Milestone(); |
41 | 48 |
newMilestone.dueDate = new Date(); |
42 | 49 |
newMilestone.setContents("테스트 마일스톤"); |
43 |
- newMilestone.project = Project.find.byId(1l); |
|
50 |
+ newMilestone.project = Project.find.byId(3l); |
|
44 | 51 |
newMilestone.title = "0.1"; |
45 | 52 |
|
46 | 53 |
// When |
... | ... | @@ -48,6 +55,8 @@ |
48 | 55 |
|
49 | 56 |
// Then |
50 | 57 |
assertThat(newMilestone.id).isNotNull(); |
58 |
+ //To keep data clean after this test. |
|
59 |
+ newMilestone.delete(); |
|
51 | 60 |
} |
52 | 61 |
|
53 | 62 |
@Test |
... | ... | @@ -82,15 +91,21 @@ |
82 | 91 |
@Test |
83 | 92 |
public void delete() throws Exception { |
84 | 93 |
// Given |
85 |
- Milestone firstMilestone = Milestone.findById(1l); |
|
86 |
- assertThat(firstMilestone).isNotNull(); |
|
94 |
+ Milestone milestone = new Milestone(); |
|
95 |
+ milestone.title = "test"; |
|
96 |
+ milestone.project = getTestProject(); |
|
97 |
+ milestone.contents = "test"; |
|
98 |
+ milestone.save(); |
|
99 |
+ |
|
100 |
+ Milestone savedMilestone = Milestone.findById(milestone.id); |
|
101 |
+ assertThat(savedMilestone).isNotNull(); |
|
87 | 102 |
|
88 | 103 |
// When |
89 |
- firstMilestone.delete(); |
|
104 |
+ savedMilestone.delete(); |
|
90 | 105 |
|
91 | 106 |
//Then |
92 |
- firstMilestone = Milestone.findById(1l); |
|
93 |
- assertThat(firstMilestone).isNull(); |
|
107 |
+ savedMilestone = Milestone.findById(milestone.id); |
|
108 |
+ assertThat(savedMilestone).isNull(); |
|
94 | 109 |
} |
95 | 110 |
|
96 | 111 |
@Test |
... | ... | @@ -221,6 +236,8 @@ |
221 | 236 |
m5 = Milestone.findById(5l); |
222 | 237 |
assertThat(m5.getNumTotalIssues()).isEqualTo(totalNumber + 1); |
223 | 238 |
assertThat(m5.getNumOpenIssues()).isEqualTo(openNumber + 1); |
239 |
+ //To keep data clean after this test. |
|
240 |
+ issue.delete(); |
|
224 | 241 |
} |
225 | 242 |
|
226 | 243 |
@Test |
--- test/models/ModelTest.java
+++ test/models/ModelTest.java
... | ... | @@ -20,14 +20,10 @@ |
20 | 20 |
*/ |
21 | 21 |
package models; |
22 | 22 |
|
23 |
-import org.junit.After; |
|
24 | 23 |
import org.junit.AfterClass; |
25 |
-import org.junit.Before; |
|
26 | 24 |
import org.junit.BeforeClass; |
27 | 25 |
import play.test.FakeApplication; |
28 | 26 |
import play.test.Helpers; |
29 |
-//import support.EbeanUtil; |
|
30 |
- |
|
31 | 27 |
|
32 | 28 |
public class ModelTest<T> { |
33 | 29 |
protected static FakeApplication app; |
... | ... | @@ -37,17 +33,16 @@ |
37 | 33 |
public ModelTest() { |
38 | 34 |
} |
39 | 35 |
|
40 |
- @Before |
|
41 |
- public void startApp() { |
|
36 |
+ @BeforeClass |
|
37 |
+ public static void startApp() { |
|
42 | 38 |
app = support.Helpers.makeTestApplication(); |
43 | 39 |
Helpers.start(app); |
44 | 40 |
} |
45 | 41 |
|
46 |
- @After |
|
47 |
- public void stopApp() { |
|
42 |
+ @AfterClass |
|
43 |
+ public static void stopApp() { |
|
48 | 44 |
Helpers.stop(app); |
49 | 45 |
} |
50 |
- |
|
51 | 46 |
/** |
52 | 47 |
* Returns the first user. (id : 2 / name : yobi) |
53 | 48 |
* |
--- test/models/OrganizationTest.java
+++ test/models/OrganizationTest.java
... | ... | @@ -20,9 +20,11 @@ |
20 | 20 |
*/ |
21 | 21 |
package models; |
22 | 22 |
|
23 |
+import org.junit.Before; |
|
23 | 24 |
import org.junit.Test; |
24 | 25 |
import play.data.validation.Validation; |
25 | 26 |
|
27 |
+import java.io.IOException; |
|
26 | 28 |
import java.util.List; |
27 | 29 |
|
28 | 30 |
import static org.fest.assertions.Assertions.assertThat; |
--- test/models/OrganizationUserTest.java
+++ test/models/OrganizationUserTest.java
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 |
|
24 | 24 |
import controllers.routes; |
25 | 25 |
import models.enumeration.RoleType; |
26 |
+import org.junit.After; |
|
26 | 27 |
import org.junit.Before; |
27 | 28 |
import org.junit.BeforeClass; |
28 | 29 |
import org.junit.Test; |
... | ... | @@ -37,34 +38,30 @@ |
37 | 38 |
/** |
38 | 39 |
* Created by kcs on 2/21/14. |
39 | 40 |
*/ |
40 |
-public class OrganizationUserTest { |
|
41 |
- protected static FakeApplication app; |
|
41 |
+public class OrganizationUserTest extends ModelTest<OrganizationUser> { |
|
42 | 42 |
|
43 |
- @BeforeClass |
|
44 |
- public static void beforeClass() { |
|
45 |
- callAction( |
|
46 |
- routes.ref.Application.init() |
|
47 |
- ); |
|
48 |
- } |
|
43 |
+ Organization organization; |
|
49 | 44 |
|
50 | 45 |
@Before |
51 | 46 |
public void before() { |
52 |
- app = support.Helpers.makeTestApplication(); |
|
53 |
- Helpers.start(app); |
|
47 |
+ organization = createOrganization(); |
|
54 | 48 |
} |
55 | 49 |
|
56 |
- private Organization createOrganization(String name) { |
|
57 |
- Organization organization = new Organization(); |
|
58 |
- organization.name = name; |
|
59 |
- organization.save(); |
|
50 |
+ @After |
|
51 |
+ public void after() { |
|
52 |
+ organization.delete(); |
|
53 |
+ } |
|
60 | 54 |
|
55 |
+ private Organization createOrganization() { |
|
56 |
+ Organization organization = new Organization(); |
|
57 |
+ organization.name = "TestOrganization"; |
|
58 |
+ organization.save(); |
|
61 | 59 |
return organization; |
62 | 60 |
} |
63 | 61 |
|
64 | 62 |
@Test |
65 | 63 |
public void addMember() { |
66 | 64 |
// Given |
67 |
- Organization organization = createOrganization("TestOrganization"); |
|
68 | 65 |
User user = User.findByLoginId("laziel"); |
69 | 66 |
|
70 | 67 |
// When |
... | ... | @@ -78,7 +75,6 @@ |
78 | 75 |
@Test |
79 | 76 |
public void checkMemberInfo() { |
80 | 77 |
// Given |
81 |
- Organization organization = createOrganization("TestOrganization"); |
|
82 | 78 |
User user = User.findByLoginId("laziel"); |
83 | 79 |
Long roleType = RoleType.ORG_ADMIN.roleType(); |
84 | 80 |
|
... | ... | @@ -96,7 +92,6 @@ |
96 | 92 |
@Test |
97 | 93 |
public void deleteMember() { |
98 | 94 |
// Given |
99 |
- Organization organization = createOrganization("TestOrganization"); |
|
100 | 95 |
User user = User.findByLoginId("laziel"); |
101 | 96 |
Long roleType = RoleType.ORG_ADMIN.roleType(); |
102 | 97 |
|
... | ... | @@ -112,7 +107,6 @@ |
112 | 107 |
@Test |
113 | 108 |
public void editMember() { |
114 | 109 |
// Given |
115 |
- Organization organization = createOrganization("TestOrganization"); |
|
116 | 110 |
User user = User.findByLoginId("laziel"); |
117 | 111 |
Long firstRoleType = RoleType.ORG_ADMIN.roleType(); |
118 | 112 |
Long secondRoleType = RoleType.ORG_MEMBER.roleType(); |
... | ... | @@ -130,7 +124,6 @@ |
130 | 124 |
@Test |
131 | 125 |
public void listOrganization() { |
132 | 126 |
// Given |
133 |
- Organization organization = createOrganization("TestOrganization"); |
|
134 | 127 |
User laziel = User.findByLoginId("laziel"); |
135 | 128 |
User doortts = User.findByLoginId("doortts"); |
136 | 129 |
|
--- test/models/PostingTest.java
+++ test/models/PostingTest.java
... | ... | @@ -69,12 +69,7 @@ |
69 | 69 |
@Test |
70 | 70 |
public void save() throws Exception { |
71 | 71 |
// Given |
72 |
- Posting post = new Posting(); |
|
73 |
- post.setBody("new Contents"); |
|
74 |
- post.title = "new_title"; |
|
75 |
- post.createdDate = JodaDateUtil.now(); |
|
76 |
- post.project = Project.find.byId(1l); |
|
77 |
- post.setAuthor(getTestUser()); |
|
72 |
+ Posting post = getNewPosting(); |
|
78 | 73 |
|
79 | 74 |
// When |
80 | 75 |
post.save(); |
... | ... | @@ -87,16 +82,35 @@ |
87 | 82 |
assertThat(actual.createdDate).isEqualTo(post.createdDate); |
88 | 83 |
assertThat(actual.authorId).isEqualTo(getTestUser().id); |
89 | 84 |
assertThat(actual.id).isEqualTo(post.id); |
85 |
+ |
|
86 |
+ // To keep data clean after this test. |
|
87 |
+ post.delete(); |
|
88 |
+ } |
|
89 |
+ |
|
90 |
+ private Posting getNewPosting() { |
|
91 |
+ Posting post = new Posting(); |
|
92 |
+ post.setBody("new Contents"); |
|
93 |
+ post.title = "new_title"; |
|
94 |
+ post.createdDate = JodaDateUtil.now(); |
|
95 |
+ post.project = Project.find.byId(1l); |
|
96 |
+ post.setAuthor(getTestUser()); |
|
97 |
+ return post; |
|
90 | 98 |
} |
91 | 99 |
|
92 | 100 |
@Test |
93 | 101 |
public void delete() throws Exception { |
94 | 102 |
// Given |
103 |
+ Posting post = getNewPosting(); |
|
104 |
+ post.save(); |
|
105 |
+ long postId = post.id; |
|
106 |
+ assertThat(Posting.finder.byId(postId)).isNotNull(); |
|
107 |
+ |
|
95 | 108 |
// When |
96 |
- Posting.finder.byId(1l).delete(); |
|
109 |
+ Posting.finder.byId(postId).delete(); |
|
110 |
+ |
|
97 | 111 |
// Then |
98 |
- assertThat(Posting.finder.byId(1l)).isNull(); |
|
99 |
- assertThat(PostingComment.find.byId(1l)).isNull(); |
|
112 |
+ assertThat(Posting.finder.byId(postId)).isNull(); |
|
113 |
+ assertThat(PostingComment.find.byId(postId)).isNull(); |
|
100 | 114 |
} |
101 | 115 |
|
102 | 116 |
@Test |
--- test/models/ProjectTest.java
+++ test/models/ProjectTest.java
... | ... | @@ -34,11 +34,7 @@ |
34 | 34 |
@Test |
35 | 35 |
public void create() throws Exception { |
36 | 36 |
// Given |
37 |
- Project project = new Project(); |
|
38 |
- project.name = "prj_test"; |
|
39 |
- project.overview = "Overview for prj_test"; |
|
40 |
- project.projectScope = ProjectScope.PRIVATE; |
|
41 |
- project.vcs = "GIT"; |
|
37 |
+ Project project = getNewProject(); |
|
42 | 38 |
// When |
43 | 39 |
Project.create(project); |
44 | 40 |
// Then |
... | ... | @@ -47,6 +43,15 @@ |
47 | 43 |
assertThat(actualProject).isNotNull(); |
48 | 44 |
assertThat(actualProject.name).isEqualTo("prj_test"); |
49 | 45 |
assertThat(actualProject.siteurl).isEqualTo("http://localhost:9000/prj_test"); |
46 |
+ } |
|
47 |
+ |
|
48 |
+ private Project getNewProject() { |
|
49 |
+ Project project = new Project(); |
|
50 |
+ project.name = "prj_test"; |
|
51 |
+ project.overview = "Overview for prj_test"; |
|
52 |
+ project.projectScope = ProjectScope.PRIVATE; |
|
53 |
+ project.vcs = "GIT"; |
|
54 |
+ return project; |
|
50 | 55 |
} |
51 | 56 |
|
52 | 57 |
@Test |
... | ... | @@ -70,14 +75,17 @@ |
70 | 75 |
@Test |
71 | 76 |
public void delete() throws Exception { |
72 | 77 |
// Given |
78 |
+ Project project = getNewProject(); |
|
79 |
+ Project.create(project); |
|
80 |
+ long projectId = project.id; |
|
73 | 81 |
// When |
74 |
- Project.find.byId(1l).delete(); |
|
82 |
+ Project.find.byId(projectId).delete(); |
|
75 | 83 |
|
76 | 84 |
// Then |
77 |
- assertThat(Project.find.byId(1l)).isNull(); |
|
78 |
- assertThat(ProjectUser.findByIds(1l, 1l)).isNull(); |
|
79 |
- assertThat(Issue.finder.byId(1l)).isNull(); |
|
80 |
- assertThat(Milestone.findById(1l)).isNull(); |
|
85 |
+ assertThat(Project.find.byId(projectId)).isNull(); |
|
86 |
+ assertThat(ProjectUser.findMemberListByProject(projectId)).isEmpty(); |
|
87 |
+ assertThat(Issue.finder.where().eq("project.id", projectId).findList()).isEmpty(); |
|
88 |
+ assertThat(Milestone.findByProjectId(projectId)).isEmpty(); |
|
81 | 89 |
} |
82 | 90 |
|
83 | 91 |
@Test |
--- test/models/ProjectUserTest.java
+++ test/models/ProjectUserTest.java
... | ... | @@ -43,6 +43,8 @@ |
43 | 43 |
// Then |
44 | 44 |
assertThat(ProjectUser.findByIds(2l, 3l).role.id) |
45 | 45 |
.isEqualTo(2l); |
46 |
+ // To keep data clean after this test. |
|
47 |
+ ProjectUser.delete(2l, 3l); |
|
46 | 48 |
} |
47 | 49 |
|
48 | 50 |
@Test |
... | ... | @@ -55,6 +57,9 @@ |
55 | 57 |
// Then |
56 | 58 |
assertThat(ProjectUser.findByIds(2l, 1l).role.id).isEqualTo(2l); |
57 | 59 |
assertThat(ProjectUser.findByIds(2l, 3l).role.id).isEqualTo(2l); |
60 |
+ // To keep data clean after this test. |
|
61 |
+ ProjectUser.assignRole(2l, 1l, 1l); |
|
62 |
+ ProjectUser.delete(2l, 3l); |
|
58 | 63 |
} |
59 | 64 |
|
60 | 65 |
@Test |
... | ... | @@ -70,6 +75,8 @@ |
70 | 75 |
// Then |
71 | 76 |
assertThat(ProjectUser.checkOneMangerPerOneProject(userIdCase1, 3l)).isEqualTo(true); |
72 | 77 |
assertThat(ProjectUser.checkOneMangerPerOneProject(userIdCase2, 3l)).isEqualTo(false); |
78 |
+ // To keep data clean after this test. |
|
79 |
+ ProjectUser.delete(2l, 3l); |
|
73 | 80 |
} |
74 | 81 |
|
75 | 82 |
@Test |
--- test/models/PullRequestTest.java
+++ test/models/PullRequestTest.java
... | ... | @@ -43,10 +43,86 @@ |
43 | 43 |
import java.util.regex.Pattern; |
44 | 44 |
|
45 | 45 |
import static org.fest.assertions.Assertions.assertThat; |
46 |
-import static play.test.Helpers.callAction; |
|
47 | 46 |
import static utils.FileUtil.rm_rf; |
48 | 47 |
|
49 | 48 |
public class PullRequestTest extends ModelTest<PullRequest> { |
49 |
+ private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/"; |
|
50 |
+ private static final String REPO_PREFIX = "resources/test/repo/git/"; |
|
51 |
+ private static final String LOCAL_REPO_PREFIX = "resources/test/local-repo/git/"; |
|
52 |
+ |
|
53 |
+ private RevCommit baseCommit; |
|
54 |
+ private RevCommit firstCommit; |
|
55 |
+ private RevCommit secondCommit; |
|
56 |
+ private PullRequest pullRequest; |
|
57 |
+ private Project forkedProject; |
|
58 |
+ |
|
59 |
+ @Before |
|
60 |
+ public void initRepositories() throws IOException, GitAPIException, ServletException, |
|
61 |
+ ClientException { |
|
62 |
+ GitRepository.setRepoPrefix(REPO_PREFIX); |
|
63 |
+ GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX); |
|
64 |
+ |
|
65 |
+ app = support.Helpers.makeTestApplication(); |
|
66 |
+ Helpers.start(app); |
|
67 |
+ |
|
68 |
+ Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); |
|
69 |
+ forkedProject = Project.findByOwnerAndProjectName("yobi", "projectYobi-1"); |
|
70 |
+ |
|
71 |
+ // 1. projectYobi 저장소를 만듦 |
|
72 |
+ RepositoryService.createRepository(project); |
|
73 |
+ |
|
74 |
+ // 2. projectYobi 저장소에 커밋 하나 |
|
75 |
+ { |
|
76 |
+ String localRepoPath = LOCAL_REPO_PREFIX + project.name; |
|
77 |
+ Git git = Git.cloneRepository() |
|
78 |
+ .setURI(GitRepository.getGitDirectoryURL(project)) |
|
79 |
+ .setDirectory(new File(localRepoPath)) |
|
80 |
+ .call(); |
|
81 |
+ Repository repo = git.getRepository(); |
|
82 |
+ baseCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), "test.txt", |
|
83 |
+ "apple\nbanana\ncat\n", "commit 1"); |
|
84 |
+ git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call(); |
|
85 |
+ } |
|
86 |
+ |
|
87 |
+ // 3. 포크된 프로젝트 클론된 저장소 만들기 |
|
88 |
+ GitRepository.cloneLocalRepository(project, forkedProject); |
|
89 |
+ |
|
90 |
+ // 4. 포크된 저장소에 새 브랜치를 만들어 그 브랜치에 커밋을 두개 하고 |
|
91 |
+ { |
|
92 |
+ String localRepoPath = LOCAL_REPO_PREFIX + forkedProject.name; |
|
93 |
+ Git git = Git.cloneRepository() |
|
94 |
+ .setURI(GitRepository.getGitDirectoryURL(forkedProject)) |
|
95 |
+ .setDirectory(new File(localRepoPath)) |
|
96 |
+ .call(); |
|
97 |
+ git.branchCreate().setName("fix/1").call(); |
|
98 |
+ git.checkout().setName("fix/1").call(); |
|
99 |
+ Repository repo = git.getRepository(); |
|
100 |
+ assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse(); |
|
101 |
+ firstCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
102 |
+ "test.txt", "apple\nbanana\ncorn\n", "commit 1"); |
|
103 |
+ secondCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
104 |
+ "test.txt", "apple\nbanana\ncake\n", "commit 2"); |
|
105 |
+ git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call(); |
|
106 |
+ } |
|
107 |
+ |
|
108 |
+ // 5. 그 브랜치로 projectYobi에 pullrequest를 보낸다. |
|
109 |
+ pullRequest = PullRequest.createNewPullRequest(forkedProject, project, "refs/heads/fix/1", |
|
110 |
+ "refs/heads/master"); |
|
111 |
+ |
|
112 |
+ // 6. attempt merge |
|
113 |
+ boolean isConflict = pullRequest.attemptMerge().conflicts(); |
|
114 |
+ |
|
115 |
+ assertThat(isConflict).isFalse(); |
|
116 |
+ } |
|
117 |
+ |
|
118 |
+ @After |
|
119 |
+ public void after() { |
|
120 |
+ rm_rf(new File(REPO_PREFIX)); |
|
121 |
+ rm_rf(new File(MERGING_REPO_PREFIX)); |
|
122 |
+ rm_rf(new File(LOCAL_REPO_PREFIX)); |
|
123 |
+ Helpers.stop(app); |
|
124 |
+ } |
|
125 |
+ |
|
50 | 126 |
@Test |
51 | 127 |
public void addIssueEvent() { |
52 | 128 |
// Given |
... | ... | @@ -184,83 +260,6 @@ |
184 | 260 |
PullRequestEvent event = new PullRequestEvent(); |
185 | 261 |
event.created = DateUtils.parseDate(str, "yyyy-MM-dd"); |
186 | 262 |
return event; |
187 |
- } |
|
188 |
- |
|
189 |
- private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/"; |
|
190 |
- private static final String REPO_PREFIX = "resources/test/repo/git/"; |
|
191 |
- private static final String LOCAL_REPO_PREFIX = "resources/test/local-repo/git/"; |
|
192 |
- |
|
193 |
- private RevCommit baseCommit; |
|
194 |
- private RevCommit firstCommit; |
|
195 |
- private RevCommit secondCommit; |
|
196 |
- private PullRequest pullRequest; |
|
197 |
- private Project forkedProject; |
|
198 |
- |
|
199 |
- @Before |
|
200 |
- public void initRepositories() throws IOException, GitAPIException, ServletException, |
|
201 |
- ClientException { |
|
202 |
- GitRepository.setRepoPrefix(REPO_PREFIX); |
|
203 |
- GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX); |
|
204 |
- |
|
205 |
- app = support.Helpers.makeTestApplication(); |
|
206 |
- Helpers.start(app); |
|
207 |
- |
|
208 |
- Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); |
|
209 |
- forkedProject = Project.findByOwnerAndProjectName("yobi", "projectYobi-1"); |
|
210 |
- |
|
211 |
- // 1. projectYobi 저장소를 만듦 |
|
212 |
- RepositoryService.createRepository(project); |
|
213 |
- |
|
214 |
- // 2. projectYobi 저장소에 커밋 하나 |
|
215 |
- { |
|
216 |
- String localRepoPath = LOCAL_REPO_PREFIX + project.name; |
|
217 |
- Git git = Git.cloneRepository() |
|
218 |
- .setURI(GitRepository.getGitDirectoryURL(project)) |
|
219 |
- .setDirectory(new File(localRepoPath)) |
|
220 |
- .call(); |
|
221 |
- Repository repo = git.getRepository(); |
|
222 |
- baseCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), "test.txt", |
|
223 |
- "apple\nbanana\ncat\n", "commit 1"); |
|
224 |
- git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call(); |
|
225 |
- } |
|
226 |
- |
|
227 |
- // 3. 포크된 프로젝트 클론된 저장소 만들기 |
|
228 |
- GitRepository.cloneLocalRepository(project, forkedProject); |
|
229 |
- |
|
230 |
- // 4. 포크된 저장소에 새 브랜치를 만들어 그 브랜치에 커밋을 두개 하고 |
|
231 |
- { |
|
232 |
- String localRepoPath = LOCAL_REPO_PREFIX + forkedProject.name; |
|
233 |
- Git git = Git.cloneRepository() |
|
234 |
- .setURI(GitRepository.getGitDirectoryURL(forkedProject)) |
|
235 |
- .setDirectory(new File(localRepoPath)) |
|
236 |
- .call(); |
|
237 |
- git.branchCreate().setName("fix/1").call(); |
|
238 |
- git.checkout().setName("fix/1").call(); |
|
239 |
- Repository repo = git.getRepository(); |
|
240 |
- assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse(); |
|
241 |
- firstCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
242 |
- "test.txt", "apple\nbanana\ncorn\n", "commit 1"); |
|
243 |
- secondCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
244 |
- "test.txt", "apple\nbanana\ncake\n", "commit 2"); |
|
245 |
- git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call(); |
|
246 |
- } |
|
247 |
- |
|
248 |
- // 5. 그 브랜치로 projectYobi에 pullrequest를 보낸다. |
|
249 |
- pullRequest = PullRequest.createNewPullRequest(forkedProject, project, "refs/heads/fix/1", |
|
250 |
- "refs/heads/master"); |
|
251 |
- |
|
252 |
- // 6. attempt merge |
|
253 |
- boolean isConflict = pullRequest.attemptMerge().conflicts(); |
|
254 |
- |
|
255 |
- assertThat(isConflict).isFalse(); |
|
256 |
- } |
|
257 |
- |
|
258 |
- @After |
|
259 |
- public void after() { |
|
260 |
- rm_rf(new File(REPO_PREFIX)); |
|
261 |
- rm_rf(new File(MERGING_REPO_PREFIX)); |
|
262 |
- rm_rf(new File(LOCAL_REPO_PREFIX)); |
|
263 |
- Helpers.stop(app); |
|
264 | 263 |
} |
265 | 264 |
|
266 | 265 |
@Test |
--- test/models/RecentlyVisitedProjectsTest.java
+++ test/models/RecentlyVisitedProjectsTest.java
... | ... | @@ -20,6 +20,7 @@ |
20 | 20 |
*/ |
21 | 21 |
package models; |
22 | 22 |
|
23 |
+import org.junit.After; |
|
23 | 24 |
import org.junit.Before; |
24 | 25 |
import org.junit.Test; |
25 | 26 |
|
... | ... | @@ -45,6 +46,13 @@ |
45 | 46 |
cubrid = Project.findByOwnerAndProjectName("doortts", "CUBRID"); |
46 | 47 |
} |
47 | 48 |
|
49 |
+ @After |
|
50 |
+ public void after() { |
|
51 |
+ for(RecentlyVisitedProjects visitedProjects: RecentlyVisitedProjects.find.all()) { |
|
52 |
+ visitedProjects.delete(); |
|
53 |
+ } |
|
54 |
+ } |
|
55 |
+ |
|
48 | 56 |
@Test |
49 | 57 |
public void addVisit() { |
50 | 58 |
// When |
--- test/models/UserTest.java
+++ test/models/UserTest.java
... | ... | @@ -197,5 +197,8 @@ |
197 | 197 |
// Then |
198 | 198 |
issue.refresh(); |
199 | 199 |
assertThat(issue.assignee).isNull(); |
200 |
+ |
|
201 |
+ // To keep data clean after this test. |
|
202 |
+ user.delete(); |
|
200 | 203 |
} |
201 | 204 |
} |
--- test/models/WatchTest.java
+++ test/models/WatchTest.java
... | ... | @@ -35,19 +35,17 @@ |
35 | 35 |
import static play.test.Helpers.start; |
36 | 36 |
import static play.test.Helpers.stop; |
37 | 37 |
|
38 |
-public class WatchTest { |
|
39 |
- |
|
40 |
- private FakeApplication application; |
|
38 |
+public class WatchTest extends ModelTest<Watch> { |
|
41 | 39 |
|
42 | 40 |
@Before |
43 |
- public void setUp() { |
|
44 |
- application = support.Helpers.makeTestApplication(); |
|
45 |
- start(application); |
|
46 |
- } |
|
41 |
+ public void setup() { |
|
42 |
+ for(Watch watch : Watch.find.all()) { |
|
43 |
+ watch.delete(); |
|
44 |
+ } |
|
47 | 45 |
|
48 |
- @After |
|
49 |
- public void tearDown() { |
|
50 |
- stop(application); |
|
46 |
+ for(Unwatch unwatch : Unwatch.find.all()) { |
|
47 |
+ unwatch.delete(); |
|
48 |
+ } |
|
51 | 49 |
} |
52 | 50 |
|
53 | 51 |
@Test |
--- test/models/support/ReviewSearchConditionTest.java
+++ test/models/support/ReviewSearchConditionTest.java
... | ... | @@ -34,7 +34,20 @@ |
34 | 34 |
*/ |
35 | 35 |
public class ReviewSearchConditionTest extends ModelTest<ReviewSearchCondition> { |
36 | 36 |
|
37 |
- protected static FakeApplication app; |
|
37 |
+ CommentThread ct1; |
|
38 |
+ CommentThread ct2; |
|
39 |
+ CommentThread ct3; |
|
40 |
+ |
|
41 |
+ @Before |
|
42 |
+ public void before() { |
|
43 |
+ addTestData(); |
|
44 |
+ } |
|
45 |
+ |
|
46 |
+ @After |
|
47 |
+ public void after() { |
|
48 |
+ clearData(); |
|
49 |
+ } |
|
50 |
+ |
|
38 | 51 |
|
39 | 52 |
/** |
40 | 53 |
* Tests searching reviews having the content. |
... | ... | @@ -160,12 +173,18 @@ |
160 | 173 |
User lazielUser = User.findByLoginId("laziel"); |
161 | 174 |
Project project = Project.findByOwnerAndProjectName("yobi", "projectYobi"); |
162 | 175 |
|
163 |
- addTestThread1(adminUser, lazielUser, project); |
|
164 |
- addTestThread2(adminUser, lazielUser, project); |
|
165 |
- addTestThread3(adminUser, lazielUser, project); |
|
176 |
+ ct1 = addTestThread1(adminUser, lazielUser, project); |
|
177 |
+ ct2 = addTestThread2(adminUser, lazielUser, project); |
|
178 |
+ ct3 = addTestThread3(adminUser, lazielUser, project); |
|
166 | 179 |
} |
167 | 180 |
|
168 |
- private void addTestThread1(User admin, User user, Project project) { |
|
181 |
+ private void clearData() { |
|
182 |
+ ct1.delete(); |
|
183 |
+ ct2.delete(); |
|
184 |
+ ct3.delete(); |
|
185 |
+ } |
|
186 |
+ |
|
187 |
+ private CommentThread addTestThread1(User admin, User user, Project project) { |
|
169 | 188 |
CodeCommentThread thread = new CodeCommentThread(); |
170 | 189 |
thread.createdDate = JodaDateUtil.today(); |
171 | 190 |
thread.commitId = "controllers"; |
... | ... | @@ -173,9 +192,10 @@ |
173 | 192 |
makeThread(admin, "Comment #1 : 111", project, thread); |
174 | 193 |
makeComment(thread, user, "Comment #1-1"); |
175 | 194 |
makeComment(thread, user, "Comment #1-2"); |
195 |
+ return thread; |
|
176 | 196 |
} |
177 | 197 |
|
178 |
- private void addTestThread2(User admin, User user, Project project) { |
|
198 |
+ private CommentThread addTestThread2(User admin, User user, Project project) { |
|
179 | 199 |
CodeCommentThread thread = new CodeCommentThread(); |
180 | 200 |
thread.createdDate = JodaDateUtil.before(2); |
181 | 201 |
thread.commitId = "200"; |
... | ... | @@ -183,9 +203,10 @@ |
183 | 203 |
makeThread(admin, "Comment #2 : /app/controllers/BoardApp.java", project, thread); |
184 | 204 |
makeComment(thread, admin, "Comment #2-1"); |
185 | 205 |
makeComment(thread, user, "Comment #2-2"); |
206 |
+ return thread; |
|
186 | 207 |
} |
187 | 208 |
|
188 |
- private void addTestThread3(User admin, User user, Project project) { |
|
209 |
+ private CommentThread addTestThread3(User admin, User user, Project project) { |
|
189 | 210 |
CodeCommentThread thread = new CodeCommentThread(); |
190 | 211 |
thread.createdDate = JodaDateUtil.before(3); |
191 | 212 |
thread.commitId = "300"; |
... | ... | @@ -195,21 +216,8 @@ |
195 | 216 |
makeComment(thread, user, "Comment #3-1"); |
196 | 217 |
makeComment(thread, user, "Comment #3-2"); |
197 | 218 |
makeComment(thread, user, "Comment #3-3"); |
219 |
+ return thread; |
|
198 | 220 |
} |
199 |
- |
|
200 |
- |
|
201 |
- @Before |
|
202 |
- public void before() { |
|
203 |
- app = support.Helpers.makeTestApplication(); |
|
204 |
- Helpers.start(app); |
|
205 |
- addTestData(); |
|
206 |
- } |
|
207 |
- |
|
208 |
- @After |
|
209 |
- public void after() { |
|
210 |
- Helpers.stop(app); |
|
211 |
- } |
|
212 |
- |
|
213 | 221 |
/** |
214 | 222 |
* Creates a comment and added to {@code thread} |
215 | 223 |
* @param thread |
--- test/playRepository/CommitTest.java
+++ test/playRepository/CommitTest.java
... | ... | @@ -30,6 +30,17 @@ |
30 | 30 |
import org.junit.*; |
31 | 31 |
|
32 | 32 |
public class CommitTest extends ModelTest<Commit> { |
33 |
+ |
|
34 |
+ @Before |
|
35 |
+ public void before() { |
|
36 |
+ for(Watch watch : Watch.find.all()) { |
|
37 |
+ watch.delete(); |
|
38 |
+ } |
|
39 |
+ for(Unwatch unwatch : Unwatch.find.all()) { |
|
40 |
+ unwatch.delete(); |
|
41 |
+ } |
|
42 |
+ } |
|
43 |
+ |
|
33 | 44 |
@Test |
34 | 45 |
public void getWatchers_no_watchers() { |
35 | 46 |
// Given |
... | ... | @@ -77,6 +88,7 @@ |
77 | 88 |
|
78 | 89 |
// Then |
79 | 90 |
assertThat(watchers).containsOnly(author, commentUser); |
91 |
+ comment.delete(); |
|
80 | 92 |
} |
81 | 93 |
|
82 | 94 |
@Test |
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
... | ... | @@ -41,6 +41,7 @@ |
41 | 41 |
import org.junit.rules.TestWatcher; |
42 | 42 |
import play.test.FakeApplication; |
43 | 43 |
import play.test.Helpers; |
44 |
+import support.ExecutionTimeWatcher; |
|
44 | 45 |
|
45 | 46 |
import javax.naming.LimitExceededException; |
46 | 47 |
import java.io.BufferedWriter; |
--- test/support/Files.java
+++ test/support/Files.java
... | ... | @@ -32,7 +32,6 @@ |
32 | 32 |
rm_rf(f); |
33 | 33 |
} |
34 | 34 |
} |
35 |
- System.gc(); |
|
36 | 35 |
file.delete(); |
37 | 36 |
} |
38 | 37 |
} |
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?