Skip to content

Commit 16f530c

Browse files
authored
Rename GraphQL operation to query (#615)
1 parent f520cfa commit 16f530c

12 files changed

Lines changed: 140 additions & 140 deletions

File tree

webtau-feature-testing/examples/scenarios/graphql/Report.groovy

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ class Report {
2626
.map { it.toMap() }
2727
.forEach { additionalData.putAll(it) }
2828

29-
validateSkippedOps(additionalData.graphQLSkippedOperations as Set)
30-
validateCoveredOps(additionalData.graphQLCoveredOperations as Set)
31-
validateOperationStatistics(additionalData.graphQLOperationTimeStatistics)
29+
validateSkippedQueries(additionalData.graphQLSkippedQueries as Set)
30+
validateCoveredQueries(additionalData.graphQLCoveredQueries as Set)
31+
validateQueryStatistics(additionalData.graphQLQueryTimeStatistics)
3232
validateCoverageSummary(additionalData.graphQLCoverageSummary)
3333
}
3434

35-
static void validateSkippedOps(Set skippedOps) {
36-
skippedOps.should == [
35+
static void validateSkippedQueries(Set skippedQueries) {
36+
skippedQueries.should == [
3737
[
3838
name: 'uncomplete',
3939
type: 'mutation'
4040
]
4141
] as Set
4242
}
4343

44-
static void validateCoveredOps(Set coveredOps) {
45-
coveredOps.should == [
44+
static void validateCoveredQueries(Set coveredQueries) {
45+
coveredQueries.should == [
4646
[
4747
name: 'allTasks',
4848
type: 'query'
@@ -58,20 +58,20 @@ class Report {
5858
] as Set
5959
}
6060

61-
static void validateOperationStatistics(opStats) {
62-
opStats.size().should == 3
61+
static void validateQueryStatistics(queryStats) {
62+
queryStats.size().should == 3
6363

64-
def allTasksQueryStats = opStats.find { it.name == 'allTasks' }
64+
def allTasksQueryStats = queryStats.find { it.name == 'allTasks' }
6565
allTasksQueryStats.shouldNot == null
6666
allTasksQueryStats.type.should == 'query'
6767
allTasksQueryStats.statistics.size().shouldBe > 0
6868

69-
def completeMutationStats = opStats.find { it.name == 'complete' }
69+
def completeMutationStats = queryStats.find { it.name == 'complete' }
7070
completeMutationStats.shouldNot == null
7171
completeMutationStats.type.should == 'mutation'
7272
completeMutationStats.statistics.size().shouldBe > 0
7373

74-
def taskByIdQueryStats = opStats.find { it.name == 'taskById' }
74+
def taskByIdQueryStats = queryStats.find { it.name == 'taskById' }
7575
taskByIdQueryStats.shouldNot == null
7676
taskByIdQueryStats.type.should == 'query'
7777
taskByIdQueryStats.statistics.size().shouldBe > 0
@@ -81,18 +81,18 @@ class Report {
8181
summary.should == [
8282
types: [
8383
mutation: [
84-
declaredOperations: 2,
85-
coveredOperations: 1,
84+
declaredQueries: 2,
85+
coveredQueries: 1,
8686
coverage: 0.5
8787
],
8888
query: [
89-
declaredOperations: 2,
90-
coveredOperations: 2,
89+
declaredQueries: 2,
90+
coveredQueries: 2,
9191
coverage: 1.0
9292
]
9393
],
94-
totalDeclaredOperations: 4,
95-
totalCoveredOperations: 3,
94+
totalDeclaredQueries: 4,
95+
totalCoveredQueries: 3,
9696
coverage: 0.75
9797
]
9898
}

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLCoverage.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@
2424

2525
public class GraphQLCoverage {
2626
private final GraphQLSchema schema;
27-
private final GraphQLCoveredOperations coveredOperations = new GraphQLCoveredOperations();
27+
private final GraphQLCoveredQueries coveredQueries = new GraphQLCoveredQueries();
2828

2929
public GraphQLCoverage(GraphQLSchema schema) {
3030
this.schema = schema;
3131
}
3232

33-
public void recordOperation(HttpValidationResult validationResult) {
33+
public void recordQuery(HttpValidationResult validationResult) {
3434
if (!schema.isSchemaDefined() || !validationResult.getRequestMethod().equals("POST")) {
3535
return;
3636
}
3737

38-
Set<GraphQLOperation> graphQLOperations = schema.findOperations(validationResult.getRequestBody());
39-
graphQLOperations.forEach(operation -> coveredOperations.add(operation, validationResult.getId(), validationResult.getElapsedTime()));
38+
Set<GraphQLQuery> graphQLQueries = schema.findQueries(validationResult.getRequestBody());
39+
graphQLQueries.forEach(query -> coveredQueries.add(query, validationResult.getId(), validationResult.getElapsedTime()));
4040
}
4141

42-
Stream<GraphQLOperation> nonCoveredOperations() {
43-
return schema.getSchemaDeclaredOperations().filter(o -> !coveredOperations.contains(o));
42+
Stream<GraphQLQuery> nonCoveredQueries() {
43+
return schema.getSchemaDeclaredQueries().filter(o -> !coveredQueries.contains(o));
4444
}
4545

46-
Stream<GraphQLOperation> coveredOperations() {
47-
return coveredOperations.coveredOperations();
46+
Stream<GraphQLQuery> coveredQueries() {
47+
return coveredQueries.coveredQueries();
4848
}
4949

50-
Stream<GraphQLOperation> declaredOperations() {
51-
return schema.getSchemaDeclaredOperations();
50+
Stream<GraphQLQuery> declaredQueries() {
51+
return schema.getSchemaDeclaredQueries();
5252
}
5353

54-
Stream<Map.Entry<GraphQLOperation, Set<GraphQLCoveredOperations.Call>>> actualCalls() {
55-
return coveredOperations.getActualCalls();
54+
Stream<Map.Entry<GraphQLQuery, Set<GraphQLCoveredQueries.Call>>> actualCalls() {
55+
return coveredQueries.getActualCalls();
5656
}
5757
}

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLCoverageRecorder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
public class GraphQLCoverageRecorder implements HttpValidationHandler {
2323
@Override
2424
public void validate(HttpValidationResult validationResult) {
25-
GraphQL.getCoverage().recordOperation(validationResult);
25+
GraphQL.getCoverage().recordQuery(validationResult);
2626
}
2727
}

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLCoveredOperations.java renamed to webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLCoveredQueries.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,29 @@
2222
import java.util.Set;
2323
import java.util.stream.Stream;
2424

25-
public class GraphQLCoveredOperations {
26-
private final Map<GraphQLOperation, Set<Call>> actualCallsIdsByOperation;
25+
public class GraphQLCoveredQueries {
26+
private final Map<GraphQLQuery, Set<Call>> actualCallsIdsByQuery;
2727

28-
GraphQLCoveredOperations() {
29-
actualCallsIdsByOperation = new LinkedHashMap<>();
28+
GraphQLCoveredQueries() {
29+
actualCallsIdsByQuery = new LinkedHashMap<>();
3030
}
3131

32-
public void add(GraphQLOperation operation, String id, long elapsedTime) {
33-
Set<Call> calls = actualCallsIdsByOperation.computeIfAbsent(operation, k -> new LinkedHashSet<>());
32+
public void add(GraphQLQuery query, String id, long elapsedTime) {
33+
Set<Call> calls = actualCallsIdsByQuery.computeIfAbsent(query, k -> new LinkedHashSet<>());
3434

3535
calls.add(new Call(id, elapsedTime));
3636
}
3737

38-
public boolean contains(GraphQLOperation operation) {
39-
return actualCallsIdsByOperation.containsKey(operation);
38+
public boolean contains(GraphQLQuery query) {
39+
return actualCallsIdsByQuery.containsKey(query);
4040
}
4141

42-
Stream<GraphQLOperation> coveredOperations() {
43-
return actualCallsIdsByOperation.keySet().stream();
42+
Stream<GraphQLQuery> coveredQueries() {
43+
return actualCallsIdsByQuery.keySet().stream();
4444
}
4545

46-
public Stream<Map.Entry<GraphQLOperation, Set<Call>>> getActualCalls() {
47-
return actualCallsIdsByOperation.entrySet().stream();
46+
public Stream<Map.Entry<GraphQLQuery, Set<Call>>> getActualCalls() {
47+
return actualCallsIdsByQuery.entrySet().stream();
4848
}
4949

5050
public static class Call {

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLOperation.java renamed to webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLQuery.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import java.util.Map;
2121
import java.util.Objects;
2222

23-
public class GraphQLOperation {
23+
public class GraphQLQuery {
2424
private final String name;
25-
private final GraphQLOperationType type;
25+
private final GraphQLQueryType type;
2626

27-
GraphQLOperation(String name, GraphQLOperationType type) {
27+
GraphQLQuery(String name, GraphQLQueryType type) {
2828
this.name = name;
2929
this.type = type;
3030
}
@@ -33,7 +33,7 @@ public String getName() {
3333
return name;
3434
}
3535

36-
public GraphQLOperationType getType() {
36+
public GraphQLQueryType getType() {
3737
return type;
3838
}
3939

@@ -49,7 +49,7 @@ public GraphQLOperationType getType() {
4949
public boolean equals(Object o) {
5050
if (this == o) return true;
5151
if (o == null || getClass() != o.getClass()) return false;
52-
GraphQLOperation that = (GraphQLOperation) o;
52+
GraphQLQuery that = (GraphQLQuery) o;
5353
return Objects.equals(name, that.name) &&
5454
type == that.type;
5555
}
@@ -61,7 +61,7 @@ public int hashCode() {
6161

6262
@Override
6363
public String toString() {
64-
return "GraphQLOperation{" +
64+
return "GraphQLQuery{" +
6565
"name='" + name + '\'' +
6666
", type=" + type +
6767
'}';

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLOperationType.java renamed to webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLQueryType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.testingisdocumenting.webtau.graphql;
1818

19-
public enum GraphQLOperationType {
19+
public enum GraphQLQueryType {
2020
QUERY,
2121
MUTATION,
2222
SUBSCRIPTION

webtau-graphql/src/main/java/org/testingisdocumenting/webtau/graphql/GraphQLReportDataProvider.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,43 +45,43 @@ public GraphQLReportDataProvider(Supplier<GraphQLCoverage> coverageSupplier) {
4545

4646
@Override
4747
public Stream<ReportCustomData> provide(WebTauTestList tests) {
48-
List<? extends Map<String, ?>> nonCoveredOperations = coverageSupplier.get().nonCoveredOperations()
49-
.map(GraphQLOperation::toMap)
48+
List<? extends Map<String, ?>> nonCoveredQueries = coverageSupplier.get().nonCoveredQueries()
49+
.map(GraphQLQuery::toMap)
5050
.collect(Collectors.toList());
5151

52-
List<? extends Map<String, ?>> coveredOperations = coverageSupplier.get().coveredOperations()
53-
.map(GraphQLOperation::toMap)
52+
List<? extends Map<String, ?>> coveredQueries = coverageSupplier.get().coveredQueries()
53+
.map(GraphQLQuery::toMap)
5454
.collect(Collectors.toList());
5555

56-
List<? extends Map<String, ?>> timingByOperation = computeTiming();
56+
List<? extends Map<String, ?>> timingByQuery = computeTiming();
5757

5858
Map<String, ?> coverageSummary = computeCoverageSummary();
5959

6060
return Stream.of(
61-
new ReportCustomData("graphQLSkippedOperations", nonCoveredOperations),
62-
new ReportCustomData("graphQLCoveredOperations", coveredOperations),
63-
new ReportCustomData("graphQLOperationTimeStatistics", timingByOperation),
61+
new ReportCustomData("graphQLSkippedQueries", nonCoveredQueries),
62+
new ReportCustomData("graphQLCoveredQueries", coveredQueries),
63+
new ReportCustomData("graphQLQueryTimeStatistics", timingByQuery),
6464
new ReportCustomData("graphQLCoverageSummary", coverageSummary));
6565
}
6666

6767
private List<? extends Map<String, ?>> computeTiming() {
6868
return coverageSupplier.get().actualCalls().map(GraphQLReportDataProvider::computeTiming).collect(Collectors.toList());
6969
}
7070

71-
private static Map<String, ?> computeTiming(Map.Entry<GraphQLOperation, Set<GraphQLCoveredOperations.Call>> entry) {
71+
private static Map<String, ?> computeTiming(Map.Entry<GraphQLQuery, Set<GraphQLCoveredQueries.Call>> entry) {
7272
Map<String, Object> data = new LinkedHashMap<>();
7373
data.put("name", entry.getKey().getName());
7474
data.put("type", entry.getKey().getType().name().toLowerCase());
7575

7676
Map<String, Object> statistics = new LinkedHashMap<>();
7777
data.put("statistics", statistics);
7878

79-
LongSummaryStatistics summaryStatistics = entry.getValue().stream().collect(Collectors.summarizingLong(GraphQLCoveredOperations.Call::getElapsedTime));
79+
LongSummaryStatistics summaryStatistics = entry.getValue().stream().collect(Collectors.summarizingLong(GraphQLCoveredQueries.Call::getElapsedTime));
8080
statistics.put("mean", summaryStatistics.getAverage());
8181
statistics.put("min", summaryStatistics.getMin());
8282
statistics.put("max", summaryStatistics.getMax());
8383

84-
double[] times = entry.getValue().stream().map(GraphQLCoveredOperations.Call::getElapsedTime).mapToDouble(Long::doubleValue).sorted().toArray();
84+
double[] times = entry.getValue().stream().map(GraphQLCoveredQueries.Call::getElapsedTime).mapToDouble(Long::doubleValue).sorted().toArray();
8585
Percentile percentile = new Percentile();
8686
statistics.put("p95", percentile.evaluate(times, 95));
8787
statistics.put("p99", percentile.evaluate(times, 99));
@@ -91,29 +91,29 @@ public Stream<ReportCustomData> provide(WebTauTestList tests) {
9191

9292
private Map<String, ?> computeCoverageSummary() {
9393
Map<String, Object> summary = new HashMap<>();
94-
Map<GraphQLOperationType, List<GraphQLOperation>> declaredOpByType = coverageSupplier.get().declaredOperations().collect(Collectors.groupingBy(GraphQLOperation::getType));
95-
Map<GraphQLOperationType, List<GraphQLOperation>> coveredOpsByType = coverageSupplier.get().coveredOperations().collect(Collectors.groupingBy(GraphQLOperation::getType));
94+
Map<GraphQLQueryType, List<GraphQLQuery>> declaredQueriesByType = coverageSupplier.get().declaredQueries().collect(Collectors.groupingBy(GraphQLQuery::getType));
95+
Map<GraphQLQueryType, List<GraphQLQuery>> coveredQueriesByType = coverageSupplier.get().coveredQueries().collect(Collectors.groupingBy(GraphQLQuery::getType));
9696

9797
Map<String, Object> summaryByType = new HashMap<>();
98-
declaredOpByType.forEach((type, ops) -> {
99-
double coveredOperations = coveredOpsByType.getOrDefault(type, Collections.emptyList()).size();
100-
double coverage = coveredOperations / ops.size();
98+
declaredQueriesByType.forEach((type, queries) -> {
99+
double coveredQueries = coveredQueriesByType.getOrDefault(type, Collections.emptyList()).size();
100+
double coverage = coveredQueries / queries.size();
101101

102102
Map<String, Object> summaryForType = new HashMap<>();
103-
summaryForType.put("declaredOperations", ops.size());
104-
summaryForType.put("coveredOperations", coveredOperations);
103+
summaryForType.put("declaredQueries", queries.size());
104+
summaryForType.put("coveredQueries", coveredQueries);
105105
summaryForType.put("coverage", coverage);
106106

107107
summaryByType.put(type.name().toLowerCase(), summaryForType);
108108
});
109109
summary.put("types", summaryByType);
110110

111-
double coveredOperations = coveredOpsByType.values().stream().mapToInt(List::size).sum();
112-
double declaredOperations = declaredOpByType.values().stream().mapToInt(List::size).sum();
113-
double totalCoverage = coveredOperations / declaredOperations;
111+
double coveredQueries = coveredQueriesByType.values().stream().mapToInt(List::size).sum();
112+
double declaredQueries = declaredQueriesByType.values().stream().mapToInt(List::size).sum();
113+
double totalCoverage = coveredQueries / declaredQueries;
114114

115-
summary.put("totalDeclaredOperations", declaredOperations);
116-
summary.put("totalCoveredOperations", coveredOperations);
115+
summary.put("totalDeclaredQueries", declaredQueries);
116+
summary.put("totalCoveredQueries", coveredQueries);
117117
summary.put("coverage", totalCoverage);
118118

119119
return summary;

0 commit comments

Comments
 (0)