Skip to content

Commit 6dec9c8

Browse files
[GH-251] Added hide-operation-in-expected option
1 parent b205ebc commit 6dec9c8

File tree

11 files changed

+274
-98
lines changed

11 files changed

+274
-98
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# th2 check1 (4.8.0)
1+
# th2 check1 (4.9.0)
22

33
## Overview
44

@@ -145,6 +145,7 @@ spec:
145145
check-null-value-as-empty: false
146146
enable-checkpoint-events-publication: true
147147
await-root-event-storing-on-wait-for-result: false
148+
hide-operation-in-expected: false
148149
rules-execution-threads: 1
149150
pins:
150151
mq:
@@ -204,6 +205,7 @@ spec:
204205
decimal-precision: '0.00001'
205206
enable-checkpoint-events-publication: true
206207
await-root-event-storing-on-wait-for-result: false
208+
hide-operation-in-expected: false
207209
rules-execution-threads: 1
208210
```
209211
@@ -292,6 +294,21 @@ spec:
292294
```
293295
_Disabled by default._
294296

297+
#### hide-operation-in-expected
298+
299+
Hides operation name from expected values for operations: `IN`, `NOT_IN`, `LIKE`, `NOT_LIKE`, `WILDCARD`, `NOT_WILDCARD`
300+
301+
| operation | option false | option true |
302+
|----------------|---------------------------|------------------|
303+
| `IN` | `IN [opt-1, opt-2]` | `[opt-1, opt-2]` |
304+
| `NOT_IN` | `NOT_IN [opt-1, opt-2]` | `[opt-1, opt-2]` |
305+
| `LIKE` | `LIKE regex.*` | `regex.*` |
306+
| `NOT_LIKE` | `NOT_LIKE regex.*` | `regex.*` |
307+
| `WILDCARD` | `WILDCARD wildcard?*` | `wildcard?*` |
308+
| `NOT_WILDCARD` | `NOT_WILDCARD wildcard?*` | `wildcard?*` |
309+
310+
_Disabled by default._
311+
295312
## Required pins
296313

