Skip to content

Commit 27741b0

Browse files
committed
update TI system and create all Integration tests
1 parent 27274a6 commit 27741b0

26 files changed

+632
-176
lines changed

src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/BuildProjectEngine.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import org.greencodeinitiative.creedengo.java.integration.tests.profile.ProfileBackup;
2828
import org.junit.jupiter.api.AfterAll;
2929
import org.junit.jupiter.api.BeforeAll;
30+
import org.sonarqube.ws.Components;
3031
import org.sonarqube.ws.Issues;
3132
import org.sonarqube.ws.Measures;
3233
import org.sonarqube.ws.client.HttpConnector;
3334
import org.sonarqube.ws.client.WsClient;
3435
import org.sonarqube.ws.client.WsClientFactories;
36+
import org.sonarqube.ws.client.components.ShowRequest;
3537
import org.sonarqube.ws.client.issues.SearchRequest;
3638
import org.sonarqube.ws.client.measures.ComponentRequest;
3739

@@ -252,11 +254,11 @@ private static Location toPluginLocation(String location) {
252254
);
253255
}
254256

255-
protected static List<Issues.Issue> issuesForFile(String projectKey, String file, String ruleId) {
256-
return issuesForComponent(projectKey + ":" + file, ruleId);
257+
protected static Issues.SearchWsResponse searchIssuesForFile(String projectKey, String file, String ruleId) {
258+
return searchIssuesForComponent(projectKey + ":" + file, ruleId);
257259
}
258260

259-
protected static List<Issues.Issue> issuesForComponent(String componentKey, String ruleId) {
261+
protected static Issues.SearchWsResponse searchIssuesForComponent(String componentKey, String ruleId) {
260262

261263
SearchRequest searchRequest = new SearchRequest()
262264
.setComponentKeys(Collections.singletonList(componentKey))
@@ -266,19 +268,19 @@ protected static List<Issues.Issue> issuesForComponent(String componentKey, Stri
266268
searchRequest.setRules(Collections.singletonList(ruleId)); // only keep issues for this rule
267269
}
268270

269-
Issues.SearchWsResponse resp = newWsClient(orchestrator)
271+
return newWsClient(orchestrator)
270272
.issues()
271273
.search(searchRequest);
274+
}
272275

273-
// System.out.println("--- NB ISSUES : " + resp.getIssuesCount());
274-
// System.out.println("--- NB ISSUES_LIST : " + resp.getIssuesList().size());
275-
// resp.getIssuesList().forEach(issue -> {
276-
//// if (issue.getRule().equals("creedengo-java:GCI27")) {
277-
// System.out.println("--- Issue --- " + issue.getRule() + " / " + issue.getLine());
278-
//// }
279-
// });
276+
protected static Components.ShowWsResponse showComponent(String componentKey) {
280277

281-
return resp.getIssuesList();
278+
ShowRequest showRequest = new org.sonarqube.ws.client.components.ShowRequest()
279+
.setComponent(componentKey);
280+
281+
return newWsClient(orchestrator)
282+
.components()
283+
.show(showRequest);
282284
}
283285

284286
protected static Map<String, Measures.Measure> getMeasures(String componentKey) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.greencodeinitiative.creedengo.java.integration.tests;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class GCI1RuleIT extends GCIRulesBase {
6+
7+
@Test
8+
void testGCI1_loop() {
9+
10+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInLoopCheck.java";
11+
12+
int[] startLines = new int[]{32};
13+
14+
int[] endLines = new int[]{32};
15+
16+
String ruleId = "creedengo-java:GCI1";
17+
String ruleMsg = "Avoid Spring repository call in loop or stream";
18+
19+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
20+
21+
}
22+
23+
@Test
24+
void testGCI1_stream() {
25+
26+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidSpringRepositoryCallInStreamCheck.java";
27+
28+
int[] startLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
29+
30+
int[] endLines = new int[]{36, 46, 56, 66, 76, 84, 96, 105};
31+
32+
String ruleId = "creedengo-java:GCI1";
33+
String ruleMsg = "Avoid Spring repository call in loop or stream";
34+
35+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines, SEVERITY, TYPE, EFFORT_50MIN);
36+
37+
}
38+
39+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.greencodeinitiative.creedengo.java.integration.tests;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class GCI28RuleIT extends GCIRulesBase {
6+
7+
@Test
8+
void testGCI28() {
9+
10+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck.java";
11+
12+
int[] startLines = new int[]{23};
13+
14+
int[] endLines = new int[]{23};
15+
16+
String ruleId = "creedengo-java:GCI28";
17+
String ruleMsg = "Optimize Read File Exceptions";
18+
19+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
20+
21+
}
22+
23+
@Test
24+
void testGCI28_2() {
25+
26+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck2.java";
27+
28+
int[] startLines = new int[]{20};
29+
30+
int[] endLines = new int[]{20};
31+
32+
String ruleId = "creedengo-java:GCI28";
33+
String ruleMsg = "Optimize Read File Exceptions";
34+
35+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
36+
37+
}
38+
39+
@Test
40+
void testGCI28_3() {
41+
42+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck3.java";
43+
44+
int[] startLines = new int[]{19};
45+
46+
int[] endLines = new int[]{19};
47+
48+
String ruleId = "creedengo-java:GCI28";
49+
String ruleMsg = "Optimize Read File Exceptions";
50+
51+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
52+
53+
}
54+
55+
@Test
56+
void testGCI28_4() {
57+
58+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck4.java";
59+
60+
int[] startLines = new int[]{18};
61+
62+
int[] endLines = new int[]{18};
63+
64+
String ruleId = "creedengo-java:GCI28";
65+
String ruleMsg = "Optimize Read File Exceptions";
66+
67+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
68+
69+
}
70+
71+
@Test
72+
void testGCI28_5() {
73+
74+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/OptimizeReadFileExceptionCheck5.java";
75+
76+
int[] startLines = new int[]{18};
77+
78+
int[] endLines = new int[]{18};
79+
80+
String ruleId = "creedengo-java:GCI28";
81+
String ruleMsg = "Optimize Read File Exceptions";
82+
83+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
84+
85+
}
86+
87+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.greencodeinitiative.creedengo.java.integration.tests;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class GCI2RuleIT extends GCIRulesBase {
6+
7+
@Test
8+
void testGCI2() {
9+
10+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatement.java";
11+
12+
int[] startLines = new int[]{
13+
24, 43, 45, 71, 88, 110,
14+
112, 131, 135, 137, 158, 164,
15+
190, 209, 212, 214, 211, 236,
16+
257, 259
17+
};
18+
19+
int[] endLines = new int[]{
20+
24, 43, 47, 71, 90, 110,
21+
114, 133, 135, 139, 160, 166,
22+
192, 209, 212, 216, 217, 238,
23+
257, 261
24+
};
25+
26+
String ruleId = "creedengo-java:GCI2";
27+
String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
28+
29+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
30+
31+
}
32+
33+
@Test
34+
void testGCI2_compareMethodNoIssue() {
35+
36+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementCompareMethodNoIssue.java";
37+
38+
int[] startLines = new int[]{};
39+
40+
int[] endLines = new int[]{};
41+
42+
String ruleId = "creedengo-java:GCI2";
43+
String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
44+
45+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
46+
47+
}
48+
49+
@Test
50+
void testGCI2_interfaceNoIssue() {
51+
52+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementInterfaceNoIssue.java";
53+
54+
int[] startLines = new int[]{};
55+
56+
int[] endLines = new int[]{};
57+
58+
String ruleId = "creedengo-java:GCI2";
59+
String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
60+
61+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
62+
63+
}
64+
65+
@Test
66+
void testGCI2_noBlockNoIssue() {
67+
68+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoBlockNoIssue.java";
69+
70+
int[] startLines = new int[]{};
71+
72+
int[] endLines = new int[]{};
73+
74+
String ruleId = "creedengo-java:GCI2";
75+
String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
76+
77+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
78+
79+
}
80+
81+
@Test
82+
void testGCI2_noIssue() {
83+
84+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidMultipleIfElseStatementNoIssue.java";
85+
86+
int[] startLines = new int[]{};
87+
88+
int[] endLines = new int[]{};
89+
90+
String ruleId = "creedengo-java:GCI2";
91+
String ruleMsg = "Use a switch statement instead of multiple if-else if possible";
92+
93+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
94+
95+
}
96+
97+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.greencodeinitiative.creedengo.java.integration.tests;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class GCI3RuleIT extends GCIRulesBase {
6+
7+
@Test
8+
void testGCI3_forEachLoopIgnored() {
9+
10+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForEachLoopIgnored.java";
11+
int[] startLines = new int[]{};
12+
int[] endLines = new int[]{};
13+
String ruleId = "creedengo-java:GCI3";
14+
String ruleMsg = "Avoid getting the size of the collection in the loop";
15+
16+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
17+
18+
}
19+
20+
@Test
21+
void testGCI3_forLoopBad() {
22+
23+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopBad.java";
24+
int[] startLines = new int[]{13};
25+
int[] endLines = new int[]{13};
26+
String ruleId = "creedengo-java:GCI3";
27+
String ruleMsg = "Avoid getting the size of the collection in the loop";
28+
29+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
30+
31+
}
32+
33+
@Test
34+
void testGCI3_forEachLoopGood() {
35+
36+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopGood.java";
37+
int[] startLines = new int[]{};
38+
int[] endLines = new int[]{};
39+
String ruleId = "creedengo-java:GCI3";
40+
String ruleMsg = "Avoid getting the size of the collection in the loop";
41+
42+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
43+
44+
}
45+
46+
@Test
47+
void testGCI3_forLoopIgnored() {
48+
49+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInForLoopIgnored.java";
50+
int[] startLines = new int[]{};
51+
int[] endLines = new int[]{};
52+
String ruleId = "creedengo-java:GCI3";
53+
String ruleMsg = "Avoid getting the size of the collection in the loop";
54+
55+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
56+
57+
}
58+
59+
@Test
60+
void testGCI3_whileLoopBad() {
61+
62+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopBad.java";
63+
int[] startLines = new int[]{17};
64+
int[] endLines = new int[]{17};
65+
String ruleId = "creedengo-java:GCI3";
66+
String ruleMsg = "Avoid getting the size of the collection in the loop";
67+
68+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
69+
70+
}
71+
72+
@Test
73+
void testGCI3_whileLoopGood() {
74+
75+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopGood.java";
76+
int[] startLines = new int[]{};
77+
int[] endLines = new int[]{};
78+
String ruleId = "creedengo-java:GCI3";
79+
String ruleMsg = "Avoid getting the size of the collection in the loop";
80+
81+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
82+
83+
}
84+
85+
@Test
86+
void testGCI3_whileLoopIgnored() {
87+
88+
String filePath = "src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidGettingSizeCollectionInWhileLoopIgnored.java";
89+
int[] startLines = new int[]{};
90+
int[] endLines = new int[]{};
91+
String ruleId = "creedengo-java:GCI3";
92+
String ruleMsg = "Avoid getting the size of the collection in the loop";
93+
94+
checkIssuesForFile(filePath, ruleId, ruleMsg, startLines, endLines);
95+
96+
}
97+
98+
}

0 commit comments

Comments
 (0)