Skip to content

Commit 84e1525

Browse files
author
Robert Diers
committed
feature flag kafka expected log
1 parent da0b4fb commit 84e1525

9 files changed

Lines changed: 34 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
| 1.14 | 1.0 | adding alias 'soap' to rest adapter |
1818
| 1.15 | 1.0 | YML support (testcase), adding 'senddelay' to REST/SOAP adapter, set Kafka 'senddelay' default to 0, use unblocking technical implementation |
1919
| 1.16 | 1.0 | Adding support to change Kafka reconnect backoff (kafka.reconnect.backoff.max.ms=60000, kafka.reconnect.backoff.ms=1000) |
20-
| 1.17 | 1.0 | improved upload output, new GUI to analyze test cases, AWS SDK update |
20+
| 1.17 | 1.0 | improved upload output, new GUI to analyze test cases, AWS SDK update |
21+
| 1.18 | 1.0 | feature flag to disable kafka expacted vs actual log, add testid and checkid to this log |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<groupId>org.opentesting</groupId>
1313
<artifactId>impl_java</artifactId>
14-
<version>1.17</version>
14+
<version>1.18</version>
1515
<name>impl_java</name>
1616
<description>open testing implementation spring boot</description>
1717

src/main/java/org/opentesting/services/adapter/Adapter.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,20 @@ protected boolean isFailedConnector(String connector) {
348348
* @return check successful or not
349349
* @throws NotFoundException
350350
*/
351-
protected boolean validateResult(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result, String logInfo) throws NotFoundException {
351+
protected boolean validateResult(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result,
352+
String logInfo, boolean dolog) throws NotFoundException {
352353

353354
boolean retvalue = true;
354355

355356
switch (validation.getType()) {
356357
case TestCaseValidationDTO.TYPE_CONTAINS:
357-
if (!validateContains(testid, check, validation, result)) retvalue = false;
358+
if (!validateContains(testid, check, validation, result, dolog)) retvalue = false;
358359
break;
359360
case TestCaseValidationDTO.TYPE_EQUALS:
360-
if (!validateEquals(testid, check, validation, result)) retvalue = false;
361+
if (!validateEquals(testid, check, validation, result, dolog)) retvalue = false;
361362
break;
362363
case TestCaseValidationDTO.TYPE_CONTAINSNOT:
363-
if (!validateContainsNot(testid, check, validation, result)) retvalue = false;
364+
if (!validateContainsNot(testid, check, validation, result, dolog)) retvalue = false;
364365
break;
365366
case TestCaseValidationDTO.TYPE_CONTAINSONEOF:
366367
retvalue = false;
@@ -379,40 +380,44 @@ protected boolean validateResult(String testid, TestCaseCheckDTO check, TestCase
379380
return retvalue;
380381
}
381382

382-
private boolean validateContains(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result) throws NotFoundException {
383+
private boolean validateContains(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation,
384+
String result, boolean dolog) throws NotFoundException {
383385
for (String response : validation.getResponse()) {
384386
String expected = this.getFileAndAddTestData(testid, response, check.getRandomdata());
385387
if (!result.contains(expected)) {
386-
log.info("validateContains:\n actual: >"+result+EXPECTED+expected+"<");
388+
if (dolog) log.info(testid+"."+check.getInstanceid()+" validateContains:\n actual: >"+result+EXPECTED+expected+"<");
387389
return false;
388390
}
389391
}
390392
return true;
391393
}
392394

393-
private boolean validateEquals(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result) throws NotFoundException {
395+
private boolean validateEquals(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation,
396+
String result, boolean dolog) throws NotFoundException {
394397
for (String response : validation.getResponse()) {
395398
String expected = this.getFileAndAddTestData(testid, response, check.getRandomdata());
396399
if (!result.equals(expected)) {
397-
log.info("equals:\n actual: >"+result+EXPECTED+expected+"<");
400+
if (dolog) log.info(testid+"."+check.getInstanceid()+" equals:\n actual: >"+result+EXPECTED+expected+"<");
398401
return false;
399402
}
400403
}
401404
return true;
402405
}
403406

404-
private boolean validateContainsNot(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result) throws NotFoundException {
407+
private boolean validateContainsNot(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation,
408+
String result, boolean dolog) throws NotFoundException {
405409
for (String response : validation.getResponse()) {
406410
String expected = this.getFileAndAddTestData(testid, response, check.getRandomdata());
407411
if (result.contains(expected)) {
408-
log.info("contains not:\n actual: >"+result+EXPECTED+expected+"<");
412+
if (dolog) log.info(testid+"."+check.getInstanceid()+" contains not:\n actual: >"+result+EXPECTED+expected+"<");
409413
return false;
410414
}
411415
}
412416
return true;
413417
}
414418

415-
private boolean validateContainsOneOf(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation, String result) throws NotFoundException {
419+
private boolean validateContainsOneOf(String testid, TestCaseCheckDTO check, TestCaseValidationDTO validation,
420+
String result) throws NotFoundException {
416421
for (String response : validation.getResponse()) {
417422
String expected = this.getFileAndAddTestData(testid, response, check.getRandomdata());
418423
if (result.contains(expected)) return true;

src/main/java/org/opentesting/services/adapter/cassandra/Cassandra.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public boolean check(String testid, TestCaseCheckDTO check, Object... args) {
8686
}
8787

8888
//do validation
89-
if (!validateResult(testid, check, validation, result, "Cassandra "+query)) {
89+
if (!validateResult(testid, check, validation, result, "Cassandra "+query, true)) {
9090
retvalue = false;
9191
}
9292
}

src/main/java/org/opentesting/services/adapter/jdbc/Jdbc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private boolean executeQuery(Connection connection, String query, String testid,
124124
}
125125

126126
//do validation
127-
return validateResult(testid, check, validation, result, "JDBC "+query);
127+
return validateResult(testid, check, validation, result, "JDBC "+query, true);
128128
} catch (Exception e) {
129129
log.error(testid+" "+check.getCheckid()+" "+check.getInstanceid()+": validation failed: "+validation.getOrder(), e);
130130
return false;

src/main/java/org/opentesting/services/adapter/kafka/Kafka.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,20 @@ public boolean check(String testid, TestCaseCheckDTO check, Object... args) {
133133
if (check.getStartts().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() >= timestamp)
134134
return false;
135135

136+
boolean dolog = true;
137+
if (check.getService().getCustom("stopexpectedlog") != null &&
138+
check.getService().getCustom("stopexpectedlog").getValue() != null &&
139+
check.getService().getCustom("stopexpectedlog").getValue().equalsIgnoreCase("true")
140+
) {
141+
dolog = false;
142+
}
143+
136144
boolean retvalue = true;
137145

138146
// check all validations, sort first
139147
for (TestCaseValidationDTO validation : sortValidations(check.getValidations())) {
140-
// do validation
141-
if (!validateResult(testid, check, validation, content, "Kafka " + timestamp)) {
148+
// do validation
149+
if (!validateResult(testid, check, validation, content, "Kafka " + timestamp, dolog)) {
142150
retvalue = false;
143151
}
144152
}

src/main/java/org/opentesting/services/adapter/kafka/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Using consumer and producer to perform inject and check
1313
* please use custom parameter jwtpost, jwtparam and jwtheader to request token, please use #username#, #password# or replacement keys as placeholders (for example #jwtpassword# could be used and will be decrypted automatically)
1414
* please use custom parameter kafkaheaderjwt to define the kafka header key for requested JWT
1515
* please use custom parameter senddelay in ms to define a kafka produce delay, helpful if kafka consumer initialization is to slow (default: 0)
16+
* please use custom parameter stopexpectedlog to stop logging if expected vs actual (default: false)
1617

1718
```
1819
{

src/main/java/org/opentesting/services/adapter/rest/Rest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public boolean check(String testid, TestCaseCheckDTO check, Object... args) {
131131
sendInfo = res.getSendInfo();
132132

133133
//do validation
134-
if (!validateResult(testid, check, validation, res.getResult(), "Rest "+sendInfo)) {
134+
if (!validateResult(testid, check, validation, res.getResult(), "Rest "+sendInfo, true)) {
135135
retvalue = false;
136136
}
137137
}

src/main/java/org/opentesting/services/adapter/s3/S3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public boolean check(String testid, TestCaseCheckDTO check, Object... args) {
8686

8787
//check all validations, sort first
8888
for (TestCaseValidationDTO validation : sortValidations(check.getValidations())) {
89-
if (!validateResult(testid, check, validation, result, "S3 "+bucketName+"/"+filename)) {
89+
if (!validateResult(testid, check, validation, result, "S3 "+bucketName+"/"+filename, true)) {
9090
retvalue = false;
9191
}
9292
}

0 commit comments

Comments
 (0)