297314
The Check1 component has two types of pin:
@@ -334,6 +351,20 @@ The `th2_check1_active_tasks_number` metric separate rules with label `rule_type
334351

335352
## Release Notes
336353

354+
### 4.9.0
355+
356+
+ [[GH-251] Filter with either IN, NOT_IN, LIKE, NOT_LIKE, WILDCARD, NOT_WILDCARD operation adds the operation name before expected value into event](https://github.com/th2-net/th2-check1/issues/251)
357+
+ Added [hide-operation-in-expected](#hide-operation-in-expected)
358+
+ Update:
359+
+ th2-plugin: `0.3.10` (bom: `4.14.3`)
360+
+ kotlin: `2.3.0`
361+
+ rxjava: `3.1.12`
362+
+ common: `5.17.0-dev`
363+
+ common-utils: `5.4.0-dev`
364+
+ grpc-check1: `4.5.1`
365+
+ grpc-lw-data-provider: `2.6.0-dev`
366+
+ lw-data-provider-utils: `0.0.8-dev`
367+
337368
### 4.8.0
338369
+ Added `await-root-event-storing-on-wait-for-result` option.
339370
+ Update:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
2-
release_version=4.8.0
2+
release_version=4.9.0
33
description='th2 check1 box'
44
vcs_url=https://github.com/th2-net/th2-check1

src/main/java/com/exactpro/th2/check1/event/VerificationEntryUtils.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Exactpro (Exactpro Systems Limited)
2+
* Copyright 2020-2025 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,20 +25,26 @@
2525
import com.exactpro.th2.common.event.bean.VerificationStatus;
2626
import com.exactpro.th2.common.grpc.FilterOperation;
2727
import com.exactpro.th2.sailfish.utils.filter.IOperationFilter;
28+
import com.exactpro.th2.sailfish.utils.filter.ListContainFilter;
29+
import com.exactpro.th2.sailfish.utils.filter.RegExFilter;
30+
import com.exactpro.th2.sailfish.utils.filter.WildcardFilter;
2831
import com.exactpro.th2.sailfish.utils.filter.util.FilterUtils;
2932
import org.jetbrains.annotations.Nullable;
3033

3134
import java.util.LinkedHashMap;
3235
import java.util.Map.Entry;
3336
import java.util.Objects;
37+
import java.util.regex.Pattern;
3438
import java.util.stream.Collectors;
3539

40+
import static com.exactpro.sf.comparison.Formatter.formatForHtml;
41+
3642
public class VerificationEntryUtils {
3743

38-
public static VerificationEntry createVerificationEntry(ComparisonResult result) {
44+
public static VerificationEntry createVerificationEntry(ComparisonResult result, boolean hideOperationInExpected) {
3945
VerificationEntry verificationEntry = new VerificationEntry();
4046
verificationEntry.setActual(convertActual(result));
41-
verificationEntry.setExpected(convertExpectedResult(result));
47+
verificationEntry.setExpected(convertExpectedResult(result, hideOperationInExpected));
4248
verificationEntry.setStatus(toVerificationStatus(result));
4349
verificationEntry.setKey(result.isKey());
4450
verificationEntry.setOperation(resolveOperation(result));
@@ -47,7 +53,7 @@ public static VerificationEntry createVerificationEntry(ComparisonResult result)
4753
verificationEntry.setFields(result.getResults().entrySet().stream()
4854
.collect(Collectors.toMap(
4955
Entry::getKey,
50-
entry -> createVerificationEntry(entry.getValue()),
56+
entry -> createVerificationEntry(entry.getValue(), hideOperationInExpected),
5157
(entry1, entry2) -> entry1,
5258
LinkedHashMap::new)));
5359
verificationEntry.setType("collection");
@@ -105,8 +111,32 @@ private static VerificationStatus toVerificationStatus(ComparisonResult result)
105111
}
106112
}
107113

108-
private static String convertExpectedResult(ComparisonResult result) {
109-
return result.getExpected() == null ? null : Formatter.formatExpected(result);
114+
public static VerificationEntry createVerificationEntry(ComparisonResult result) {
115+
return createVerificationEntry(result, false);
116+
}
117+
118+
private static String convertExpectedResult(ComparisonResult result, boolean hideOperationInExpected) {
119+
if (result.getExpected() == null) {
120+
return null;
121+
}
122+
if (hideOperationInExpected) {
123+
// this code is modified copy of Formatter.formatExpected method
124+
Object expected = result.getExpected();
125+
126+
if (expected instanceof IComparisonFilter) {
127+
if (expected instanceof RegExFilter) {
128+
return ((Pattern)((RegExFilter) expected).getValue()).pattern();
129+
} else if (expected instanceof ListContainFilter) {
130+
return ((ListContainFilter) expected).getValue().toString();
131+
} else if (expected instanceof WildcardFilter) {
132+
return ((WildcardFilter) expected).getValue().toString();
133+
}
134+
return ((IComparisonFilter) expected).getCondition(result.getActual());
135+
}
136+
137+
return formatForHtml(expected, true);
138+
}
139+
return Formatter.formatExpected(result);
110140
}
111141

112142
private static String extractHint(ComparisonResult result) {

src/main/java/com/exactpro/th2/check1/event/bean/builder/VerificationBuilder.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
2+
* Copyright 2020-2025 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,34 +19,45 @@
1919
import java.util.Map;
2020

2121
import com.exactpro.sf.comparison.ComparisonResult;
22-
import com.exactpro.th2.check1.event.VerificationEntryUtils;
2322
import com.exactpro.th2.common.event.IBodyData;
2423
import com.exactpro.th2.common.event.bean.Verification;
2524
import com.exactpro.th2.common.event.bean.VerificationEntry;
2625
import com.exactpro.th2.common.grpc.MessageFilter;
2726
import com.exactpro.th2.common.grpc.MetadataFilter;
2827

28+
import static com.exactpro.th2.check1.event.VerificationEntryUtils.createVerificationEntry;
29+
30+
@SuppressWarnings("unused")
2931
public class VerificationBuilder {
3032

3133
public static final String VERIFICATION_TYPE = "verification";
3234
public static final String PASSED_STATUS = "PASSED";
3335
public static final String FAILED_STATUS = "FAILED";
3436

3537
protected String status;
36-
protected Map<String, VerificationEntry> fields = new HashMap<>();
38+
protected final Map<String, VerificationEntry> fields = new HashMap<>();
39+
protected final boolean hideOperationInExpected;
40+
41+
public VerificationBuilder(boolean hideOperationInExpected) {
42+
this.hideOperationInExpected = hideOperationInExpected;
43+
}
44+
45+
public VerificationBuilder() {
46+
this(false);
47+
}
3748

3849
public VerificationBuilder status(String status) {
3950
this.status = status;
4051
return this;
4152
}
4253

4354
public VerificationBuilder verification(String fieldName, ComparisonResult comparisonResult, MessageFilter messageFilter, boolean listItemAsSeparate) {
44-
fields.put(fieldName, VerificationEntryUtils.createVerificationEntry(comparisonResult));
55+
fields.put(fieldName, createVerificationEntry(comparisonResult, hideOperationInExpected));
4556
return this;
4657
}
4758

4859
public VerificationBuilder verification(String fieldName, ComparisonResult comparisonResult, MetadataFilter messageFilter) {
49-
fields.put(fieldName, VerificationEntryUtils.createVerificationEntry(comparisonResult));
60+
fields.put(fieldName, createVerificationEntry(comparisonResult, hideOperationInExpected));
5061
return this;
5162
}
5263

src/main/kotlin/com/exactpro/th2/check1/configuration/Check1Configuration.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ class Check1Configuration(
7070

7171
@field:JsonProperty(value = "await-root-event-storing-on-wait-for-result", defaultValue = "false")
7272
val awaitRootEventStoringOnWaitForResult: Boolean = false,
73+
74+
@field:JsonProperty(value = "hide-operation-in-expected", defaultValue = "false")
75+
val hideOperationInExpected: Boolean = false
7376
)

src/main/kotlin/com/exactpro/th2/check1/entities/RuleConfiguration.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 Exactpro (Exactpro Systems Limited)
2+
* Copyright 2021-2025 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,8 @@ data class RuleConfiguration(
2525
val decimalPrecision: Double,
2626
val maxEventBatchContentSize: Int,
2727
val isCheckNullValueAsEmpty: Boolean,
28-
val defaultCheckSimpleCollectionsOrder: Boolean
28+
val defaultCheckSimpleCollectionsOrder: Boolean,
29+
val hideOperationInExpected: Boolean,
2930
) {
3031
init {
3132
require(!timePrecision.isNegative) { "Time precision cannot be negative" }

src/main/kotlin/com/exactpro/th2/check1/rule/AbstractCheckTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ abstract class AbstractCheckTask(
781781
protoFilter: RootMessageFilter,
782782
comparisonResult: ComparisonResult
783783
): Event {
784-
val verificationComponent = VerificationBuilder()
784+
val verificationComponent = VerificationBuilder(ruleConfiguration.hideOperationInExpected)
785785
comparisonResult.results.forEach { (key: String?, value: ComparisonResult?) ->
786786
verificationComponent.verification(key, value, protoFilter.messageFilter, true)
787787
}
@@ -804,7 +804,7 @@ abstract class AbstractCheckTask(
804804
metadataFilter: MetadataFilter,
805805
comparisonResult: ComparisonResult
806806
): Event {
807-
val verificationComponent = VerificationBuilder()
807+
val verificationComponent = VerificationBuilder(ruleConfiguration.hideOperationInExpected)
808808
comparisonResult.results.forEach { (key: String?, value: ComparisonResult?) ->
809809
verificationComponent.verification(key, value, metadataFilter)
810810
}

src/main/kotlin/com/exactpro/th2/check1/rule/RuleFactory.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class RuleFactory(
5555
private val decimalPrecision = configuration.decimalPrecision
5656
private val isCheckNullValueAsEmpty = configuration.isCheckNullValueAsEmpty
5757
private val defaultCheckSimpleCollectionsOrder = configuration.isDefaultCheckSimpleCollectionsOrder
58+
private val hideOperationInExpected = configuration.hideOperationInExpected
5859

5960
fun createCheckRule(
6061
request: CheckRuleRequest,
@@ -81,7 +82,8 @@ class RuleFactory(
8182
timePrecision,
8283
decimalPrecision, maxEventBatchContentSize,
8384
isCheckNullValueAsEmpty,
84-
defaultCheckSimpleCollectionsOrder
85+
defaultCheckSimpleCollectionsOrder,
86+
hideOperationInExpected,
8587
)
8688

8789
CheckRuleTask(
@@ -129,7 +131,8 @@ class RuleFactory(
129131
decimalPrecision,
130132
maxEventBatchContentSize,
131133
isCheckNullValueAsEmpty,
132-
defaultCheckSimpleCollectionsOrder
134+
defaultCheckSimpleCollectionsOrder,
135+
hideOperationInExpected,
133136
)
134137

135138
SequenceCheckRuleTask(
@@ -177,7 +180,8 @@ class RuleFactory(
177180
decimalPrecision,
178181
maxEventBatchContentSize,
179182
isCheckNullValueAsEmpty,
180-
defaultCheckSimpleCollectionsOrder
183+
defaultCheckSimpleCollectionsOrder,
184+
hideOperationInExpected,
181185
)
182186

183187
NoMessageCheckTask(
@@ -219,7 +223,8 @@ class RuleFactory(
219223
decimalPrecision,
220224
maxEventBatchContentSize,
221225
isCheckNullValueAsEmpty,
222-
defaultCheckSimpleCollectionsOrder
226+
defaultCheckSimpleCollectionsOrder,
227+
hideOperationInExpected,
223228
)
224229

225230
SilenceCheckTask(

src/test/kotlin/com/exactpro/th2/check1/entities/RuleConfigurationTest.kt

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 Exactpro (Exactpro Systems Limited)
2+
* Copyright 2020-2025 Exactpro (Exactpro Systems Limited)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,11 +27,14 @@ class RuleConfigurationTest {
2727
fun `check that time precision is negative`() {
2828
val exception = assertThrows<IllegalArgumentException> {
2929
RuleConfiguration(
30-
TaskTimeout(0, 0), null, Duration.ofSeconds(-1),
31-
0.005,
32-
1,
33-
true,
34-
true
30+
taskTimeout = TaskTimeout(0, 0),
31+
description = null,
32+
timePrecision = Duration.ofSeconds(-1),
33+
decimalPrecision = 0.005,
34+
maxEventBatchContentSize = 1,
35+
isCheckNullValueAsEmpty = true,
36+
defaultCheckSimpleCollectionsOrder = true,
37+
hideOperationInExpected = false,
3538
)
3639
}
3740
assertEquals(exception.message, "Time precision cannot be negative")
@@ -41,11 +44,14 @@ class RuleConfigurationTest {
4144
fun `check that decimal precision is negative`() {
4245
val exception = assertThrows<IllegalArgumentException> {
4346
RuleConfiguration(
44-
TaskTimeout(0, 0), null, Duration.ofSeconds(1),
45-
-0.005,
46-
1,
47-
true,
48-
true
47+
taskTimeout = TaskTimeout(0, 0),
48+
description = null,
49+
timePrecision = Duration.ofSeconds(1),
50+
decimalPrecision = -0.005,
51+
maxEventBatchContentSize = 1,
52+
isCheckNullValueAsEmpty = true,
53+
defaultCheckSimpleCollectionsOrder = true,
54+
hideOperationInExpected = false,
4955
)
5056
}
5157
assertEquals(exception.message, "Decimal precision cannot be negative")
@@ -57,13 +63,14 @@ class RuleConfigurationTest {
5763

5864
val exception = assertThrows<IllegalArgumentException> {
5965
RuleConfiguration(
60-
TaskTimeout(0, 0),
61-
null,
62-
Duration.ofSeconds(1),
63-
0.005,
64-
maxEventBatchContentSize,
65-
true,
66-
true
66+
taskTimeout = TaskTimeout(0, 0),
67+
description = null,
68+
timePrecision = Duration.ofSeconds(1),
69+
decimalPrecision = 0.005,
70+
maxEventBatchContentSize = maxEventBatchContentSize,
71+
isCheckNullValueAsEmpty = true,
72+
defaultCheckSimpleCollectionsOrder = true,
73+
hideOperationInExpected = false,
6774
)
6875
}
6976
assertEquals(exception.message, "'maxEventBatchContentSize' should be greater than zero, actual: $maxEventBatchContentSize")
@@ -75,13 +82,14 @@ class RuleConfigurationTest {
7582

7683
val exception = assertThrows<IllegalArgumentException> {
7784
RuleConfiguration(
78-
TaskTimeout(timeout, 0),
79-
null,
80-
Duration.ofSeconds(1),
81-
0.005,
82-
1,
83-
true,
84-
true
85+
taskTimeout = TaskTimeout(timeout, 0),
86+
description = null,
87+
timePrecision = Duration.ofSeconds(1),
88+
decimalPrecision = 0.005,
89+
maxEventBatchContentSize = 1,
90+
isCheckNullValueAsEmpty = true,
91+
defaultCheckSimpleCollectionsOrder = true,
92+
hideOperationInExpected = false,
8593
)
8694
}
8795
assertEquals(exception.message, "'timeout' should be set or be greater than zero, actual: $timeout")

0 commit comments

Comments
 (0)