Skip to content

Commit 215b03a

Browse files
http: fix contain handler marking values as failed
1 parent d841052 commit 215b03a

4 files changed

Lines changed: 59 additions & 8 deletions

File tree

webtau-core/src/main/java/org/testingisdocumenting/webtau/expectation/contain/ContainAnalyzer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2021 webtau maintainers
23
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +19,7 @@
1819

1920
import org.testingisdocumenting.webtau.data.render.DataRenderers;
2021
import org.testingisdocumenting.webtau.expectation.ActualPath;
22+
import org.testingisdocumenting.webtau.expectation.contain.handlers.IterableContainHandler;
2123
import org.testingisdocumenting.webtau.expectation.contain.handlers.NullContainHandler;
2224
import org.testingisdocumenting.webtau.expectation.equality.ActualPathMessage;
2325
import org.testingisdocumenting.webtau.utils.ServiceLoaderUtils;
@@ -30,7 +32,7 @@
3032
import static java.util.stream.Collectors.joining;
3133

3234
public class ContainAnalyzer {
33-
private static List<ContainHandler> handlers = discoverHandlers();
35+
private static final List<ContainHandler> handlers = discoverHandlers();
3436

3537
private final List<ActualPathMessage> mismatches;
3638

@@ -85,6 +87,7 @@ private static List<ContainHandler> discoverHandlers() {
8587
List<ContainHandler> result = new ArrayList<>();
8688
result.add(new NullContainHandler());
8789
result.addAll(ServiceLoaderUtils.load(ContainHandler.class));
90+
result.add(new IterableContainHandler());
8891

8992
return result;
9093
}

webtau-core/src/main/resources/META-INF/services/org.testingisdocumenting.webtau.expectation.contain.ContainHandler

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@
1414
# limitations under the License.
1515
#
1616

17-
org.testingisdocumenting.webtau.expectation.contain.handlers.StringContainHandler
18-
org.testingisdocumenting.webtau.expectation.contain.handlers.IterableContainHandler
17+
org.testingisdocumenting.webtau.expectation.contain.handlers.StringContainHandler

webtau-http-groovy/src/test/groovy/org/testingisdocumenting/webtau/http/HttpGroovyTest.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.testingisdocumenting.webtau.http
1919

2020
import org.junit.Test
21+
import org.testingisdocumenting.webtau.data.traceable.CheckLevel
2122
import org.testingisdocumenting.webtau.http.datanode.DataNode
2223
import org.testingisdocumenting.webtau.http.datanode.GroovyDataNode
2324
import org.testingisdocumenting.webtau.http.testserver.TestServerResponse
@@ -527,6 +528,18 @@ class HttpGroovyTest extends HttpTestBase {
527528
}
528529
}
529530

