-
Notifications
You must be signed in to change notification settings - Fork 35
/
ConditionUtilTest.java
78 lines (63 loc) · 2.96 KB
/
ConditionUtilTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* (C) Copyright IBM Corp. 2020, 2021
*
* SPDX-License-Identifier: Apache-2.0
*/
package io.github.linuxforhealth.core.expression.condition;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class ConditionUtilTest {
private static Stream<Arguments> parmsTestValueComparisionValueSimpleConditions() {
return Stream.of(
// Arguments are: (condition, val1, val2, operator)
// simple_equals_string_condition
Arguments.of("$var1 EQUALS abc", "$var1", "abc", "EQUALS"),
// simple_greaterthan_condition
Arguments.of("$var1 GREATER_THAN 4", "$var1", "4", "GREATER_THAN"),
// simpleQuotedCharactersParsing
Arguments.of("$var1 EQUALS ':'", "$var1", ":", "EQUALS"),
// another simpleQuotedCharactersParsing
Arguments.of("$var1 EQUALS '/'", "$var1", "/", "EQUALS"));
}
@ParameterizedTest
@MethodSource("parmsTestValueComparisionValueSimpleConditions")
void testValueComparisionValueSimpleConditions(String condition, String val1, String val2, String operator) {
SimpleBiCondition simplecondition = (SimpleBiCondition) ConditionUtil.createCondition(condition);
assertThat(simplecondition).isNotNull();
assertThat(simplecondition.getVar1()).isEqualTo(val1);
assertThat(simplecondition.getVar2()).isEqualTo(val2);
assertThat(simplecondition.getConditionOperator()).isEqualTo(operator);
}
@Test
void multiple_or_condition() {
String condition = "$var1 EQUALS abc || $var1 EQUALS xyz";
CompoundORCondition simplecondition = (CompoundORCondition) ConditionUtil.createCondition(condition);
assertThat(simplecondition).isNotNull();
assertThat(simplecondition.getConditions()).hasSize(2);
}
@Test
void multiple_and_condition() {
String condition = "$var1 EQUALS abc && $var1 EQUALS xyz";
CompoundAndCondition simplecondition = (CompoundAndCondition) ConditionUtil.createCondition(condition);
assertThat(simplecondition).isNotNull();
assertThat(simplecondition.getConditions()).hasSize(2);
}
@Test
void notnull_condition() {
String condition = "$var1 NOT_NULL";
CheckNotNull simplecondition = (CheckNotNull) ConditionUtil.createCondition(condition);
assertThat(simplecondition).isNotNull();
assertThat(simplecondition.getVar1()).isEqualTo("$var1");
}
@Test
void null_condition() {
String condition = "$var1 NULL";
CheckNull simplecondition = (CheckNull) ConditionUtil.createCondition(condition);
assertThat(simplecondition).isNotNull();
assertThat(simplecondition.getVar1()).isEqualTo("$var1");
}
}