Skip to content

Commit

Permalink
Merge pull request #15 from osvalda/PAC-012
Browse files Browse the repository at this point in the history
PAC-012 | comment and ignore options are added
  • Loading branch information
osvalda authored May 26, 2024
2 parents 400bedc + 8e42e19 commit e6bf6ca
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 39 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ DELETE /posts/{post_id}, Posts
GET /posts/{post_id}/comments, Comments
GET /comments/{post_id}, Comments
# comment line
# a star marks the endpoint to be ignored
* GET /posts/{post_id}/pics, Pictures
GET /posts/{post_id}/pics, Pictures
...
```
Expand Down
32 changes: 16 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'io.github.osvalda'
version '1.2.1'
version '1.2.2'

sourceCompatibility = 1.8

Expand Down Expand Up @@ -42,24 +42,24 @@ jacocoTestReport {
}

dependencies {
compile group: 'org.testng', name: 'testng', version: '7.4.0'
compile group: 'org.junit.jupiter', name:'junit-jupiter-engine', version:'5.8.1'
compile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.8.1'
implementation group: 'org.testng', name: 'testng', version: '7.4.0'
implementation group: 'org.junit.jupiter', name:'junit-jupiter-engine', version:'5.8.1'
implementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.8.1'

compile group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
compile group: 'org.freemarker', name: 'freemarker', version: '2.3.29'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
compile group: 'com.google.inject', name: 'guice', version: '4.2.3'
compile group: 'io.swagger.parser.v3', name: 'swagger-parser-v3', version: '2.0.21'
implementation group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.30'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
implementation group: 'com.google.guava', name: 'guava', version: '11.0.2'
implementation group: 'com.google.inject', name: 'guice', version: '4.2.3'
implementation group: 'io.swagger.parser.v3', name: 'swagger-parser-v3', version: '2.0.21'

compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

annotationProcessor 'org.projectlombok:lombok:1.18.6'

testCompile group: 'org.assertj', name: 'assertj-core', version: '3.16.1'
testCompile group: 'org.jmockit', name: 'jmockit', version: '1.41'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.15.0'
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.16.1'
testImplementation group: 'org.jmockit', name: 'jmockit', version: '1.41'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.15.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class CoverageReporter {
protected static final String APP_NAME = "appName";
protected static final String BAR_CHART_HEIGHT = "barChartHeight";
protected static final String BAR_CHART_WIDTH = "barChartWidth";
protected static final String IGNORED_NUMBER = "ignoredEndpointNumber";

protected void saveReportResult(Map<String, Object> templateInput) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void close() {
templateInput.put(AREA_NUMBER, areaWiseEndpointMap.keySet().size());
templateInput.put(CURRENT_DATE_AND_TIME, dateAndTime);
templateInput.put(APP_NAME, appName);
templateInput.put(IGNORED_NUMBER, coverages.values().stream().filter(CoverageObject::isIgnored).count());
if(!barChartHeight.isEmpty() && !barChartWidth.isEmpty()) {
templateInput.put(BAR_CHART_HEIGHT, barChartHeight);
templateInput.put(BAR_CHART_WIDTH, barChartWidth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String
templateInput.put(AREA_WISE_ENDPOINTS, PitayaMapArrangeUtility.collectAreaWiseEndpointDetails(coverages));
templateInput.put(ENDPOINT_COVERAGE, PitayaMapArrangeUtility.arrangeEndpointsByAreas(coverages));
templateInput.put(ALL_ENDPOINTS_NUMBER, coverages.keySet().size());
templateInput.put(IGNORED_NUMBER, coverages.values().stream().filter(CoverageObject::isIgnored).count());
templateInput.put(COVERED_ENDPOINTS_NUMBER, countCoveredEndpoints(coverages));
templateInput.put(AREA_NUMBER, PitayaMapArrangeUtility.arrangeEndpointsByAreas(coverages).keySet().size());
templateInput.put(CURRENT_DATE_AND_TIME, dateAndTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ public Map<String, CoverageObject> processEndpointListFile(String fileName) {
throw new IllegalStateException("The endpoint input file is empty!");
}
FileUtils.readLines(file, StandardCharsets.UTF_8).forEach(fileLine -> {
boolean ignored = false;
if(!fileLine.isEmpty()) {
fileLine = StringUtils.strip(fileLine);
if (fileLine.startsWith("#")) {
return;
}
if (fileLine.startsWith("*")) {
fileLine = StringUtils.strip(fileLine, "* \n\t");
ignored = true;
}
String[] endpointLine = StringUtils.splitByWholeSeparator(fileLine, ", ");
if(endpointLine.length == 2) {
endpoints.put(endpointLine[0], new CoverageObject(endpointLine[1], endpointLine[0]));
endpoints.put(endpointLine[0], new CoverageObject(endpointLine[1], endpointLine[0], ignored));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ public class AreaWiseCoverageObject {
private int coveredEndpoints;
@Getter
private int allEndpoints;
@Getter
private int ignoredEndpoints = 0;

/**
* Creates a new area wise coverage object with first endpoint
*
* @param covered how many test case cover the first endpoint
*/
public AreaWiseCoverageObject(int covered) {
public AreaWiseCoverageObject(int covered, boolean ignored) {
allEndpoints = 1;
if(covered > 0)
if(covered > 0) {
this.coveredEndpoints = 1;
}
if (ignored) {
ignoredEndpoints += 1;
}
}

/**
Expand All @@ -38,16 +44,20 @@ public AreaWiseCoverageObject() {
*
* @param covered how many test case cover the newly added endpoint
*/
public void increaseCoverage(int covered) {
public void increaseCoverage(int covered, boolean ignored) {
allEndpoints += 1;
if(covered > 0)
if(covered > 0) {
this.coveredEndpoints += 1;
}
if (ignored) {
ignoredEndpoints += 1;
}
}

/**
* Returns the number of uncovered endpoints of the area.
*/
public int getUncoveredEndpointNum() {
return allEndpoints - coveredEndpoints;
return allEndpoints - coveredEndpoints - ignoredEndpoints;
}
}
14 changes: 14 additions & 0 deletions src/main/java/io/github/osvalda/pitaya/models/CoverageObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class CoverageObject {
@Getter
private String api = "NoN";
@Getter
private boolean ignored = false;
@Getter
private List<ITestResult> testCases = new ArrayList<>();

/**
Expand All @@ -33,8 +35,20 @@ public class CoverageObject {
* @param endpoint the actual endpoint
*/
public CoverageObject(String area, String endpoint) {
this(area, endpoint, false);
}

/**
* Creates a new coverage object for an area's endpoint
*
* @param area the area where the endpoint belongs
* @param endpoint the actual endpoint
* @param ignored marks the endpoint to be ignored in the report
*/
public CoverageObject(String area, String endpoint, boolean ignored) {
this.area = area;
this.api = endpoint;
this.ignored = ignored;
if(!endpoint.isEmpty()) {
this.endpoint = StringUtils.substringAfter(endpoint, SEPARATOR);
this.method = StringUtils.substringBefore(endpoint, SEPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static Map<String, AreaWiseCoverageObject> collectAreaWiseEndpointDetails
Map<String, AreaWiseCoverageObject> areaWiseCoverages = new HashMap<>();
coverages.values().forEach(endpoint -> {
if (areaWiseCoverages.containsKey(endpoint.getArea())) {
areaWiseCoverages.get(endpoint.getArea()).increaseCoverage(endpoint.getTestCases().size());
areaWiseCoverages.get(endpoint.getArea()).increaseCoverage(endpoint.getTestCases().size(), endpoint.isIgnored());
} else {
areaWiseCoverages.put(endpoint.getArea(), new AreaWiseCoverageObject(endpoint.getTestCases().size()));
areaWiseCoverages.put(endpoint.getArea(), new AreaWiseCoverageObject(endpoint.getTestCases().size(), endpoint.isIgnored()));
}
});
return areaWiseCoverages;
Expand All @@ -62,6 +62,8 @@ public static Map<String, AreaWiseCoverageObject> collectAreaWiseEndpointDetails
* @return the number of endpoints with at least one corresponding test case
*/
public static int countCoveredEndpoints(Map<String, CoverageObject> coverages) {
return Math.toIntExact(coverages.values().stream().filter(endpoint -> !endpoint.getTestCases().isEmpty()).count());
return Math.toIntExact(coverages.values().stream().filter(endpoint ->
!endpoint.getTestCases().isEmpty() && !endpoint.isIgnored())
.count());
}
}
28 changes: 21 additions & 7 deletions src/main/resources/reportTemplates/coverageReportTemplate.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>

<#assign missedEndpointNum = (allEndpointsNumber - coveredEndpointsNumber)>
<#assign missedEndpointNum = (allEndpointsNumber - coveredEndpointsNumber - ignoredEndpointNumber)>
<#assign coveragePercent = ((coveredEndpointsNumber / allEndpointsNumber) * 100)>
<#if coveragePercent == 100>
<#assign left = '224px'>
Expand Down Expand Up @@ -97,6 +97,11 @@ h3 {
box-shadow: 0px 0px 9px 0px rgba(249, 62, 62, 0.1);
border: 1px solid #f93e3e;
}
.responsive-table .table-row-ignore {
background-color: rgba(128, 209, 217, 0.15);
box-shadow: 0px 0px 9px 0px rgba(89, 195, 205, 0.1);
border: 1px solid #59C3CD;
}
.responsive-table .detail-content {
border-radius: 0px;
border-bottom-left-radius: 3px;
Expand Down Expand Up @@ -166,6 +171,9 @@ h3 {
.responsive-table .skipped {
color: orange;
}
.responsive-table .ignored {
color: #59C3CD;
}
.responsive-table .hed-1 {
flex-basis: 10%;
Expand Down Expand Up @@ -285,7 +293,8 @@ h3 {
var data = google.visualization.arrayToDataTable([
['Coverage', 'Percentage'],
['Covered', ${coveredEndpointsNumber}],
['Missed', ${missedEndpointNum}]
['Missed', ${missedEndpointNum}],
['Ignored', ${ignoredEndpointNumber}]
]);
var options = {
Expand All @@ -297,16 +306,16 @@ h3 {
position: 'none'
},
'pieSliceText': 'none',
'colors': ['#7DCEA0', '#D98880']};
'colors': ['#7DCEA0', '#D98880', '#80D1D9']};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
function drawAreaWiseBarChart() {
var data = google.visualization.arrayToDataTable([
['Area', 'Covered', 'Missing', 'Average'],
['Area', 'Covered', 'Missing', 'Ignored'],
<#list endpointCoverage?keys as key>
['${key}', ${areaWiseEndpoints[key].getCoveredEndpoints()}, ${areaWiseEndpoints[key].getUncoveredEndpointNum()}, (${coveredEndpointsNumber}/${areaNumber})], ${'\n'}
['${key}', ${areaWiseEndpoints[key].getCoveredEndpoints()}, ${areaWiseEndpoints[key].getUncoveredEndpointNum()}, ${areaWiseEndpoints[key].getIgnoredEndpoints()}], ${'\n'}
</#list>
]);
Expand All @@ -316,8 +325,8 @@ h3 {
hAxis: {title: 'Areas'},
animation: {startup: true, easing: 'inAndOut', duration: 700},
seriesType: 'bars',
colors: ['7DCEA0', '#D98880', '#d35ebe'],
series: {2: {type: 'line'}}
colors: ['7DCEA0', '#D98880', '#80D1D9'],
isStacked: true
};
var chart = new google.visualization.ComboChart(document.getElementById('chart_div'));
Expand Down Expand Up @@ -395,10 +404,12 @@ h3 {
<tr>
<td>Covered</td>
<td>Missing</td>
<td>Ignored</td>
</tr>
<tr>
<td>${coveredEndpointsNumber}</td>
<td>${missedEndpointNum}</td>
<td>${ignoredEndpointNumber}</td>
</tr>
</table>
Expand All @@ -421,6 +432,9 @@ h3 {
<#if endpoint.testCases?size gt 0>
<#assign lineClass = 'table-row-success'>
<#assign color = 'passed'>
<#elseif endpoint.ignored>
<#assign lineClass = 'table-row-ignore'>
<#assign color = 'ignored'>
<#else>
<#assign lineClass = 'table-row-danger'>
<#assign color = 'failed'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public void testCorruptedPitayaTextEndpointListFile() {
public void testPitayaTextEndpointListFile() {
Map<String, CoverageObject> stringCoverageObjectMap = new PitayaTextEndpointList().processEndpointListFile("endpoints/all_endpoints.txt");

assertThat(stringCoverageObjectMap).hasSize(14).containsKey("PUT /posts/pics");
assertThat(stringCoverageObjectMap).hasSize(15).containsKey("PUT /posts/pics");
assertThat(stringCoverageObjectMap.get("PUT /posts/pics").getArea()).isEqualTo("Pictures");
assertThat(stringCoverageObjectMap.get("PUT /posts/pics").getTestCases()).isEmpty();
assertThat(stringCoverageObjectMap.get("POST /posts/ignored").isIgnored()).isTrue();
assertThat(stringCoverageObjectMap).doesNotContainKey("PUT /posts/commented");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ public class ModelTests {

@Test
public void testAreaWiseEndpointObjectWithCoveredInitialEndpoint() {
AreaWiseCoverageObject sut = new AreaWiseCoverageObject(1);
AreaWiseCoverageObject sut = new AreaWiseCoverageObject(1, false);
assertThat(sut.getAllEndpoints()).isEqualTo(1);
assertThat(sut.getCoveredEndpoints()).isEqualTo(1);
assertThat(sut.getUncoveredEndpointNum()).isZero();
}

@Test
public void testAreaWiseEndpointObjectWithIgnoredInitialEndpoint() {
AreaWiseCoverageObject sut = new AreaWiseCoverageObject(0, true);
assertThat(sut.getAllEndpoints()).isEqualTo(1);
assertThat(sut.getCoveredEndpoints()).isZero();
assertThat(sut.getUncoveredEndpointNum()).isZero();
assertThat(sut.getIgnoredEndpoints()).isEqualTo(1);
}

@Test
public void testAreaWiseEndpointObjectDefaultConstructor () {
AreaWiseCoverageObject sut = new AreaWiseCoverageObject();
Expand All @@ -28,13 +37,16 @@ public void testAreaWiseEndpointObjectDefaultConstructor () {

@Test
public void testAreaWiseEndpointObjectIncreasedEndpoints () {
AreaWiseCoverageObject sut = new AreaWiseCoverageObject(1);
sut.increaseCoverage(11);
sut.increaseCoverage(1);
sut.increaseCoverage(0);
AreaWiseCoverageObject sut = new AreaWiseCoverageObject(1, false);
sut.increaseCoverage(11, false);
sut.increaseCoverage(1, false);
sut.increaseCoverage(0, false);
sut.increaseCoverage(0, true);
sut.increaseCoverage(0, true);
assertThat(sut.getCoveredEndpoints()).isEqualTo(3);
assertThat(sut.getAllEndpoints()).isEqualTo(4);
assertThat(sut.getAllEndpoints()).isEqualTo(6);
assertThat(sut.getUncoveredEndpointNum()).isEqualTo(1);
assertThat(sut.getIgnoredEndpoints()).isEqualTo(2);
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/endpoints/all_endpoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ POST /posts, Posts
PUT /posts/{post_id}, Posts
PATCH /posts/{post_id}, Posts
DELETE /posts/{post_id}, Posts
* POST /posts/ignored, Posts
# PUT /posts/commented, Posts

# this is a regular comment

GET /posts/{post_id}/comments, Comments
GET /comments/{post_id}, Comments
Expand Down

0 comments on commit e6bf6ca

Please sign in to comment.