531+
@Test
532+
void "list contain check level"() {
533+
http.get("/end-point") {
534+
list.should contain(2)
535+
}
536+
537+
def body = http.lastValidationResult.bodyNode
538+
body.get("list[0]").traceableValue.checkLevel.should == CheckLevel.None
539+
body.get("list[1]").traceableValue.checkLevel.should == CheckLevel.ExplicitPassed
540+
body.get("list[2]").traceableValue.checkLevel.should == CheckLevel.None
541+
}
542+
530543
@Test
531544
void "groovy find on list"() {
532545
def found = http.get("/end-point") {

webtau-http/src/test/groovy/org/testingisdocumenting/webtau/http/datanode/DataNodeListContainHandlerTest.groovy

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright 2021 webtau maintainers
23
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,15 +26,32 @@ import static org.testingisdocumenting.webtau.data.traceable.CheckLevel.FuzzyPas
2526
import static org.testingisdocumenting.webtau.data.traceable.CheckLevel.None
2627

2728
class DataNodeListContainHandlerTest {
28-
def listOfNames = [
29+
def listOfFirstNames = ['FN0', 'FN1', 'FN2', 'FN3']
30+
31+
def listOfFullNames = [
2932
[firstName: 'FN0', lastName: 'LN0'],
3033
[firstName: 'FN1', lastName: 'LN1'],
3134
[firstName: 'FN2', lastName: 'LN2'],
3235
[firstName: 'FN3', lastName: 'LN3']]
3336

37+
38+
@Test
39+
void "should mark single containing items with passed status and not change other item statuses"() {
40+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), listOfFirstNames)
41+
42+
dataNode.get(0).getTraceableValue().updateCheckLevel(FuzzyPassed)
43+
44+
dataNode.should contain('FN2')
45+
46+
dataNode.get(0).getTraceableValue().checkLevel.should == FuzzyPassed
47+
dataNode.get(1).getTraceableValue().checkLevel.should == None
48+
dataNode.get(2).getTraceableValue().checkLevel.should == ExplicitPassed
49+
dataNode.get(3).getTraceableValue().checkLevel.should == None
50+
}
51+
3452
@Test
3553
void "should mark containing items with passed status and not change other item statuses"() {
36-
def dataNode = DataNodeBuilder.fromList(new DataNodeId("body"), listOfNames)
54+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), listOfFullNames)
3755

3856
dataNode.get(0).get('firstName').getTraceableValue().updateCheckLevel(FuzzyPassed)
3957

@@ -49,9 +67,27 @@ class DataNodeListContainHandlerTest {
4967
dataNode.get(3).get('lastName').getTraceableValue().checkLevel.should == ExplicitPassed
5068
}
5169

70+
@Test
71+
void "should mark containing items with passed status and not change other item statuses when compare derived items"() {
72+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), listOfFullNames)
73+
74+
dataNode.get(0).get('firstName').getTraceableValue().updateCheckLevel(FuzzyPassed)
75+
76+
dataNode.get("firstName").should contain('FN3')
77+
78+
dataNode.get(0).get('firstName').getTraceableValue().checkLevel.should == FuzzyPassed
79+
dataNode.get(0).get('lastName').getTraceableValue().checkLevel.should == None
80+
dataNode.get(1).get('firstName').getTraceableValue().checkLevel.should == None
81+
dataNode.get(1).get('lastName').getTraceableValue().checkLevel.should == None
82+
dataNode.get(2).get('firstName').getTraceableValue().checkLevel.should == None
83+
dataNode.get(2).get('lastName').getTraceableValue().checkLevel.should == None
84+
dataNode.get(3).get('firstName').getTraceableValue().checkLevel.should == ExplicitPassed
85+
dataNode.get(3).get('lastName').getTraceableValue().checkLevel.should == None
86+
}
87+
5288
@Test
5389
void "should mark all items as failed when item is not present"() {
54-
def dataNode = DataNodeBuilder.fromList(new DataNodeId("body"), listOfNames)
90+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), listOfFullNames)
5591

5692
code {
5793
dataNode.should contain([firstName: 'FN8', lastName: 'LN8'])
@@ -63,15 +99,15 @@ class DataNodeListContainHandlerTest {
6399

64100
@Test
65101
void "should mark all items as fuzzy passed when item is not present and should not be present"() {
66-
def dataNode = DataNodeBuilder.fromList(new DataNodeId("body"), [1, 2, 3])
102+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), [1, 2, 3])
67103
dataNode.shouldNot contain(8)
68104

69105
dataNode.elements().collect { it.getTraceableValue().checkLevel }.should == [FuzzyPassed, FuzzyPassed, FuzzyPassed]
70106
}
71107

72108
@Test
73109
void "should mark containing items as failed when when they should not be present"() {
74-
def dataNode = DataNodeBuilder.fromList(new DataNodeId("body"), listOfNames)
110+
def dataNode = DataNodeBuilder.fromList(new DataNodeId('body'), listOfFullNames)
75111

76112
code {
77113
dataNode.shouldNot contain([firstName: 'FN2', lastName: 'LN2'])

0 commit comments

Comments
 (0)