aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-03 16:20:47 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-02-03 16:20:47 +0100
commit4942f2824202671ab5ef9a9895e48c35b018b62f (patch)
tree728fea80e2366ea55f3119d9a6ae0b234d7a0ce6
parentddfdce994fda7cbdc9d71b5f8f0e0e68e75f5352 (diff)
downloadsonarqube-4942f2824202671ab5ef9a9895e48c35b018b62f.tar.gz
sonarqube-4942f2824202671ab5ef9a9895e48c35b018b62f.zip
SONAR-6987 WS api/tests/list factor test code
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java162
1 files changed, 54 insertions, 108 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
index 67ff39371fa..8e15837b7ce 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/test/ws/ListActionTest.java
@@ -73,21 +73,10 @@ public class ListActionTest {
public void list_based_on_test_uuid() throws Exception {
userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
- es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- new TestDoc()
- .setUuid(TestFile1.UUID)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- .setName(TestFile1.NAME)
- .setFileUuid(TestFile1.FILE_UUID)
- .setDurationInMs(TestFile1.DURATION_IN_MS)
- .setStatus(TestFile1.STATUS)
- .setMessage(TestFile1.MESSAGE)
- .setCoveredFiles(TestFile1.COVERED_FILES)
- .setStackTrace(TestFile1.STACKTRACE)
- );
+ es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, TestFile1.doc());
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_ID, TestFile1.UUID);
@@ -97,20 +86,10 @@ public class ListActionTest {
@Test
public void list_based_on_test_file_uuid() throws Exception {
userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
- es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- new TestDoc()
- .setUuid(TestFile1.UUID)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- .setName(TestFile1.NAME)
- .setFileUuid(TestFile1.FILE_UUID)
- .setDurationInMs(TestFile1.DURATION_IN_MS)
- .setCoveredFiles(TestFile1.COVERED_FILES)
- .setStatus(TestFile1.STATUS)
- .setMessage(TestFile1.MESSAGE)
- .setStackTrace(TestFile1.STACKTRACE));
+ es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, TestFile1.doc());
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID);
@@ -120,21 +99,10 @@ public class ListActionTest {
@Test
public void list_based_on_test_file_key() throws Exception {
userSessionRule.addComponentPermission(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID, TestFile1.KEY);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
- es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- new TestDoc()
- .setUuid(TestFile1.UUID)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- .setName(TestFile1.NAME)
- .setFileUuid(TestFile1.FILE_UUID)
- .setDurationInMs(TestFile1.DURATION_IN_MS)
- .setCoveredFiles(TestFile1.COVERED_FILES)
- .setStatus(TestFile1.STATUS)
- .setMessage(TestFile1.MESSAGE)
- .setStackTrace(TestFile1.STACKTRACE)
- );
+ es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE, TestFile1.doc());
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_KEY, TestFile1.KEY);
@@ -146,44 +114,16 @@ public class ListActionTest {
String mainFileUuid = "MAIN-FILE-UUID";
userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID);
dbClient.componentDao().insert(db.getSession(),
- new ComponentDto()
- .setUuid(TestFile1.FILE_UUID)
- .setLongName(TestFile1.LONG_NAME)
- .setKey(TestFile1.KEY)
- .setProjectUuid(TestFile1.PROJECT_UUID),
- new ComponentDto()
- .setUuid(TestFile2.FILE_UUID)
- .setLongName(TestFile2.LONG_NAME)
- .setProjectUuid(TestFile2.PROJECT_UUID)
- .setKey(TestFile2.KEY),
+ TestFile1.dto(),
+ TestFile2.dto(),
new ComponentDto()
.setUuid(mainFileUuid)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- );
+ .setProjectUuid(TestFile1.PROJECT_UUID));
db.getSession().commit();
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- new TestDoc()
- .setUuid(TestFile1.UUID)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- .setName(TestFile1.NAME)
- .setFileUuid(TestFile1.FILE_UUID)
- .setDurationInMs(TestFile1.DURATION_IN_MS)
- .setStatus(TestFile1.STATUS)
- .setMessage(TestFile1.MESSAGE)
- .setCoveredFiles(TestFile1.COVERED_FILES)
- .setStackTrace(TestFile1.STACKTRACE),
- new TestDoc()
- .setUuid(TestFile2.UUID)
- .setProjectUuid(TestFile2.PROJECT_UUID)
- .setName(TestFile2.NAME)
- .setFileUuid(TestFile2.FILE_UUID)
- .setDurationInMs(TestFile2.DURATION_IN_MS)
- .setStatus(TestFile2.STATUS)
- .setStackTrace(TestFile2.STATUS)
- .setMessage(TestFile2.MESSAGE)
- .setCoveredFiles(TestFile2.COVERED_FILES)
- .setStackTrace(TestFile2.STACKTRACE));
+ TestFile1.doc(),
+ TestFile2.doc());
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list")
.setParam(ListAction.SOURCE_FILE_ID, mainFileUuid)
@@ -198,45 +138,16 @@ public class ListActionTest {
String sourceFileKey = "MAIN-FILE-KEY";
userSessionRule.addProjectUuidPermissions(UserRole.CODEVIEWER, TestFile1.PROJECT_UUID);
dbClient.componentDao().insert(db.getSession(),
- new ComponentDto()
- .setUuid(TestFile1.FILE_UUID)
- .setLongName(TestFile1.LONG_NAME)
- .setKey(TestFile1.KEY)
- .setProjectUuid(TestFile1.PROJECT_UUID),
- new ComponentDto()
- .setUuid(TestFile2.FILE_UUID)
- .setLongName(TestFile2.LONG_NAME)
- .setProjectUuid(TestFile2.PROJECT_UUID)
- .setKey(TestFile2.KEY),
+ TestFile1.dto(),
+ TestFile2.dto(),
new ComponentDto()
.setUuid(sourceFileUuid)
.setKey(sourceFileKey)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- );
+ .setProjectUuid(TestFile1.PROJECT_UUID));
db.getSession().commit();
es.putDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE,
- new TestDoc()
- .setUuid(TestFile1.UUID)
- .setProjectUuid(TestFile1.PROJECT_UUID)
- .setName(TestFile1.NAME)
- .setFileUuid(TestFile1.FILE_UUID)
- .setDurationInMs(TestFile1.DURATION_IN_MS)
- .setStatus(TestFile1.STATUS)
- .setMessage(TestFile1.MESSAGE)
- .setCoveredFiles(TestFile1.COVERED_FILES)
- .setStackTrace(TestFile1.STACKTRACE),
- new TestDoc()
- .setUuid(TestFile2.UUID)
- .setProjectUuid(TestFile2.PROJECT_UUID)
- .setName(TestFile2.NAME)
- .setFileUuid(TestFile2.FILE_UUID)
- .setDurationInMs(TestFile2.DURATION_IN_MS)
- .setStatus(TestFile2.STATUS)
- .setStackTrace(TestFile2.STATUS)
- .setMessage(TestFile2.MESSAGE)
- .setCoveredFiles(TestFile2.COVERED_FILES)
- .setStackTrace(TestFile2.STACKTRACE));
+ TestFile1.doc(), TestFile2.doc());
WsTester.TestRequest request = ws.newGetRequest("api/tests", "list")
.setParam(ListAction.SOURCE_FILE_KEY, sourceFileKey)
@@ -258,7 +169,7 @@ public class ListActionTest {
@Test(expected = ForbiddenException.class)
public void fail_when_no_sufficent_privilege_on_file_uuid() throws Exception {
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID).execute();
}
@@ -266,7 +177,7 @@ public class ListActionTest {
@Test(expected = ForbiddenException.class)
public void fail_when_no_sufficent_privilege_on_test_uuid() throws Exception {
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_ID, TestFile1.FILE_UUID).execute();
}
@@ -274,7 +185,7 @@ public class ListActionTest {
@Test(expected = ForbiddenException.class)
public void fail_when_no_sufficent_privilege_on_file_key() throws Exception {
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID);
- dbClient.componentDao().insert(db.getSession(), TestFile1.newDto());
+ dbClient.componentDao().insert(db.getSession(), TestFile1.dto());
db.getSession().commit();
ws.newGetRequest("api/tests", "list").setParam(ListAction.TEST_FILE_KEY, TestFile1.KEY).execute();
}
@@ -305,7 +216,7 @@ public class ListActionTest {
public static final String LONG_NAME = "src/test/java/org/foo/BarTest.java";
public static final List<CoveredFileDoc> COVERED_FILES = Arrays.asList(new CoveredFileDoc().setFileUuid("MAIN-FILE-UUID").setCoveredLines(Arrays.asList(1, 2, 3, 10)));
- public static ComponentDto newDto() {
+ public static ComponentDto dto() {
return new ComponentDto()
.setUuid(TestFile1.FILE_UUID)
.setLongName(TestFile1.LONG_NAME)
@@ -313,6 +224,19 @@ public class ListActionTest {
.setKey(TestFile1.KEY);
}
+ public static TestDoc doc() {
+ return new TestDoc()
+ .setUuid(TestFile1.UUID)
+ .setProjectUuid(TestFile1.PROJECT_UUID)
+ .setName(TestFile1.NAME)
+ .setFileUuid(TestFile1.FILE_UUID)
+ .setDurationInMs(TestFile1.DURATION_IN_MS)
+ .setStatus(TestFile1.STATUS)
+ .setMessage(TestFile1.MESSAGE)
+ .setCoveredFiles(TestFile1.COVERED_FILES)
+ .setStackTrace(TestFile1.STACKTRACE);
+ }
+
private TestFile1() {
// static stuff for test purposes
}
@@ -331,6 +255,28 @@ public class ListActionTest {
public static final String LONG_NAME = "src/test/java/org/foo/FileTest.java";
public static final List<CoveredFileDoc> COVERED_FILES = Arrays.asList(new CoveredFileDoc().setFileUuid("MAIN-FILE-UUID").setCoveredLines(Arrays.asList(11, 12, 13, 10)));
+ public static ComponentDto dto() {
+ return new ComponentDto()
+ .setUuid(TestFile2.FILE_UUID)
+ .setLongName(TestFile2.LONG_NAME)
+ .setProjectUuid(TestFile2.PROJECT_UUID)
+ .setKey(TestFile2.KEY);
+ }
+
+ public static TestDoc doc() {
+ return new TestDoc()
+ .setUuid(TestFile2.UUID)
+ .setProjectUuid(TestFile2.PROJECT_UUID)
+ .setName(TestFile2.NAME)
+ .setFileUuid(TestFile2.FILE_UUID)
+ .setDurationInMs(TestFile2.DURATION_IN_MS)
+ .setStatus(TestFile2.STATUS)
+ .setStackTrace(TestFile2.STATUS)
+ .setMessage(TestFile2.MESSAGE)
+ .setCoveredFiles(TestFile2.COVERED_FILES)
+ .setStackTrace(TestFile2.STACKTRACE);
+ }
+
private TestFile2() {
// static stuff for test purposes
}